summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/IPO/LowerTypeTests.cpp4
-rw-r--r--llvm/test/Transforms/LowerTypeTests/simplify_phi.ll20
2 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index cdda8a68ecc..21f1ed881d2 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -634,6 +634,10 @@ Value *LowerTypeTestsModule::lowerTypeTestCall(Metadata *TypeId, CallInst *CI,
Br->getMetadata(LLVMContext::MD_prof));
ReplaceInstWithInst(InitialBB->getTerminator(), NewBr);
+ // Update phis in Else resulting from InitialBB being split
+ for (auto &Phi : Else->phis())
+ Phi.addIncoming(Phi.getIncomingValueForBlock(Then), InitialBB);
+
IRBuilder<> ThenB(CI);
return createBitSetTest(ThenB, TIL, BitOffset);
}
diff --git a/llvm/test/Transforms/LowerTypeTests/simplify_phi.ll b/llvm/test/Transforms/LowerTypeTests/simplify_phi.ll
new file mode 100644
index 00000000000..e5981a73cf0
--- /dev/null
+++ b/llvm/test/Transforms/LowerTypeTests/simplify_phi.ll
@@ -0,0 +1,20 @@
+; Ensure that LowerTypeTests control flow simplification correctly handle phi nodes.
+; RUN: opt -S -lowertypetests -lowertypetests-summary-action=import -lowertypetests-read-summary=%S/Inputs/import.yaml < %s | FileCheck %s
+
+target datalayout = "e-p:64:64"
+
+declare i1 @llvm.type.test(i8* %ptr, metadata %bitset) nounwind readnone
+
+; CHECK: define i1 @bytearray7(i8* [[p:%.*]])
+define i1 @bytearray7(i8* %p) {
+ %x = call i1 @llvm.type.test(i8* %p, metadata !"bytearray7")
+ br i1 %x, label %t, label %f
+
+t:
+ br label %f
+
+f:
+ ; CHECK: %test = phi i1 [ false, %{{[0-9]+}} ], [ true, %t ], [ false, %0 ]
+ %test = phi i1 [ false, %0 ], [ true, %t ]
+ ret i1 %test
+}
OpenPOWER on IntegriCloud