https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126171
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amacleod at redhat dot com
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
With -O2 -fno-tree-vrp we optimize to
<bb 2> [local count: 2088427870]:
o = 2147483645;
n ();
n ();
o.0_23 = o;
_24 = -2 - o.0_23;
o = _24;
return 0;
while -O2 produces:
<bb 2> [local count: 2088427865]:
o = 2147483645;
<bb 3> [local count: 19522579055]:
# am_7 = PHI <am_9(3), -1(2)>
be:
am_9 = am_7 + 1;
_10 = n ();
_11 = _10 + -129105632;
_12 = am_9 << _11;
if (_12 == 0)
goto <bb 3>; [94.50%]
else
goto <bb 4>; [5.50%]
<bb 4> [local count: 1073741842]:
o.0_23 = o;
_24 = -2 - o.0_23;
o = _24;
return 1;
visible from CCP3:
> diff -u a-t.c.151t.phiopt3 a-t.c.152t.ccp3
...
+Global Exported: ak_20 = [irange] int [-1, -1][2147483645, 2147483645] MASK
0xfffffffe VALUE 0x1
+Global Exported: ak_22 = [irange] int [2147483645, 2147483645] MASK 0x0 VALUE
0x7ffffffd
...
- _39 = ak_20 != 2147483646;
- _19 = (int) _39;
- return _19;
+ return 1;
The upper bound of the loop iterations is correctly determined as 1, so the
error happens before. With -fno-tree-vrp we have
# RANGE [irange] int [-1, 0]
_26 = ay_16 >> 31;
# RANGE [irange] int [-2, +INF]
_27 = ak_20 + _26;
_5 = _27 != 2147483645;
With VRP DOM computes _26 as -1 meaning it must conclude the loop doesn't
iterate or some other logic is broken. Like we have in the IL:
# RANGE [irange] int [-1782460880, -1782460880][3, 3] MASK 0x95c1ce33 VALUE
0x0
# ay_16 = PHI <365022768(4), -1782460880(2)>
which is weird (where's 365022768?). VRP1 produces the above PHI.
> diff -u a-t.c.127t.threadfull1 a-t.c.128t.vrp1
...
<bb 3> [local count: 19522579055]:
- # ak_20 = PHI <ak_22(10), ak_30(6)>
- # am_7 = PHI <am_9(10), am_31(6)>
- # RANGE [irange] int [-1782460880, -1782460880][3, 3][365022767, 365022768]
MASK 0x95c1ce33 VALUE 0x0
- # ay_16 = PHI <ay_17(10), ay_32(6)>
+ # RANGE [irange] int [-1, 0][2147483645, +INF]
+ # ak_20 = PHI <ak_22(4), -1(2)>
+ # RANGE [irange] int [-2147483647, 1]
+ # am_7 = PHI <am_9(4), -1(2)>
+ # RANGE [irange] int [-1782460880, -1782460880][3, 3] MASK 0x95c1ce33 VALUE
0x0
+ # ay_16 = PHI <365022768(4), -1782460880(2)>
It should be possible to simplify the testcase based on the 127t.threadfull1
IL.