Do not insert trivially dead select instructions, which allows us to
authorChris Lattner <sabre@nondot.org>
Wed, 29 Sep 2004 05:43:32 +0000 (05:43 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 29 Sep 2004 05:43:32 +0000 (05:43 +0000)
potentially fold more in one pass.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16583 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp

index baa737eddb83f533b7da59f6e07e41a7e567ccaa..77d3fe36583f5654b9172db05b792ecea8e4d6c2 100644 (file)
@@ -753,10 +753,19 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
             FalseSucc->removePredecessor(BI->getParent());
 
             // Insert a new select instruction.
-            Value *NewRetVal = new SelectInst(BI->getCondition(), TrueValue,
-                                              FalseValue, "retval", BI);
+            Value *NewRetVal;
+            Value *BrCond = BI->getCondition();
+            if (TrueValue != FalseValue)
+              NewRetVal = new SelectInst(BrCond, TrueValue,
+                                         FalseValue, "retval", BI);
+            else
+              NewRetVal = TrueValue;
+
             new ReturnInst(NewRetVal, BI);
             BI->getParent()->getInstList().erase(BI);
+            if (BrCond->use_empty())
+              if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond))
+                BrCondI->getParent()->getInstList().erase(BrCondI);
             return true;
           }
         }