On 05/10/2013 08:53 AM, Jakub Jelinek wrote:
Hi!
Our rotate expansion if rotate optab isn't present for the respective
mode looks unsafe for rotations by variable count if that count could
be 0, because then it invokes right or left shift by bitsize.
While on most targets the hw will probably do the right thing
(it is fine if x << 32 will either yield x or 0, in both cases
that ored together with x >> 0 aka x will still yield x), perhaps gcc
could try to optimize based on the fact that undefined behavior can't
happen, so IMHO it is better to generate a safer sequence.
Ok for trunk?
2013-05-10 Jakub Jelinek <ja...@redhat.com>
* expmed.c (expand_shift_1): For rotations by const0_rtx just
return shifted. Use (-op1) & (prec - 1) as other_amount
instead of prec - op1.
Found by inspection? Presumably the rotate was synthesized by GCC from
some other set of operations. To be optimizable, we'd have to prove the
original sequence triggered undefined behaviour.
Seems that we ought to have a testcase, even though it probably means
scanning the tree dumps to pick up the undefined behaviour. Approved
with a testcase.
Out of curiosity, do we recognize the original sequence created by
expand_shift_1 as a rotate if they appeared in the original source?
jeff