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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82970 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-09-28 06:49:44 +00:00
parent 0e6b590b91
commit 3ddfb21306
2 changed files with 19 additions and 2 deletions

View File

@ -2002,10 +2002,11 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I,
// not the true/false values. // not the true/false values.
Value *TrueV = SI->getTrueValue(); Value *TrueV = SI->getTrueValue();
Value *FalseV = SI->getFalseValue(); Value *FalseV = SI->getFalseValue();
BasicBlock *PhiTransBB = PN->getParent();
for (unsigned i = 0; i != NumPHIValues; ++i) { for (unsigned i = 0; i != NumPHIValues; ++i) {
BasicBlock *ThisBB = PN->getIncomingBlock(i); BasicBlock *ThisBB = PN->getIncomingBlock(i);
Value *TrueVInPred = TrueV->DoPHITranslation(I.getParent(), ThisBB); Value *TrueVInPred = TrueV->DoPHITranslation(PhiTransBB, ThisBB);
Value *FalseVInPred = FalseV->DoPHITranslation(I.getParent(), ThisBB); Value *FalseVInPred = FalseV->DoPHITranslation(PhiTransBB, ThisBB);
Value *InV = 0; Value *InV = 0;
if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i))) { if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i))) {
InV = InC->isNullValue() ? FalseVInPred : TrueVInPred; InV = InC->isNullValue() ? FalseVInPred : TrueVInPred;

View File

@ -247,3 +247,19 @@ ret:
%b = select i1 %a, i32 %A, i32 %c %b = select i1 %a, i32 %A, i32 %c
ret i32 %b 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
}