summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/JumpThreading/loop-phi.ll
diff options
context:
space:
mode:
authorEli Friedman <efriedma@quicinc.com>2019-07-03 23:12:39 +0000
committerEli Friedman <efriedma@quicinc.com>2019-07-03 23:12:39 +0000
commit41ee3977c45a056011ffbdc2a7d31f59c18a7ae1 (patch)
treee29748500e5d53447b62236518e20f8b68dcaf69 /llvm/test/Transforms/JumpThreading/loop-phi.ll
parent43cbca50e42808f382ac1b0d5f4193bc52ce1fa2 (diff)
downloadbcm5719-llvm-41ee3977c45a056011ffbdc2a7d31f59c18a7ae1.tar.gz
bcm5719-llvm-41ee3977c45a056011ffbdc2a7d31f59c18a7ae1.zip
[JumpThreading] Fix threading with unusual PHI nodes.
If the block being cloned contains a PHI node, in general, we need to clone that PHI node, even though it's trivial. If the operand of the PHI is an instruction in the block being cloned, the correct value for the operand doesn't exist until SSAUpdater constructs it. We usually don't hit this issue because we try to avoid threading across loop headers, but it's possible to hit this in some cases involving irreducible CFGs. I added a flag to allow threading across loop headers to make the testcase easier to understand. Thanks to Brian Rzycki for reducing the testcase. Fixes https://bugs.llvm.org/show_bug.cgi?id=42085. Differential Revision: https://reviews.llvm.org/D63913 llvm-svn: 365094
Diffstat (limited to 'llvm/test/Transforms/JumpThreading/loop-phi.ll')
-rw-r--r--llvm/test/Transforms/JumpThreading/loop-phi.ll41
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/test/Transforms/JumpThreading/loop-phi.ll b/llvm/test/Transforms/JumpThreading/loop-phi.ll
new file mode 100644
index 00000000000..7ec69f97c25
--- /dev/null
+++ b/llvm/test/Transforms/JumpThreading/loop-phi.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -jump-threading -S -jump-threading-across-loop-headers | FileCheck %s
+
+; Make sure we correctly distinguish between %tmp15 and %tmp16 when we clone
+; body2.
+
+; CHECK: body2.thread:
+; CHECK-NEXT: %tmp163 = add i32 %tmp165, 1
+; CHECK-NEXT: br label %latch1
+
+; CHECK: latch1:
+; CHECK-NEXT: %tmp165 = phi i32 [ %tmp163, %body2.thread ], [ %tmp16, %body2 ]
+; CHECK-NEXT: %tmp154 = phi i32 [ %tmp165, %body2.thread ], [ %tmp15, %body2 ]
+
+define i32 @test(i1 %ARG1, i1 %ARG2, i32 %n) {
+entry:
+ br label %head1
+
+head1: ; preds = %entry, %body1
+ %tmp = phi i32 [ 0, %entry ], [ %tmp16, %body1 ]
+ %tmp3 = phi i32 [ 0, %entry ], [ %tmp16, %body1 ]
+ %tmp4 = phi i32 [ 0, %entry ], [ %tmp16, %body1 ]
+ br i1 %ARG1, label %exit, label %body2
+
+body1: ; preds = %latch1
+ %tmp12 = icmp sgt i32 %tmp16, 1
+ br i1 %tmp12, label %body2, label %head1
+
+body2: ; preds = %head1, %body1
+ %tmp14 = phi i32 [ %tmp16, %body1 ], [ %tmp, %head1 ]
+ %tmp15 = phi i32 [ %tmp16, %body1 ], [ %tmp3, %head1 ]
+ %tmp16 = add i32 %tmp14, 1
+ br i1 %ARG2, label %exit, label %latch1
+
+latch1: ; preds = %body2
+ %tmp18 = icmp sgt i32 %tmp16, %n
+ br i1 %tmp18, label %exit, label %body1
+
+exit: ; preds = %latch1, %body2, %head1
+ %rc = phi i32 [ %tmp15, %body2 ], [ %tmp15, %latch1 ], [ -1, %head1 ]
+ ret i32 %rc
+}
OpenPOWER on IntegriCloud