[llvm-commits] [llvm] r82970 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/select.ll

Chris Lattner sabre at nondot.org
Sun Sep 27 23:49:44 PDT 2009


Author: lattner
Date: Mon Sep 28 01:49:44 2009
New Revision: 82970

URL: http://llvm.org/viewvc/llvm-project?rev=82970&view=rev
Log:
The select instruction is not neccesarily in the same block as the
phi nodes.  Make sure to phi translate from the right block. 

This fixes a llvm-building-llvm failure on GVN-PRE.cpp

Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
    llvm/trunk/test/Transforms/InstCombine/select.ll

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=82970&r1=82969&r2=82970&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Sep 28 01:49:44 2009
@@ -2002,10 +2002,11 @@
     // not the true/false values.
     Value *TrueV = SI->getTrueValue();
     Value *FalseV = SI->getFalseValue();
+    BasicBlock *PhiTransBB = PN->getParent();
     for (unsigned i = 0; i != NumPHIValues; ++i) {
       BasicBlock *ThisBB = PN->getIncomingBlock(i);
-      Value *TrueVInPred = TrueV->DoPHITranslation(I.getParent(), ThisBB);
-      Value *FalseVInPred = FalseV->DoPHITranslation(I.getParent(), ThisBB);
+      Value *TrueVInPred = TrueV->DoPHITranslation(PhiTransBB, ThisBB);
+      Value *FalseVInPred = FalseV->DoPHITranslation(PhiTransBB, ThisBB);
       Value *InV = 0;
       if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i))) {
         InV = InC->isNullValue() ? FalseVInPred : TrueVInPred;

Modified: llvm/trunk/test/Transforms/InstCombine/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=82970&r1=82969&r2=82970&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/select.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/select.ll Mon Sep 28 01:49:44 2009
@@ -247,3 +247,19 @@
   %b = select i1 %a, i32 %A, i32 %c
   ret i32 %b
 }
+
+define i32 @test29(i1 %cond, i32 %A, i32 %B)  {
+entry:
+  br i1 %cond, label %jump, label %ret
+jump:
+  br label %ret 
+ret:
+  %c = phi i32 [%A, %jump], [%B, %entry]
+  %a = phi i1 [true, %jump], [false, %entry]
+  br label %next
+  
+next:
+  %b = select i1 %a, i32 %A, i32 %c
+  ret i32 %b
+}
+





More information about the llvm-commits mailing list