From 83f895d95291ede8ec901b13414bf6ba9c5692c1 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Tue, 8 Feb 2022 11:39:22 -0800 Subject: [PATCH] [SCEV] Add interface for constructing generic SCEVComparePredicate [NFC} --- llvm/include/llvm/Analysis/ScalarEvolution.h | 2 ++ llvm/lib/Analysis/ScalarEvolution.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 51b15510a3ad..7c1c7e32f563 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1167,6 +1167,8 @@ public: } const SCEVPredicate *getEqualPredicate(const SCEV *LHS, const SCEV *RHS); + const SCEVPredicate *getComparePredicate(ICmpInst::Predicate Pred, + const SCEV *LHS, const SCEV *RHS); const SCEVPredicate * getWrapPredicate(const SCEVAddRecExpr *AR, diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index fca5614c7469..620f3bf61af3 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -13537,19 +13537,25 @@ void ScalarEvolutionWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { const SCEVPredicate *ScalarEvolution::getEqualPredicate(const SCEV *LHS, const SCEV *RHS) { + return getComparePredicate(ICmpInst::ICMP_EQ, LHS, RHS); +} + +const SCEVPredicate * +ScalarEvolution::getComparePredicate(const ICmpInst::Predicate Pred, + const SCEV *LHS, const SCEV *RHS) { FoldingSetNodeID ID; assert(LHS->getType() == RHS->getType() && "Type mismatch between LHS and RHS"); // Unique this node based on the arguments ID.AddInteger(SCEVPredicate::P_Compare); - ID.AddInteger(ICmpInst::ICMP_EQ); + ID.AddInteger(Pred); ID.AddPointer(LHS); ID.AddPointer(RHS); void *IP = nullptr; if (const auto *S = UniquePreds.FindNodeOrInsertPos(ID, IP)) return S; SCEVComparePredicate *Eq = new (SCEVAllocator) - SCEVComparePredicate(ID.Intern(SCEVAllocator), ICmpInst::ICMP_EQ, LHS, RHS); + SCEVComparePredicate(ID.Intern(SCEVAllocator), Pred, LHS, RHS); UniquePreds.InsertNode(Eq, IP); return Eq; }