https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84433
Bug ID: 84433
Summary: gcc 7 and before miscompile loop and remove exit due
to incorrect range calculation
Product: gcc
Version: 7.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: acsawdey at gcc dot gnu.org
CC: segher at gcc dot gnu.org, wschmidt at gcc dot gnu.org
Target Milestone: ---
Target: ppc64le
Created attachment 43446
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43446&action=edit
test case for range error bug
An incorrect range calculation results in the cunroll pass thinking that the
loop exit conditional branch can never happen:
Analyzing # of iterations of loop 1
exit condition [15, + , 4294967295] != 0
bounds on difference of bases: -15 ... -15
result:
# of iterations 15, bounded by 15
Loop 1 iterates 15 times.
Loop 1 iterates at most 14 times.
Loop 1 likely iterates at most 14 times.
Analyzing # of iterations of loop 1
exit condition [15, + , 4294967295] != 0
bounds on difference of bases: -15 ... -15
result:
# of iterations 15, bounded by 15
Removed pointless exit: if (ivtmp_24 != 0)
As a result gcc 7 and below (I've also tested 5.4.0 and 6.4.1) generate an
infinite loop here with -O2 or -O3. -O1 generates working code.
It appears this is fixed in gcc 8 as trunk does not have this failure. Not sure
if this can be fixed in 7 or 6 but I think I will see if this little test case
can go into the testsuite to make sure we don't run into this again.