Skip to content

Commit 6c4bc5a

Browse files
authored
Merge pull request #4165 from phsauter/shiftadd-offset-fix
peepopt: handle offset too large in `shiftadd`
2 parents 3bc83c6 + cbdf9b2 commit 6c4bc5a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

passes/pmgen/peepopt_shiftadd.pmg

+14-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,20 @@ code
103103
new_a.append(old_a);
104104
} else {
105105
// data >> (...+c) transformed to data[MAX:c] >> (...)
106-
new_a.append(old_a.extract_end(offset));
107-
106+
if(offset < GetSize(old_a)) { // some signal bits left?
107+
new_a.append(old_a.extract_end(offset));
108+
} else {
109+
// warn user in case data is empty (no bits left)
110+
std::string location = shift->get_src_attribute();
111+
if (location.empty())
112+
location = shift->name.str();
113+
if(shift->type.in($shiftx))
114+
log_warning("at %s: result of indexed part-selection is always constant (selecting from '%s' with index '%s + %d')\n", \
115+
location.c_str(), log_signal(old_a), log_signal(var_signal), offset);
116+
else
117+
log_warning("at %s: result of shift operation is always constant (shifting '%s' by '%s + %d'-bits)\n", \
118+
location.c_str(), log_signal(old_a), log_signal(var_signal), offset);
119+
}
108120
}
109121

110122
SigSpec new_b = {var_signal, SigSpec(State::S0, log2scale)};

0 commit comments

Comments
 (0)