[llvm] r276505 - [SCEV] Make isImpliedCondOperandsViaRanges smarter
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 22 17:54:37 PDT 2016
Author: sanjoy
Date: Fri Jul 22 19:54:36 2016
New Revision: 276505
URL: http://llvm.org/viewvc/llvm-project?rev=276505&view=rev
Log:
[SCEV] Make isImpliedCondOperandsViaRanges smarter
This change lets us prove things like
"{X,+,10} s< 5000" implies "{X+7,+,10} does not sign overflow"
It does this by replacing replacing getConstantDifference by
computeConstantDifference (which is smarter) in
isImpliedCondOperandsViaRanges.
Modified:
llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
llvm/trunk/test/Analysis/ScalarEvolution/no-wrap-unknown-becount.ll
Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=276505&r1=276504&r2=276505&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Fri Jul 22 19:54:36 2016
@@ -1175,15 +1175,6 @@ namespace llvm {
/// add recurrence on the loop \p L.
bool isAddRecNeverPoison(const Instruction *I, const Loop *L);
- /// Compute \p LHS - \p RHS and returns the result as an APInt if it is a
- /// constant, and None if it isn't.
- ///
- /// This is intended to be a cheaper version of getMinusSCEV. We can be
- /// frugal here since we just bail out of actually constructing and
- /// canonicalizing an expression in the cases where the result isn't going
- /// to be a constant.
- Optional<APInt> getConstantDifference(const SCEV *LHS, const SCEV *RHS);
-
public:
ScalarEvolution(Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC,
DominatorTree &DT, LoopInfo &LI);
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=276505&r1=276504&r2=276505&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Fri Jul 22 19:54:36 2016
@@ -8571,16 +8571,6 @@ ScalarEvolution::isImpliedCondOperandsHe
return false;
}
-Optional<APInt> ScalarEvolution::getConstantDifference(const SCEV *LHS,
- const SCEV *RHS) {
- if (const SCEVAddExpr *AddLHS = dyn_cast<SCEVAddExpr>(LHS))
- if (AddLHS->getOperand(1) == RHS)
- if (auto *Addend = dyn_cast<SCEVConstant>(AddLHS->getOperand(0)))
- return Addend->getAPInt();
-
- return None;
-}
-
bool ScalarEvolution::isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred,
const SCEV *LHS,
const SCEV *RHS,
@@ -8591,7 +8581,7 @@ bool ScalarEvolution::isImpliedCondOpera
// reduce the compile time impact of this optimization.
return false;
- Optional<APInt> Addend = getConstantDifference(LHS, FoundLHS);
+ Optional<APInt> Addend = computeConstantDifference(LHS, FoundLHS);
if (!Addend)
return false;
Modified: llvm/trunk/test/Analysis/ScalarEvolution/no-wrap-unknown-becount.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/no-wrap-unknown-becount.ll?rev=276505&r1=276504&r2=276505&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/no-wrap-unknown-becount.ll (original)
+++ llvm/trunk/test/Analysis/ScalarEvolution/no-wrap-unknown-becount.ll Fri Jul 22 19:54:36 2016
@@ -63,6 +63,50 @@ leave:
ret void
}
+define void @s_3(i32 %start, i1* %cond) {
+; CHECK-LABEL: Classifying expressions for: @s_3
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [ %start, %entry ], [ %iv.inc, %be ]
+ %cmp = icmp slt i32 %iv, 10000
+ br i1 %cmp, label %be, label %leave
+
+be:
+ %iv.inc = add i32 %iv, 3
+ %iv.inc.sext = sext i32 %iv.inc to i64
+; CHECK: %iv.inc.sext = sext i32 %iv.inc to i64
+; CHECK-NEXT: --> {(sext i32 (3 + %start) to i64),+,3}<nsw><%loop>
+ %c = load volatile i1, i1* %cond
+ br i1 %c, label %loop, label %leave
+
+leave:
+ ret void
+}
+
+define void @s_4(i32 %start, i1* %cond) {
+; CHECK-LABEL: Classifying expressions for: @s_4
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [ %start, %entry ], [ %iv.inc, %be ]
+ %cmp = icmp sgt i32 %iv, -1000
+ br i1 %cmp, label %be, label %leave
+
+be:
+ %iv.inc = add i32 %iv, -3
+ %iv.inc.sext = sext i32 %iv.inc to i64
+; CHECK: %iv.inc.sext = sext i32 %iv.inc to i64
+; CHECK-NEXT: --> {(sext i32 (-3 + %start) to i64),+,-3}<nsw><%loop>
+ %c = load volatile i1, i1* %cond
+ br i1 %c, label %loop, label %leave
+
+leave:
+ ret void
+}
+
define void @u_0(i32 %n, i1* %cond) {
; CHECK-LABEL: Classifying expressions for: @u_0
entry:
@@ -119,6 +163,28 @@ loop:
%c = load volatile i1, i1* %cond
br i1 %c, label %loop, label %leave
+leave:
+ ret void
+}
+
+define void @u_3(i32 %start, i1* %cond) {
+; CHECK-LABEL: Classifying expressions for: @u_3
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [ %start, %entry ], [ %iv.inc, %be ]
+ %cmp = icmp ult i32 %iv, 10000
+ br i1 %cmp, label %be, label %leave
+
+be:
+ %iv.inc = add i32 %iv, 3
+ %iv.inc.zext = zext i32 %iv.inc to i64
+; CHECK: %iv.inc.zext = zext i32 %iv.inc to i64
+; CHECK-NEXT: --> {(zext i32 (3 + %start) to i64),+,3}<nuw><%loop>
+ %c = load volatile i1, i1* %cond
+ br i1 %c, label %loop, label %leave
+
leave:
ret void
}
More information about the llvm-commits
mailing list