https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110875
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amacleod at redhat dot com
--- Comment #2 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> I am super confused about VRP's ranges:
> We have the following that ranges that get exported and their relationships:
> Global Exported: a.8_105 = [irange] int [-2, 0]
> _10 = a.8_105 + -1;
> Global Exported: _10 = [irange] int [-INF, -6][-3, -1][1, 2147483645]
> _103 = (unsigned int) _10;
> Global Exported: _103 = [irange] unsigned int [1, 2147483645][2147483648,
> 4294967290][4294967294, +INF]
> Simplified relational if (_103 > 1)
> into if (_103 != 1)
>
>
> Shouldn't the range of _10 just be [-3,-1] ????
> If so _103 can't get 0 or 1 ? And then if that gets it right then the call
> to foo will go away.
[It looks like a caching issue of some kind. Looping Andrew.]
Yes, that is indeed confusing. _10 should have a more refined range.
Note that there's a dependency between a.8_105 and _10:
<bb 4> [local count: 327784168]:
# f_lsm.17_26 = PHI <f_lsm.17_50(3), f_lsm.17_26(13)>
# a.8_105 = PHI <0(3), _10(13)>
# b_lsm.19_33 = PHI <b_lsm.19_52(3), 0(13)>
# b_lsm_flag.20_53 = PHI <0(3), 1(13)>
# a_lsm.21_49 = PHI <_54(D)(3), _10(13)>
_9 = e.10_39 + 4294967061;
_10 = a.8_105 + -1;
if (_10 != -3(OVF))
goto <bb 7>; [94.50%]
else
goto <bb 8>; [5.50%]
This is what I see with --param=ranger-debug=tracegori in VRP2...
We first calculate a.8_105 to [-INF, -5][-2, 0][2, 2147483646]:
1140 range_of_stmt (a.8_105) at stmt a.8_105 = PHI <0(3), _10(13)>
1141 ROS dependence fill
ROS dep fill (a.8_105) at stmt a.8_105 = PHI <0(3), _10(13)>
ROS dep fill (_10) at stmt _10 = a.8_105 + -1;
1142 range_of_expr(a.8_105) at stmt _10 = a.8_105 + -1;
TRUE : (1142) range_of_expr (a.8_105) [irange] int [-INF, -5][-2,
0][2, 2147483646]
Which we later refine with SCEV:
Statement _10 = a.8_105 + -1;
is executed at most 2147483647 (bounded by 2147483647) + 1 times in loop 4.
Loops range found for a.8_105: [irange] int [-2, 0] and calculated range
:[irange] int [-INF, -6][-2, 0][2, 2147483645]
TRUE : (1140) range_of_stmt (a.8_105) [irange] int [-2, 0]
Global Exported: a.8_105 = [irange] int [-2, 0]
I have verified that range_of_expr after this point returns [-2, 0], so we know
both globally and locally this refined range.
However, when we try to fold _10 later on, we use the cached value instead of
recalculating with the new range for a.8_105:
Folding statement: _10 = a.8_105 + -1;
872 range_of_stmt (_10) at stmt _10 = a.8_105 + -1;
TRUE : (872) cached (_10) [irange] int [-INF, -6][-3, -1][1,
2147483645]