From d16989607bef594007cb571e0383bd14d7a72fe9 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 18 Oct 2022 10:35:12 -0400 Subject: [PATCH] [InstCombine] reduce code duplication in visitBranchInst(); NFCI --- .../Transforms/InstCombine/InstructionCombining.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 6771cd9..c75f22f 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3133,9 +3133,9 @@ Instruction *InstCombinerImpl::visitBranchInst(BranchInst &BI) { return visitUnconditionalBranchInst(BI); // Change br (not X), label True, label False to: br X, label False, True + Value *Cond = BI.getCondition(); Value *X = nullptr; - if (match(&BI, m_Br(m_Not(m_Value(X)), m_BasicBlock(), m_BasicBlock())) && - !isa(X)) { + if (match(Cond, m_Not(m_Value(X))) && !isa(X)) { // Swap Destinations and condition... BI.swapSuccessors(); return replaceOperand(BI, 0, X); @@ -3143,21 +3143,18 @@ Instruction *InstCombinerImpl::visitBranchInst(BranchInst &BI) { // If the condition is irrelevant, remove the use so that other // transforms on the condition become more effective. - if (!isa(BI.getCondition()) && - BI.getSuccessor(0) == BI.getSuccessor(1)) - return replaceOperand( - BI, 0, ConstantInt::getFalse(BI.getCondition()->getType())); + if (!isa(Cond) && BI.getSuccessor(0) == BI.getSuccessor(1)) + return replaceOperand(BI, 0, ConstantInt::getFalse(Cond->getType())); // Canonicalize, for example, fcmp_one -> fcmp_oeq. CmpInst::Predicate Pred; - if (match(&BI, m_Br(m_OneUse(m_FCmp(Pred, m_Value(), m_Value())), - m_BasicBlock(), m_BasicBlock())) && + if (match(Cond, m_OneUse(m_FCmp(Pred, m_Value(), m_Value()))) && !isCanonicalPredicate(Pred)) { // Swap destinations and condition. - CmpInst *Cond = cast(BI.getCondition()); - Cond->setPredicate(CmpInst::getInversePredicate(Pred)); + auto *Cmp = cast(Cond); + Cmp->setPredicate(CmpInst::getInversePredicate(Pred)); BI.swapSuccessors(); - Worklist.push(Cond); + Worklist.push(Cmp); return &BI; } -- 2.7.4