diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-06-09 01:13:59 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-06-09 01:13:59 +0000 |
commit | c7f69b921ff8b2e06762055e159cce55cd5f406b (patch) | |
tree | 6cb5b577bd19ec1fe8cbd2476039bfa7fa3ef328 /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | 97cd7d5d44b60df7fc4a8dffb0a7d7d8d128aee2 (diff) | |
download | bcm5719-llvm-c7f69b921ff8b2e06762055e159cce55cd5f406b.tar.gz bcm5719-llvm-c7f69b921ff8b2e06762055e159cce55cd5f406b.zip |
Be wary of abnormal exits from loop when exploiting UB
We can safely rely on a NoWrap add recurrence causing UB down the road
only if we know the loop does not have a exit expressed in a way that is
opaque to ScalarEvolution (e.g. by a function call that conditionally
calls exit(0)).
I believe with this change PR28012 is fixed.
Note: I had to change some llvm-lit tests in LoopReroll, since it looks
like they were depending on this incorrect behavior.
llvm-svn: 272237
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 9278aa05dcb..867b0515003 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -7199,7 +7199,8 @@ ScalarEvolution::howFarToZero(const SCEV *V, const Loop *L, bool ControlsExit, // compute the backedge count. In this case, the step may not divide the // distance, but we don't care because if the condition is "missed" the loop // will have undefined behavior due to wrapping. - if (ControlsExit && AddRec->hasNoSelfWrap()) { + if (ControlsExit && AddRec->hasNoSelfWrap() && + loopHasNoAbnormalExits(AddRec->getLoop())) { const SCEV *Exact = getUDivExpr(Distance, CountDown ? getNegativeSCEV(Step) : Step); return ExitLimit(Exact, Exact, P); |