[llvm] 7181572 - [LoopDeletion] Move ICmpInst handling to getValueOnFirstIteration()
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 3 04:36:46 PDT 2021
Author: Max Kazantsev
Date: 2021-09-03T18:36:19+07:00
New Revision: 718157283c7954e744041a5b04f91037f4a487d6
URL: https://github.com/llvm/llvm-project/commit/718157283c7954e744041a5b04f91037f4a487d6
DIFF: https://github.com/llvm/llvm-project/commit/718157283c7954e744041a5b04f91037f4a487d6.diff
LOG: [LoopDeletion] Move ICmpInst handling to getValueOnFirstIteration()
As noticed in https://reviews.llvm.org/D105688, it would be great to move
handling of ICmpInst which was in canProveExitOnFirstIteration() to
getValueOnFirstIteration().
Patch by Dmitry Makogon!
Differential Revision: https://reviews.llvm.org/D108978
Reviewed By: reames
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 73f97f2b6e51..e1e5ef958363 100644
--- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -191,6 +191,12 @@ getValueOnFirstIteration(Value *V, DenseMap<Value *, Value *> &FirstIterValue,
Value *RHS =
getValueOnFirstIteration(BO->getOperand(1), FirstIterValue, SQ);
FirstIterV = SimplifyBinOp(BO->getOpcode(), LHS, RHS, SQ);
+ } else if (auto *Cmp = dyn_cast<ICmpInst>(V)) {
+ Value *LHS =
+ getValueOnFirstIteration(Cmp->getOperand(0), FirstIterValue, SQ);
+ Value *RHS =
+ getValueOnFirstIteration(Cmp->getOperand(1), FirstIterValue, SQ);
+ FirstIterV = SimplifyICmpInst(Cmp->getPredicate(), LHS, RHS, SQ);
}
if (!FirstIterV)
FirstIterV = V;
@@ -314,22 +320,20 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
}
using namespace PatternMatch;
- ICmpInst::Predicate Pred;
- Value *LHS, *RHS;
+ Value *Cond;
BasicBlock *IfTrue, *IfFalse;
auto *Term = BB->getTerminator();
- if (match(Term, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
+ if (match(Term, m_Br(m_Value(Cond),
m_BasicBlock(IfTrue), m_BasicBlock(IfFalse)))) {
- if (!LHS->getType()->isIntegerTy()) {
+ auto *ICmp = dyn_cast<ICmpInst>(Cond);
+ if (!ICmp || !ICmp->getType()->isIntegerTy()) {
MarkAllSuccessorsLive(BB);
continue;
}
// Can we prove constant true or false for this condition?
- LHS = getValueOnFirstIteration(LHS, FirstIterValue, SQ);
- RHS = getValueOnFirstIteration(RHS, FirstIterValue, SQ);
- auto *KnownCondition = SimplifyICmpInst(Pred, LHS, RHS, SQ);
- if (!KnownCondition) {
+ auto *KnownCondition = getValueOnFirstIteration(ICmp, FirstIterValue, SQ);
+ if (KnownCondition == ICmp) {
// Failed to simplify.
MarkAllSuccessorsLive(BB);
continue;
More information about the llvm-commits
mailing list