Maybe this actually does not make any difference as synthesis-tools might figure this out anyway. However, if this is done in the intermediate representation optimization, there might be follow-up optimization opportunities that currently might be left on the table ?
This example was with AND, but of course this is true for all bit-wise operations that do not depend on neighbors and have one known bit:
AND: if known bit is 0, result is 0; if known 1, output is input.
OR: if known bit is 0, result is just input; if 1, output always stuck on 1
XOR if known bit is 0, keep input as-is, if known bit is 1, strength reduce operation to ~input.
Consider the following function in
/tmp/foo.x
We expect that the last bit is whatever is
b & x[0]
and the remaining bits zero.Let's generate code from this
Result
The generated code does not see any optimization opportunity and essentially emits the code similar to the input, that
AND
s 32 bits:Expected Result
It would be good if the optimizer would recognize that we only actually need to
AND
one bit, while all the other bits are known to be zero already:Remarks
This is essentially a generalization of #1217
Maybe this actually does not make any difference as synthesis-tools might figure this out anyway. However, if this is done in the intermediate representation optimization, there might be follow-up optimization opportunities that currently might be left on the table ?
This example was with
AND
, but of course this is true for all bit-wise operations that do not depend on neighbors and have one known bit:AND
: if known bit is 0, result is 0; if known 1, output is input.OR
: if known bit is 0, result is just input; if 1, output always stuck on 1XOR
if known bit is 0, keep input as-is, if known bit is 1, strength reduce operation to ~input.