From 081379e8b44c7e092517c11e23dc9fcc60542c32 Mon Sep 17 00:00:00 2001 From: Jatin Bhateja Date: Sun, 26 Nov 2017 15:08:41 +0000 Subject: [PATCH] [SCEV] Adding a check on outgoing branches of a terminator instr for SCEVBackedgeConditionFolder, NFC. Summary: For a given loop, getLoopLatch returns a non-null value when a loop has only one latch block. In the modified context adding an assertion to check that both the outgoing branches of a terminator instruction (of latch) does not target same header. + few minor code reorganization. Reviewers: jbhateja Reviewed By: jbhateja Subscribers: sanjoy Differential Revision: https://reviews.llvm.org/D40460 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318997 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolution.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 53e216a5dc5..faf99c0a3c9 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -4049,9 +4049,6 @@ namespace { class SCEVInitRewriter : public SCEVRewriteVisitor { public: - SCEVInitRewriter(const Loop *L, ScalarEvolution &SE) - : SCEVRewriteVisitor(SE), L(L) {} - static const SCEV *rewrite(const SCEV *S, const Loop *L, ScalarEvolution &SE) { SCEVInitRewriter Rewriter(L, SE); @@ -4076,6 +4073,9 @@ public: bool isValid() { return Valid; } private: + explicit SCEVInitRewriter(const Loop *L, ScalarEvolution &SE) + : SCEVRewriteVisitor(SE), L(L) {} + const Loop *L; bool Valid = true; }; @@ -4093,6 +4093,8 @@ public: if (BasicBlock *Latch = L->getLoopLatch()) { BranchInst *BI = dyn_cast(Latch->getTerminator()); if (BI && BI->isConditional()) { + assert(BI->getSuccessor(0) != BI->getSuccessor(1) && + "Both outgoing branches should not target same header!"); BECond = BI->getCondition(); IsPosBECond = BI->getSuccessor(0) == L->getHeader(); } else { @@ -4160,9 +4162,6 @@ SCEVBackedgeConditionFolder::compareWithBackedgeCondition(Value *IC) { class SCEVShiftRewriter : public SCEVRewriteVisitor { public: - SCEVShiftRewriter(const Loop *L, ScalarEvolution &SE) - : SCEVRewriteVisitor(SE), L(L) {} - static const SCEV *rewrite(const SCEV *S, const Loop *L, ScalarEvolution &SE) { SCEVShiftRewriter Rewriter(L, SE); @@ -4187,6 +4186,9 @@ public: bool isValid() { return Valid; } private: + explicit SCEVShiftRewriter(const Loop *L, ScalarEvolution &SE) + : SCEVRewriteVisitor(SE), L(L) {} + const Loop *L; bool Valid = true; }; @@ -11342,10 +11344,6 @@ namespace { class SCEVPredicateRewriter : public SCEVRewriteVisitor { public: - SCEVPredicateRewriter(const Loop *L, ScalarEvolution &SE, - SmallPtrSetImpl *NewPreds, - SCEVUnionPredicate *Pred) - : SCEVRewriteVisitor(SE), NewPreds(NewPreds), Pred(Pred), L(L) {} /// Rewrites \p S in the context of a loop L and the SCEV predication /// infrastructure. @@ -11406,6 +11404,11 @@ public: } private: + explicit SCEVPredicateRewriter(const Loop *L, ScalarEvolution &SE, + SmallPtrSetImpl *NewPreds, + SCEVUnionPredicate *Pred) + : SCEVRewriteVisitor(SE), NewPreds(NewPreds), Pred(Pred), L(L) {} + bool addOverflowAssumption(const SCEVPredicate *P) { if (!NewPreds) { // Check if we've already made this assumption. -- 2.11.0