Skip to content

Commit 7181572

Browse files
committed
[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
1 parent 90d5298 commit 7181572

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

llvm/lib/Transforms/Scalar/LoopDeletion.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ getValueOnFirstIteration(Value *V, DenseMap<Value *, Value *> &FirstIterValue,
191191
Value *RHS =
192192
getValueOnFirstIteration(BO->getOperand(1), FirstIterValue, SQ);
193193
FirstIterV = SimplifyBinOp(BO->getOpcode(), LHS, RHS, SQ);
194+
} else if (auto *Cmp = dyn_cast<ICmpInst>(V)) {
195+
Value *LHS =
196+
getValueOnFirstIteration(Cmp->getOperand(0), FirstIterValue, SQ);
197+
Value *RHS =
198+
getValueOnFirstIteration(Cmp->getOperand(1), FirstIterValue, SQ);
199+
FirstIterV = SimplifyICmpInst(Cmp->getPredicate(), LHS, RHS, SQ);
194200
}
195201
if (!FirstIterV)
196202
FirstIterV = V;
@@ -314,22 +320,20 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
314320
}
315321

316322
using namespace PatternMatch;
317-
ICmpInst::Predicate Pred;
318-
Value *LHS, *RHS;
323+
Value *Cond;
319324
BasicBlock *IfTrue, *IfFalse;
320325
auto *Term = BB->getTerminator();
321-
if (match(Term, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
326+
if (match(Term, m_Br(m_Value(Cond),
322327
m_BasicBlock(IfTrue), m_BasicBlock(IfFalse)))) {
323-
if (!LHS->getType()->isIntegerTy()) {
328+
auto *ICmp = dyn_cast<ICmpInst>(Cond);
329+
if (!ICmp || !ICmp->getType()->isIntegerTy()) {
324330
MarkAllSuccessorsLive(BB);
325331
continue;
326332
}
327333

328334
// Can we prove constant true or false for this condition?
329-
LHS = getValueOnFirstIteration(LHS, FirstIterValue, SQ);
330-
RHS = getValueOnFirstIteration(RHS, FirstIterValue, SQ);
331-
auto *KnownCondition = SimplifyICmpInst(Pred, LHS, RHS, SQ);
332-
if (!KnownCondition) {
335+
auto *KnownCondition = getValueOnFirstIteration(ICmp, FirstIterValue, SQ);
336+
if (KnownCondition == ICmp) {
333337
// Failed to simplify.
334338
MarkAllSuccessorsLive(BB);
335339
continue;

0 commit comments

Comments
 (0)