[llvm] r274199 - [SCEV] Compute max be count from shift operator only if all else fails
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 29 19:47:29 PDT 2016
Author: sanjoy
Date: Wed Jun 29 21:47:28 2016
New Revision: 274199
URL: http://llvm.org/viewvc/llvm-project?rev=274199&view=rev
Log:
[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.
Added:
llvm/trunk/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=274199&r1=274198&r2=274199&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Jun 29 21:47:28 2016
@@ -5948,11 +5948,6 @@ ScalarEvolution::computeExitLimitFromICm
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::computeExitLimitFromICm
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
Added: llvm/trunk/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll?rev=274199&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll (added)
+++ llvm/trunk/test/Analysis/ScalarEvolution/exhaustive-trip-counts.ll Wed Jun 29 21:47:28 2016
@@ -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()
More information about the llvm-commits
mailing list