missed optimization: transforming while(n>=1) into if(n>=1)

Paolo Bonzini bonzini@gnu.org
Sat May 21 08:28:00 GMT 2011


On 05/21/2011 08:07 AM, Matt Turner wrote:
> I suppose this is a missed optimization. Is this known, or should I
> make a new bug report?

It's always better to do that.  In this case, the bug is that when we 
compute a range from an ASSERT_EXPR, and the base variable has a known 
but symbolic range, we do not try replacing the known range of the 
symbolic operands:

n_28 = ASSERT_EXPR <n_3, n_3 <= 1>;

Found new range for n_28: [-INF, 1]

...

Visiting PHI node: n_7 = PHI <n_28(10)>

n_7: [-INF, 1]

...

Visiting PHI node: n_4 = PHI <n_7(7), n_20(6)>

Found new range for n_4: [-INF, n_7]

...

And then in the body of the loop:

n_29 = ASSERT_EXPR <n_4, n_4 > 0>;

Found new range for n_29: [1, +INF]

This should have been the intersection of [-INF, 1] and [1, +INF], i.e. 
1.  Note that this has a chain effect: n_20 is n_29 - 1, so it will get 
a range of [0, 0].  Then, n_4 will get a range of [-INF, 1] too instead 
of the symbolic range.

Something like the attached untested patch should fix it...

Paolo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vrp-symrange.patch
Type: text/x-patch
Size: 2721 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20110521/2535d689/attachment.bin>


More information about the Gcc mailing list