Skip to content

Commit d169896

Browse files
committed
[InstCombine] reduce code duplication in visitBranchInst(); NFCI
1 parent 57ba07c commit d169896

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,31 +3133,28 @@ Instruction *InstCombinerImpl::visitBranchInst(BranchInst &BI) {
31333133
return visitUnconditionalBranchInst(BI);
31343134

31353135
// Change br (not X), label True, label False to: br X, label False, True
3136+
Value *Cond = BI.getCondition();
31363137
Value *X = nullptr;
3137-
if (match(&BI, m_Br(m_Not(m_Value(X)), m_BasicBlock(), m_BasicBlock())) &&
3138-
!isa<Constant>(X)) {
3138+
if (match(Cond, m_Not(m_Value(X))) && !isa<Constant>(X)) {
31393139
// Swap Destinations and condition...
31403140
BI.swapSuccessors();
31413141
return replaceOperand(BI, 0, X);
31423142
}
31433143

31443144
// If the condition is irrelevant, remove the use so that other
31453145
// transforms on the condition become more effective.
3146-
if (!isa<ConstantInt>(BI.getCondition()) &&
3147-
BI.getSuccessor(0) == BI.getSuccessor(1))
3148-
return replaceOperand(
3149-
BI, 0, ConstantInt::getFalse(BI.getCondition()->getType()));
3146+
if (!isa<ConstantInt>(Cond) && BI.getSuccessor(0) == BI.getSuccessor(1))
3147+
return replaceOperand(BI, 0, ConstantInt::getFalse(Cond->getType()));
31503148

31513149
// Canonicalize, for example, fcmp_one -> fcmp_oeq.
31523150
CmpInst::Predicate Pred;
3153-
if (match(&BI, m_Br(m_OneUse(m_FCmp(Pred, m_Value(), m_Value())),
3154-
m_BasicBlock(), m_BasicBlock())) &&
3151+
if (match(Cond, m_OneUse(m_FCmp(Pred, m_Value(), m_Value()))) &&
31553152
!isCanonicalPredicate(Pred)) {
31563153
// Swap destinations and condition.
3157-
CmpInst *Cond = cast<CmpInst>(BI.getCondition());
3158-
Cond->setPredicate(CmpInst::getInversePredicate(Pred));
3154+
auto *Cmp = cast<CmpInst>(Cond);
3155+
Cmp->setPredicate(CmpInst::getInversePredicate(Pred));
31593156
BI.swapSuccessors();
3160-
Worklist.push(Cond);
3157+
Worklist.push(Cmp);
31613158
return &BI;
31623159
}
31633160

0 commit comments

Comments
 (0)