This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Fix predicate usage in computeExitLimitFromICmp
ClosedPublic

Authored by mkazantsev on Dec 7 2017, 6:34 AM.

Details

Summary

In this method, we invoke SimplifyICmpOperands which takes the Cond predicate
by reference and may change it along with LHS and RHS SCEVs. But then we invoke
computeShiftCompareExitLimit with Values from which the SCEVs have been derived,
these Values have not been modified while Cond could be.

One of possible outcomes of this is that we may falsely prove that an infinite loop ends
within some finite number of iterations.

In this patch, we save the original Cond and pass it along with original operands.
This logic may be removed in future once computeShiftCompareExitLimit works
with SCEVs instead of value operands.

Diff Detail

Repository
rL LLVM

Event Timeline

mkazantsev created this revision.Dec 7 2017, 6:34 AM
sanjoy accepted this revision.Dec 7 2017, 10:34 PM

lgtm!

lib/Analysis/ScalarEvolution.cpp
7061 ↗(On Diff #125943)

If possible, I'd suggest also cleaning this up a bit -- the variable should be called Pred and not Cond (a later NFC change is fine).

Also, how about making OriginalCond const so that it obviously can't be modified?

This revision is now accepted and ready to land.Dec 7 2017, 10:34 PM
mkazantsev added inline comments.Dec 8 2017, 1:33 AM
lib/Analysis/ScalarEvolution.cpp
7061 ↗(On Diff #125943)

Fair point, I'll do it.

This revision was automatically updated to reflect the committed changes.