[llvm] b0b2bf3 - [NFCI][LoopDeletion] Only query SCEV about loop successor if another successor is also in loop
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Wed May 26 22:44:53 PDT 2021
Author: Max Kazantsev
Date: 2021-05-27T12:44:22+07:00
New Revision: b0b2bf3b5da950679db1431aae431a6dedea2245
URL: https://github.com/llvm/llvm-project/commit/b0b2bf3b5da950679db1431aae431a6dedea2245
DIFF: https://github.com/llvm/llvm-project/commit/b0b2bf3b5da950679db1431aae431a6dedea2245.diff
LOG: [NFCI][LoopDeletion] Only query SCEV about loop successor if another successor is also in loop
Added:
Modified:
llvm/lib/Transforms/Scalar/LoopDeletion.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
index 41be776ec141..14eb07ab17e6 100644
--- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -267,10 +267,10 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
ICmpInst::Predicate Pred;
Value *LHS, *RHS;
const BasicBlock *IfTrue, *IfFalse;
+ auto *Term = BB->getTerminator();
// TODO: Handle switches.
- if (!match(BB->getTerminator(),
- m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
- m_BasicBlock(IfTrue), m_BasicBlock(IfFalse)))) {
+ if (!match(Term, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
+ m_BasicBlock(IfTrue), m_BasicBlock(IfFalse)))) {
MarkAllSuccessorsLive(BB);
continue;
}
@@ -283,13 +283,16 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
// Can we prove constant true or false for this condition?
const SCEV *LHSS = getSCEVOnFirstIteration(LHS, L, SE, FirstIterSCEV);
const SCEV *RHSS = getSCEVOnFirstIteration(RHS, L, SE, FirstIterSCEV);
- // TODO: isKnownPredicateAt is more powerful, but it's too compile time
- // consuming. So we avoid using it here.
- if (SE.isKnownPredicate(Pred, LHSS, RHSS))
- MarkLiveEdge(BB, BB->getTerminator()->getSuccessor(0));
- else if (SE.isKnownPredicate(ICmpInst::getInversePredicate(Pred), LHSS,
- RHSS))
- MarkLiveEdge(BB, BB->getTerminator()->getSuccessor(1));
+ // Only query for liveness of in-loop edge if another successor is also
+ // in-loop.
+ // TODO: isKnownPredicateAt is more powerful, but it's too compile time
+ // consuming. So we avoid using it here.
+ if (L->contains(Term->getSuccessor(1)) &&
+ SE.isKnownPredicate(Pred, LHSS, RHSS))
+ MarkLiveEdge(BB, Term->getSuccessor(0));
+ else if (L->contains(Term->getSuccessor(0)) &&
+ SE.isKnownPredicate(ICmpInst::getInversePredicate(Pred), LHSS,
+ RHSS)) MarkLiveEdge(BB, Term->getSuccessor(1));
else
MarkAllSuccessorsLive(BB);
}
More information about the llvm-commits
mailing list