1 ; RUN: opt < %s -ipsccp -S | FileCheck %s
2 ; RUN: opt < %s -enable-debugify -ipsccp -debugify-quiet -disable-output
4 ;;======================== test1
6 define internal i32 @test1a(i32 %A) {
10 ; CHECK-LABEL: define internal i32 @test1a(
11 ; CHECK: ret i32 undef
13 define i32 @test1b() {
14 %X = call i32 @test1a( i32 17 )
17 ; CHECK-LABEL: define i32 @test1b(
23 ;;======================== test2
25 define internal i32 @test2a(i32 %A) {
26 %C = icmp eq i32 %A, 0
27 br i1 %C, label %T, label %F
29 %B = call i32 @test2a( i32 0 )
32 %C.upgrd.1 = call i32 @test2a(i32 1)
35 ; CHECK-LABEL: define internal i32 @test2a(
36 ; CHECK-NEXT: br label %T
37 ; CHECK: ret i32 undef
40 define i32 @test2b() {
41 %X = call i32 @test2a(i32 0)
44 ; CHECK-LABEL: define i32 @test2b(
45 ; CHECK-NEXT: %X = call i32 @test2a(i32 0)
46 ; CHECK-NEXT: ret i32 0
49 ;;======================== test3
51 @G = internal global i32 undef
53 define void @test3a() {
54 %X = load i32, i32* @G
58 ; CHECK-LABEL: define void @test3a(
59 ; CHECK-NEXT: %X = load i32, i32* @G
60 ; CHECK-NEXT: store i32 %X, i32* @G
61 ; CHECK-NEXT: ret void
64 define i32 @test3b() {
65 %V = load i32, i32* @G
66 %C = icmp eq i32 %V, 17
67 br i1 %C, label %T, label %F
72 store i32 123, i32* @G
75 ; CHECK-LABEL: define i32 @test3b(
76 ; CHECK-NEXT: %V = load i32, i32* @G
77 ; CHECK-NEXT: %C = icmp eq i32 %V, 17
78 ; CHECK-NEXT: br i1 %C, label %T, label %F
81 ; CHECK-NEXT: store i32 17, i32* @G
82 ; CHECK-NEXT: ret i32 17
85 ; CHECK-NEXT: store i32 123, i32* @G
86 ; CHECK-NEXT: ret i32 0
88 ;;======================== test4
90 define internal {i64,i64} @test4a() {
91 %a = insertvalue {i64,i64} undef, i64 4, 1
92 %b = insertvalue {i64,i64} %a, i64 5, 0
96 ; CHECK-LABEL: define internal { i64, i64 } @test4a(
97 ; CHECK-NEXT: ret { i64, i64 } undef
100 define i64 @test4b() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
101 %a = invoke {i64,i64} @test4a()
102 to label %A unwind label %B
104 %b = extractvalue {i64,i64} %a, 0
105 %c = call i64 @test4c(i64 %b)
108 %val = landingpad { i8*, i32 }
112 ; CHECK: define i64 @test4b()
113 ; CHECK: %c = call i64 @test4c(i64 5)
114 ; CHECK-NEXT: ret i64 5
117 define internal i64 @test4c(i64 %a) {
120 ; CHECK-LABEL: define internal i64 @test4c(
121 ; CHECK: ret i64 undef
125 ;;======================== test5
128 define internal {i64,i64} @test5a() {
129 %a = insertvalue {i64,i64} undef, i64 4, 1
130 %b = insertvalue {i64,i64} %a, i64 5, 0
134 define i64 @test5b() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
135 %a = invoke {i64,i64} @test5a()
136 to label %A unwind label %B
138 %c = call i64 @test5c({i64,i64} %a)
141 %val = landingpad { i8*, i32 }
146 ; CHECK: define i64 @test5b()
148 ; CHECK-NEXT: %c = call i64 @test5c({ i64, i64 } { i64 5, i64 4 })
149 ; CHECK-NEXT: ret i64 5
151 define internal i64 @test5c({i64,i64} %a) {
152 %b = extractvalue {i64,i64} %a, 0
157 ;;======================== test6
159 define i64 @test6a() {
163 define i64 @test6b() {
164 %a = call i64 @test6a()
167 ; CHECK-LABEL: define i64 @test6b(
170 ;;======================== test7
175 define internal %T @test7a(i32 %A) {
177 %mrv0 = insertvalue %T undef, i32 %X, 0
178 %mrv1 = insertvalue %T %mrv0, i32 %A, 1
180 ; CHECK-LABEL: @test7a(
181 ; CHECK-NEXT: ret %T undef
184 define i32 @test7b() {
185 %X = call %T @test7a(i32 17)
186 %Y = extractvalue %T %X, 0
189 ; CHECK-LABEL: define i32 @test7b(
190 ; CHECK-NEXT: call %T @test7a(i32 17)
191 ; CHECK-NEXT: ret i32 36
194 ;;======================== test8
197 define internal {} @test8a(i32 %A, i32* %P) {
198 store i32 %A, i32* %P
200 ; CHECK-LABEL: @test8a(
201 ; CHECK-NEXT: store i32 5,
205 define void @test8b(i32* %P) {
206 %X = call {} @test8a(i32 5, i32* %P)
208 ; CHECK-LABEL: define void @test8b(
209 ; CHECK-NEXT: call {} @test8a
210 ; CHECK-NEXT: ret void
213 ;;======================== test9
215 @test9g = internal global { } zeroinitializer
217 define void @test9() {
219 %local_foo = alloca { }
220 load { }, { }* @test9g
221 store { } %0, { }* %local_foo
225 ; CHECK-LABEL: define void @test9(
227 ; CHECK-NEXT: %local_foo = alloca {}
228 ; CHECK-NEXT: store {} zeroinitializer, {}* %local_foo
229 ; CHECK-NEXT: ret void
231 declare i32 @__gxx_personality_v0(...)
233 ;;======================== test10
235 define i32 @test10a() nounwind {
237 %call = call i32 @test10b(i32 undef)
240 ; CHECK-LABEL: define i32 @test10a(
242 ; CHECK-NEXT: %call = call i32 @test10b(i32 undef)
243 ; CHECK-NEXT: ret i32 %call
246 define internal i32 @test10b(i32 %x) nounwind {
250 ; CHECK-LABEL: define internal i32 @test10b(
252 ; CHECK-NEXT: %r = and i32 undef, 1
253 ; CHECK-NEXT: ret i32 %r
256 ;;======================== test11
258 define i64 @test11a() {
259 %xor = xor i64 undef, undef
261 ; CHECK-LABEL: define i64 @test11a
262 ; CHECK-NEXT: %xor = xor i64 undef, undef
263 ; CHECK-NEXT: ret i64 %xor
266 define i64 @test11b() {
267 %call1 = call i64 @test11a()
268 %call2 = call i64 @llvm.ctpop.i64(i64 %call1)
270 ; CHECK-LABEL: define i64 @test11b
271 ; CHECK-NEXT: [[call1:%.*]] = call i64 @test11a()
272 ; CHECK-NEXT: [[call2:%.*]] = call i64 @llvm.ctpop.i64(i64 [[call1]])
273 ; CHECK-NEXT: ret i64 [[call2]]
276 declare i64 @llvm.ctpop.i64(i64)
278 ;;======================== test12
279 ;; Ensure that a struct as an arg to a potentially constant-foldable
280 ;; function does not crash SCCP (for now it'll just ignores it)
282 define i1 @test12() {
283 %c = call i1 @llvm.is.constant.sl_i32i32s({i32, i32} {i32 -1, i32 32})
285 ; CHECK-LABEL: define i1 @test12
289 declare i1 @llvm.is.constant.sl_i32i32s({i32, i32} %a)