This is an archive of the discontinued LLVM Phabricator instance.

[IRCE] Fix corner case with Start = INT_MAX
ClosedPublic

Authored by mkazantsev on Jul 13 2017, 1:55 AM.

Details

Summary

When iterating through loop

for (int i = INT_MAX; i > 0; i--)

We fail to generate the pre-loop for it. It happens because we use the overflown value
in a comparison predicate when identifying whether or not we need it.

In old logic, we used SLE predicate against Greatest value which exceeds all seen values
of the IV and might be overflown. Now we use the GreatestSeen value of this IV with SLT
predicate.

Also added a test that ensures that a pre-loop is generated for such loops.

Diff Detail

Repository
rL LLVM

Event Timeline

mkazantsev created this revision.Jul 13 2017, 1:55 AM
anna accepted this revision.Jul 13 2017, 8:00 AM

LGTM w/ comments inline.

test/Transforms/IRCE/pre_post_loops.ll
19 ↗(On Diff #106383)

I don't think the branch weight really needed here? Pls remove if so.

Same for one below.

37 ↗(On Diff #106383)

Could you pls add some statements here regarding what's the expected terminating condition of the preloop. Similar for the test above.

44 ↗(On Diff #106383)

Could you please state in the comment above the test that this tests the case where START = INT_MAX.

This revision is now accepted and ready to land.Jul 13 2017, 8:00 AM
mkazantsev marked 3 inline comments as done.
This revision was automatically updated to reflect the committed changes.
sanjoy added inline comments.Jul 15 2017, 4:57 PM
llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
948

Please update this comment.