summaryrefslogtreecommitdiff
path: root/test/Transforms/SCCP
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-10-23 14:19:52 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-10-23 14:19:52 +0000
commit4a142eb28942073eb27a112b5ca1cca3f01beb9c (patch)
tree22cc59e4b240d84c3a5a60531119c4eca914a256 /test/Transforms/SCCP
parent5cd822fa9bbb9622241e3bf4d7674ed49ccde5b9 (diff)
Diffstat (limited to 'test/Transforms/SCCP')
-rw-r--r--test/Transforms/SCCP/ipsccp-basic.ll135
-rw-r--r--test/Transforms/SCCP/sccptest.ll65
2 files changed, 175 insertions, 25 deletions
diff --git a/test/Transforms/SCCP/ipsccp-basic.ll b/test/Transforms/SCCP/ipsccp-basic.ll
index 7f0772e53d93..d3584d1b3ce7 100644
--- a/test/Transforms/SCCP/ipsccp-basic.ll
+++ b/test/Transforms/SCCP/ipsccp-basic.ll
@@ -1,13 +1,136 @@
-; RUN: opt < %s -ipsccp -S | \
-; RUN: grep -v {ret i32 17} | grep -v {ret i32 undef} | not grep ret
+; RUN: opt < %s -ipsccp -S | FileCheck %s
-define internal i32 @bar(i32 %A) {
- %X = add i32 1, 2 ; <i32> [#uses=0]
+;;======================== test1
+
+define internal i32 @test1a(i32 %A) {
+ %X = add i32 1, 2
ret i32 %A
}
+; CHECK: define internal i32 @test1a
+; CHECK: ret i32 undef
-define i32 @foo() {
- %X = call i32 @bar( i32 17 ) ; <i32> [#uses=1]
+define i32 @test1b() {
+ %X = call i32 @test1a( i32 17 )
ret i32 %X
+
+; CHECK: define i32 @test1b
+; CHECK: ret i32 17
+}
+
+
+
+;;======================== test2
+
+define internal i32 @test2a(i32 %A) {
+ %C = icmp eq i32 %A, 0
+ br i1 %C, label %T, label %F
+T:
+ %B = call i32 @test2a( i32 0 )
+ ret i32 0
+F:
+ %C.upgrd.1 = call i32 @test2a(i32 1)
+ ret i32 %C.upgrd.1
+}
+; CHECK: define internal i32 @test2a
+; CHECK-NEXT: br label %T
+; CHECK: ret i32 undef
+
+
+define i32 @test2b() {
+ %X = call i32 @test2a(i32 0)
+ ret i32 %X
+}
+; CHECK: define i32 @test2b
+; CHECK-NEXT: %X = call i32 @test2a(i32 0)
+; CHECK-NEXT: ret i32 0
+
+
+;;======================== test3
+
+@G = internal global i32 undef
+
+define void @test3a() {
+ %X = load i32* @G
+ store i32 %X, i32* @G
+ ret void
+}
+; CHECK: define void @test3a
+; CHECK-NEXT: ret void
+
+
+define i32 @test3b() {
+ %V = load i32* @G
+ %C = icmp eq i32 %V, 17
+ br i1 %C, label %T, label %F
+T:
+ store i32 17, i32* @G
+ ret i32 %V
+F:
+ store i32 123, i32* @G
+ ret i32 0
+}
+; CHECK: define i32 @test3b
+; CHECK-NOT: store
+; CHECK: ret i32 0
+
+
+;;======================== test4
+
+define internal {i64,i64} @test4a() {
+ %a = insertvalue {i64,i64} undef, i64 4, 1
+ %b = insertvalue {i64,i64} %a, i64 5, 0
+ ret {i64,i64} %b
+}
+
+define i64 @test4b() {
+ %a = invoke {i64,i64} @test4a()
+ to label %A unwind label %B
+A:
+ %b = extractvalue {i64,i64} %a, 0
+ %c = call i64 @test4c(i64 %b)
+ ret i64 %c
+B:
+ ret i64 0
+}
+; CHECK: define i64 @test4b()
+; CHECK: %c = call i64 @test4c(i64 5)
+; CHECK-NEXT: ret i64 5
+
+
+define internal i64 @test4c(i64 %a) {
+ ret i64 %a
+}
+; CHECK: define internal i64 @test4c
+; CHECK: ret i64 undef
+
+
+
+;;======================== test5
+
+; PR4313
+define internal {i64,i64} @test5a() {
+ %a = insertvalue {i64,i64} undef, i64 4, 1
+ %b = insertvalue {i64,i64} %a, i64 5, 0
+ ret {i64,i64} %b
+}
+
+define i64 @test5b() {
+ %a = invoke {i64,i64} @test5a()
+ to label %A unwind label %B
+A:
+ %c = call i64 @test5c({i64,i64} %a)
+ ret i64 %c
+B:
+ ret i64 0
+}
+
+; CHECK: define i64 @test5b()
+; CHECK: A:
+; CHECK-NEXT: %c = call i64 @test5c(%0 %a)
+; CHECK-NEXT: ret i64 %c
+
+define internal i64 @test5c({i64,i64} %a) {
+ %b = extractvalue {i64,i64} %a, 0
+ ret i64 %b
}
diff --git a/test/Transforms/SCCP/sccptest.ll b/test/Transforms/SCCP/sccptest.ll
index 6f422f07d661..a719f6cfb48d 100644
--- a/test/Transforms/SCCP/sccptest.ll
+++ b/test/Transforms/SCCP/sccptest.ll
@@ -1,31 +1,58 @@
+; RUN: opt < %s -sccp -S | FileCheck %s
+
+; This is a basic sanity check for constant propagation. The add instruction
+; should be eliminated.
+
+define i32 @test1(i1 %B) {
+ br i1 %B, label %BB1, label %BB2
+BB1: ; preds = %0
+ %Val = add i32 0, 0 ; <i32> [#uses=1]
+ br label %BB3
+BB2: ; preds = %0
+ br label %BB3
+BB3: ; preds = %BB2, %BB1
+ %Ret = phi i32 [ %Val, %BB1 ], [ 1, %BB2 ] ; <i32> [#uses=1]
+ ret i32 %Ret
+
+; CHECK: @test1
+; CHECK: %Ret = phi i32 [ 0, %BB1 ], [ 1, %BB2 ]
+}
+
; This is the test case taken from appel's book that illustrates a hard case
-; that SCCP gets right. BB3 should be completely eliminated.
+; that SCCP gets right.
;
-; RUN: opt < %s -sccp -constprop -dce -simplifycfg | \
-; RUN: llvm-dis | not grep BB3
-
-define i32 @testfunction(i32 %i0, i32 %j0) {
+define i32 @test2(i32 %i0, i32 %j0) {
+; CHECK: @test2
BB1:
br label %BB2
-BB2: ; preds = %BB7, %BB1
- %j2 = phi i32 [ %j4, %BB7 ], [ 1, %BB1 ] ; <i32> [#uses=2]
- %k2 = phi i32 [ %k4, %BB7 ], [ 0, %BB1 ] ; <i32> [#uses=4]
- %kcond = icmp slt i32 %k2, 100 ; <i1> [#uses=1]
+BB2:
+ %j2 = phi i32 [ %j4, %BB7 ], [ 1, %BB1 ]
+ %k2 = phi i32 [ %k4, %BB7 ], [ 0, %BB1 ]
+ %kcond = icmp slt i32 %k2, 100
br i1 %kcond, label %BB3, label %BB4
-BB3: ; preds = %BB2
- %jcond = icmp slt i32 %j2, 20 ; <i1> [#uses=1]
+BB3:
+ %jcond = icmp slt i32 %j2, 20
br i1 %jcond, label %BB5, label %BB6
-BB4: ; preds = %BB2
+; CHECK: BB3:
+; CHECK-NEXT: br i1 true, label %BB5, label %BB6
+BB4:
ret i32 %j2
-BB5: ; preds = %BB3
- %k3 = add i32 %k2, 1 ; <i32> [#uses=1]
+; CHECK: BB4:
+; CHECK-NEXT: ret i32 1
+BB5:
+ %k3 = add i32 %k2, 1
br label %BB7
-BB6: ; preds = %BB3
- %k5 = add i32 %k2, 1 ; <i32> [#uses=1]
+BB6:
+ %k5 = add i32 %k2, 1
br label %BB7
-BB7: ; preds = %BB6, %BB5
- %j4 = phi i32 [ 1, %BB5 ], [ %k2, %BB6 ] ; <i32> [#uses=1]
- %k4 = phi i32 [ %k3, %BB5 ], [ %k5, %BB6 ] ; <i32> [#uses=1]
+; CHECK: BB6:
+; CHECK-NEXT: br label %BB7
+BB7:
+ %j4 = phi i32 [ 1, %BB5 ], [ %k2, %BB6 ]
+ %k4 = phi i32 [ %k3, %BB5 ], [ %k5, %BB6 ]
br label %BB2
+; CHECK: BB7:
+; CHECK-NEXT: %k4 = phi i32 [ %k3, %BB5 ], [ undef, %BB6 ]
+; CHECK-NEXT: br label %BB2
}