[llvm] 16fde88 - [SCEV] Support unsigned predicates in isKnownPredicateViaNoOverflow
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 03:14:24 PDT 2020
Author: Max Kazantsev
Date: 2020-09-22T17:14:05+07:00
New Revision: 16fde88dbd797b01f3c236062fbec50fe5bbf81d
URL: https://github.com/llvm/llvm-project/commit/16fde88dbd797b01f3c236062fbec50fe5bbf81d
DIFF: https://github.com/llvm/llvm-project/commit/16fde88dbd797b01f3c236062fbec50fe5bbf81d.diff
LOG: [SCEV] Support unsigned predicates in isKnownPredicateViaNoOverflow
SCEV should be able to prove facts like `x <u x+1<nuw>`.
Differential Revision: https://reviews.llvm.org/D88015
Reviewed By: lebedev.ri
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/unittests/Analysis/ScalarEvolutionTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 3bf7f2036136..39bccecd678c 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9314,6 +9314,24 @@ bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred,
if (MatchBinaryAddToConst(LHS, RHS, C, SCEV::FlagNSW) && C.isNegative())
return true;
break;
+
+ case ICmpInst::ICMP_UGE:
+ std::swap(LHS, RHS);
+ LLVM_FALLTHROUGH;
+ case ICmpInst::ICMP_ULE:
+ // X u<= (X + C)<nuw> for any C
+ if (MatchBinaryAddToConst(RHS, LHS, C, SCEV::FlagNUW))
+ return true;
+ break;
+
+ case ICmpInst::ICMP_UGT:
+ std::swap(LHS, RHS);
+ LLVM_FALLTHROUGH;
+ case ICmpInst::ICMP_ULT:
+ // X u< (X + C)<nuw> if C != 0
+ if (MatchBinaryAddToConst(RHS, LHS, C, SCEV::FlagNUW) && !C.isNullValue())
+ return true;
+ break;
}
return false;
diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
index 156427f56ead..04aaae18be27 100644
--- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
+++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -1165,4 +1165,25 @@ TEST_F(ScalarEvolutionsTest, SCEVrewriteUnknowns) {
cast<SCEVAddRecExpr>(ScevIV)->getStepRecurrence(SE));
});
}
+
+TEST_F(ScalarEvolutionsTest, SCEVAddNUW) {
+ LLVMContext C;
+ SMDiagnostic Err;
+ std::unique_ptr<Module> M = parseAssemblyString("define void @foo(i32 %x) { "
+ " ret void "
+ "} ",
+ Err, C);
+
+ ASSERT_TRUE(M && "Could not parse module?");
+ ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
+
+ runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
+ auto *X = SE.getSCEV(getArgByName(F, "x"));
+ auto *One = SE.getOne(X->getType());
+ auto *Sum = SE.getAddExpr(X, One, SCEV::FlagNUW);
+ EXPECT_TRUE(SE.isKnownPredicate(ICmpInst::ICMP_UGE, Sum, X));
+ EXPECT_TRUE(SE.isKnownPredicate(ICmpInst::ICMP_UGT, Sum, X));
+ });
+}
+
} // end namespace llvm
More information about the llvm-commits
mailing list