Bug 23128 - [4.1 Regression] VRP fails for unsigned values
Summary: [4.1 Regression] VRP fails for unsigned values
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 critical
Target Milestone: 4.1.0
Assignee: James A. Morrison
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: monitored, patch, wrong-code
Depends on:
Blocks:
 
Reported: 2005-07-29 09:13 UTC by Ross Morgan-Linial
Modified: 2005-08-06 05:42 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-29 11:31:44


Attachments
Patch for a bunch of vrp problems (1.13 KB, patch)
2005-07-30 18:12 UTC, James A. Morrison
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ross Morgan-Linial 2005-07-29 09:13:58 UTC
VRP miscompiles the following testcase at -O2 (on a machine with 32-bit ints):

#include <stdlib.h>

void test(unsigned int a, unsigned int b)
{
        if (a < 5)
                abort();
        if (b < 5)
                abort();
        if (a + b != 0)
                abort();
}

int main()
{
        unsigned int x = 0x80000000;
        test(x, x);
}


The t27.vrp dump shows why:

...
D.1824_3: [10, 0fffffffe]  EQUIVALENCES: { } (0 elements)
a_4: [5, +INF]  EQUIVALENCES: { a_1 } (1 elements)
b_5: [5, +INF]  EQUIVALENCES: { b_2 } (1 elements)

Folding predicate D.1824_3 != 0 to 1
...

VRP concludes that since a >= 5 and b >= 5, a + b >= 10. However, since unsigned
variables have wrapping semantics, this is incorrect. It then miscompiles test()
to include an unconditional abort.
Comment 1 Andrew Pinski 2005-07-29 11:31:44 UTC
Confirmed.
Comment 2 James A. Morrison 2005-07-30 18:12:52 UTC
Created attachment 9388 [details]
Patch for a bunch of vrp problems
Comment 4 James A. Morrison 2005-08-06 05:42:20 UTC
Fixed.