summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorXin Tong <trent.xin.tong@gmail.com>2017-04-10 00:33:25 +0000
committerXin Tong <trent.xin.tong@gmail.com>2017-04-10 00:33:25 +0000
commit34888c08bc72813f959ce8f3bee85d313bebcf69 (patch)
tree331761f6867e41f294e365568d801e9396b7d697 /llvm/test
parent16a054d5c7350a879b1852f6fe76827d514c2c70 (diff)
downloadbcm5719-llvm-34888c08bc72813f959ce8f3bee85d313bebcf69.tar.gz
bcm5719-llvm-34888c08bc72813f959ce8f3bee85d313bebcf69.zip
[SCCP] Resolve indirect branch target when possible.
Summary: Resolve indirect branch target when possible. This potentially eliminates more basicblocks and result in better evaluation for phi and other things. Reviewers: davide, efriedma, sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D30322 llvm-svn: 299830
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Transforms/SCCP/indirectbr.ll76
1 files changed, 76 insertions, 0 deletions
diff --git a/llvm/test/Transforms/SCCP/indirectbr.ll b/llvm/test/Transforms/SCCP/indirectbr.ll
new file mode 100644
index 00000000000..b977961ca49
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/indirectbr.ll
@@ -0,0 +1,76 @@
+; RUN: opt -S -sccp < %s | FileCheck %s
+
+declare void @BB0_f()
+declare void @BB1_f()
+
+; Make sure we can eliminate what is in BB0 as we know that the indirectbr is going to BB1.
+;
+; CHECK-LABEL: define void @indbrtest1(
+; CHECK-NOT: call void @BB0_f()
+; CHECK: ret void
+define void @indbrtest1() {
+entry:
+ indirectbr i8* blockaddress(@indbrtest1, %BB1), [label %BB0, label %BB1]
+BB0:
+ call void @BB0_f()
+ br label %BB1
+BB1:
+ call void @BB1_f()
+ ret void
+}
+
+; Make sure we can eliminate what is in BB0 as we know that the indirectbr is going to BB1
+; by looking through the casts. The casts should be folded away when they are visited
+; before the indirectbr instruction.
+;
+; CHECK-LABEL: define void @indbrtest2(
+; CHECK-NOT: call void @BB0_f()
+; CHECK: ret void
+define void @indbrtest2() {
+entry:
+ %a = ptrtoint i8* blockaddress(@indbrtest2, %BB1) to i64
+ %b = inttoptr i64 %a to i8*
+ %c = bitcast i8* %b to i8*
+ indirectbr i8* %b, [label %BB0, label %BB1]
+BB0:
+ call void @BB0_f()
+ br label %BB1
+BB1:
+ call void @BB1_f()
+ ret void
+}
+
+; Make sure we can not eliminate BB0 as we do not know the target of the indirectbr.
+;
+; CHECK-LABEL: define void @indbrtest3(
+; CHECK: call void @BB0_f()
+; CHECK: ret void
+define void @indbrtest3(i8** %Q) {
+entry:
+ %t = load i8*, i8** %Q
+ indirectbr i8* %t, [label %BB0, label %BB1]
+BB0:
+ call void @BB0_f()
+ br label %BB1
+BB1:
+ call void @BB1_f()
+ ret void
+}
+
+; Make sure we eliminate BB1 as we pick the first successor on undef.
+;
+; CHECK-LABEL: define void @indbrtest4(
+; CHECK: call void @BB0_f()
+; CHECK: ret void
+define void @indbrtest4(i8** %Q) {
+entry:
+ indirectbr i8* undef, [label %BB0, label %BB1]
+BB0:
+ call void @BB0_f()
+ br label %BB1
+BB1:
+ call void @BB1_f()
+ ret void
+}
+
+
OpenPOWER on IntegriCloud