[llvm] 60da436 - [NFC] Bail early simplifying unconditional branches

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 00:00:59 PDT 2020


Author: Max Kazantsev
Date: 2020-06-15T13:59:53+07:00
New Revision: 60da4369a1cc65685922f2eed7cfb73f0f4b96e7

URL: https://github.com/llvm/llvm-project/commit/60da4369a1cc65685922f2eed7cfb73f0f4b96e7
DIFF: https://github.com/llvm/llvm-project/commit/60da4369a1cc65685922f2eed7cfb73f0f4b96e7.diff

LOG: [NFC] Bail early simplifying unconditional branches

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index c13f8ba8e8fe..442efdbcaf71 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2737,6 +2737,10 @@ Instruction *InstCombiner::visitReturnInst(ReturnInst &RI) {
 }
 
 Instruction *InstCombiner::visitBranchInst(BranchInst &BI) {
+  // Nothing to do about unconditional branches.
+  if (BI.isUnconditional())
+    return nullptr;
+
   // Change br (not X), label True, label False to: br X, label False, True
   Value *X = nullptr;
   if (match(&BI, m_Br(m_Not(m_Value(X)), m_BasicBlock(), m_BasicBlock())) &&
@@ -2748,7 +2752,7 @@ Instruction *InstCombiner::visitBranchInst(BranchInst &BI) {
 
   // If the condition is irrelevant, remove the use so that other
   // transforms on the condition become more effective.
-  if (BI.isConditional() && !isa<ConstantInt>(BI.getCondition()) &&
+  if (!isa<ConstantInt>(BI.getCondition()) &&
       BI.getSuccessor(0) == BI.getSuccessor(1))
     return replaceOperand(
         BI, 0, ConstantInt::getFalse(BI.getCondition()->getType()));


        


More information about the llvm-commits mailing list