Implement select.ll:test16: fold load (select C, X, null) -> load X
authorChris Lattner <sabre@nondot.org>
Thu, 23 Sep 2004 15:46:00 +0000 (15:46 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 23 Sep 2004 15:46:00 +0000 (15:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16499 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 462824d1f8f1ede090143af1bbb968b4a7d16be1..f4edc4cb50534fe8de8d7697b2174ded00af36bf 100644 (file)
@@ -3071,6 +3071,20 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
         return new SelectInst(SI->getCondition(), V1, V2);
       }
 
+      // load (select (cond, null, P)) -> load P
+      if (Constant *C = dyn_cast<Constant>(SI->getOperand(1)))
+        if (C->isNullValue()) {
+          LI.setOperand(0, SI->getOperand(2));
+          return &LI;
+        }
+
+      // load (select (cond, P, null)) -> load P
+      if (Constant *C = dyn_cast<Constant>(SI->getOperand(2)))
+        if (C->isNullValue()) {
+          LI.setOperand(0, SI->getOperand(1));
+          return &LI;
+        }
+
     } else if (PHINode *PN = dyn_cast<PHINode>(Op)) {
       // load (phi (&V1, &V2, &V3))  --> phi(load &V1, load &V2, load &V3)
       bool Safe = PN->getParent() == LI.getParent();