[PATCH] GVN: If a branch has two identical successors, we cannot declare either dead.
Peter Collingbourne
peter at pcc.me.uk
Thu Jun 25 00:52:45 PDT 2015
Hi spatel,
This previously caused miscompilations as a result of phi nodes receiving
undef incoming values from blocks dominated by such successors.
http://reviews.llvm.org/D10726
Files:
lib/Transforms/Scalar/GVN.cpp
test/Transforms/GVN/br-identical.ll
Index: lib/Transforms/Scalar/GVN.cpp
===================================================================
--- lib/Transforms/Scalar/GVN.cpp
+++ lib/Transforms/Scalar/GVN.cpp
@@ -2808,6 +2808,10 @@
if (!BI || BI->isUnconditional())
return false;
+ // If a branch has two identical successors, we cannot declare either dead.
+ if (BI->getSuccessor(0) == BI->getSuccessor(1))
+ return false;
+
ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition());
if (!Cond)
return false;
Index: test/Transforms/GVN/br-identical.ll
===================================================================
--- /dev/null
+++ test/Transforms/GVN/br-identical.ll
@@ -0,0 +1,61 @@
+; RUN: opt -gvn -S -o - %s | FileCheck %s
+
+define void @widget() {
+bb21:
+ br label %bb22
+
+bb22:
+ %tmp = phi i64 [ 0, %bb21 ], [ %tmp75, %bb74 ]
+ %tmp24 = add i64 %tmp, 1
+ br i1 undef, label %bb27, label %bb59
+
+bb27:
+ %tmp28 = sub i64 %tmp24, 0
+ %tmp29 = icmp ult i64 0, %tmp28
+ br i1 %tmp29, label %bb30, label %bb55
+
+bb30:
+ br label %bb32
+
+bb32:
+ br i1 undef, label %bb38, label %bb32
+
+ %tmp35 = call i8* @f()
+ br label %bb36
+
+bb36:
+ br label %bb38
+
+bb38:
+ %tmp39 = phi i8* [ %tmp35, %bb36 ], [ null, %bb32 ]
+ %tmp40 = bitcast i8* %tmp39 to double*
+ br label %bb52
+
+bb52:
+ %tmp53 = getelementptr double, double* %tmp40
+ %tmp54 = ptrtoint double* %tmp53 to i64
+ br label %bb55
+
+bb55:
+ ; CHECK-NOT: phi {{.*}} undef
+ %1 = phi i64 [ %tmp54, %bb52 ], [ 0, %bb27 ]
+ br label %bb59
+
+bb59:
+ br i1 undef, label %bb73, label %bb72
+
+bb72:
+ br i1 true, label %bb74, label %bb74
+
+bb73:
+ br i1 true, label %bb74, label %bb74
+
+bb74:
+ %tmp75 = add i64 %tmp, 1
+ br i1 undef, label %bb22, label %bb77
+
+bb77:
+ ret void
+}
+
+declare i8* @f()
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10726.28440.patch
Type: text/x-patch
Size: 1796 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150625/905f7a39/attachment.bin>
More information about the llvm-commits
mailing list