diff options
| author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-06-30 02:47:28 +0000 |
|---|---|---|
| committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-06-30 02:47:28 +0000 |
| commit | 0da2d147668532ce9266b03a29c078359d267f61 (patch) | |
| tree | 32fcbd3afba58fcc4dbc09bd34bbcbe288ba2f9c | |
| parent | 758032726d8e4ed1005c26ef61abde406df124af (diff) | |
| download | bcm5719-llvm-0da2d147668532ce9266b03a29c078359d267f61.tar.gz bcm5719-llvm-0da2d147668532ce9266b03a29c078359d267f61.zip | |
[SCEV] Compute max be count from shift operator only if all else fails
In particular, check to see if we can compute a precise trip count by
exhaustively simulating the loop first.
llvm-svn: 274199
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 15 | ||||
| -rw-r--r-- | llvm/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll | 26 |
2 files changed, 35 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 40274f77c6f..e28587e67d3 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -5948,11 +5948,6 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L, return ItCnt; } - ExitLimit ShiftEL = computeShiftCompareExitLimit( - ExitCond->getOperand(0), ExitCond->getOperand(1), L, Cond); - if (ShiftEL.hasAnyInfo()) - return ShiftEL; - const SCEV *LHS = getSCEV(ExitCond->getOperand(0)); const SCEV *RHS = getSCEV(ExitCond->getOperand(1)); @@ -6018,7 +6013,15 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L, default: break; } - return computeExitCountExhaustively(L, ExitCond, !L->contains(TBB)); + + auto *ExhaustiveCount = + computeExitCountExhaustively(L, ExitCond, !L->contains(TBB)); + + if (!isa<SCEVCouldNotCompute>(ExhaustiveCount)) + return ExhaustiveCount; + + return computeShiftCompareExitLimit(ExitCond->getOperand(0), + ExitCond->getOperand(1), L, Cond); } ScalarEvolution::ExitLimit diff --git a/llvm/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll b/llvm/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll new file mode 100644 index 00000000000..16d9cc54438 --- /dev/null +++ b/llvm/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll @@ -0,0 +1,26 @@ +; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f_0() { +; CHECK-LABEL: Printing analysis 'Scalar Evolution Analysis' for function 'f_0': +; CHECK: Loop %for.body: backedge-taken count is 5 +; CHECK: Loop %for.body: max backedge-taken count is 5 +; CHECK: Loop %for.body: Predicated backedge-taken count is 5 + +entry: + br label %for.body + +for.body: + %i.05 = phi i32 [ 32, %entry ], [ %div4, %for.body ] + tail call void @dummy() + %div4 = lshr i32 %i.05, 1 + %cmp = icmp eq i32 %div4, 0 + br i1 %cmp, label %for.cond.cleanup, label %for.body + +for.cond.cleanup: + ret void +} + +declare void @dummy() |

