On 01/20/2013 12:46 PM, Jakub Jelinek wrote:
Hi!

As the first hunk in the testcase shows, we can't perform this optimization
if the conversion is narrowing.
As the second hunk shows, if we allow 1 << 31 (we don't optimize
int foo (int x) { return (1 << x) < 0; } so I think it would be surprising
if we did optimize it in this case, plus I'm afraid it could break a lot
of code if we started optimizing (1 << x) < 0 into 0), we can't optimize
a widening conversion from signed to unsigned either.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

For 4.9, I think we should see why e.g.
X < (unsigned) (1 << Y)
optimization isn't performed e.g. when X is just an unsigned int variable
(rather than say ARRAY_REF as in the testcase), probably we need to handle
it for arg1 being X and arg0 being (1 << Y) too.

2013-01-20  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/56051
        * fold-const.c (fold_binary_loc): Don't fold
        X < (cast) (1 << Y) into (X >> Y) != 0 if cast is either
        a narrowing conversion, or widening conversion from signed
        to unsigned.

        * gcc.c-torture/execute/pr56051.c: New test.
Please add a comment to the fold-const.c change indicating why we can't apply this optimization as aggressively in the presence of conversions.

Pre-approved with that comment.

Thanks,
Jeff

Reply via email to