aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-09-28 06:49:44 +0000
committerChris Lattner <sabre@nondot.org>2009-09-28 06:49:44 +0000
commitda3ee9ce1a46cf351e614a6c17627b63cec9b2b4 (patch)
tree3f48d7c7603349fdccf1da0bf2285df424ba6b97
parent58cb38c09d1b7e0e8c27d56ac94a524552ef436c (diff)
downloadexternal_llvm-da3ee9ce1a46cf351e614a6c17627b63cec9b2b4.zip
external_llvm-da3ee9ce1a46cf351e614a6c17627b63cec9b2b4.tar.gz
external_llvm-da3ee9ce1a46cf351e614a6c17627b63cec9b2b4.tar.bz2
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
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp5
-rw-r--r--test/Transforms/InstCombine/select.ll16
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 6826e13..561527c 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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<Constant>(PN->getIncomingValue(i))) {
InV = InC->isNullValue() ? FalseVInPred : TrueVInPred;
diff --git a/test/Transforms/InstCombine/select.ll b/test/Transforms/InstCombine/select.ll
index 701d596..b04382e 100644
--- a/test/Transforms/InstCombine/select.ll
+++ b/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
+}
+