diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 6826e1327350..561527cbb461 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2002,10 +2002,11 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I, // 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(PN->getIncomingValue(i))) { InV = InC->isNullValue() ? FalseVInPred : TrueVInPred; diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll index 701d5967a67c..b04382e8b113 100644 --- a/llvm/test/Transforms/InstCombine/select.ll +++ b/llvm/test/Transforms/InstCombine/select.ll @@ -247,3 +247,19 @@ ret: %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 +} +