ipsccp-basic.ll
5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
; RUN: opt < %s -ipsccp -S | FileCheck %s
; RUN: opt < %s -enable-debugify -ipsccp -debugify-quiet -disable-output
;;======================== test1
define internal i32 @test1a(i32 %A) {
%X = add i32 1, 2
ret i32 %A
}
; CHECK-LABEL: define internal i32 @test1a(
; CHECK: ret i32 undef
define i32 @test1b() {
%X = call i32 @test1a( i32 17 )
ret i32 %X
; CHECK-LABEL: 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-LABEL: 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-LABEL: 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, i32* @G
store i32 %X, i32* @G
ret void
}
; CHECK-LABEL: define void @test3a(
; CHECK-NEXT: ret void
define i32 @test3b() {
%V = load i32, 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-LABEL: 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
}
; CHECK-LABEL: define internal { i64, i64 } @test4a(
; CHECK-NEXT: ret { i64, i64 } undef
; CHECK-NEXT: }
define i64 @test4b() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
%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:
%val = landingpad { i8*, i32 }
catch i8* null
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-LABEL: 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() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
%a = invoke {i64,i64} @test5a()
to label %A unwind label %B
A:
%c = call i64 @test5c({i64,i64} %a)
ret i64 %c
B:
%val = landingpad { i8*, i32 }
catch i8* null
ret i64 0
}
; CHECK: define i64 @test5b()
; CHECK: A:
; CHECK-NEXT: %c = call i64 @test5c({ i64, i64 } { i64 5, i64 4 })
; CHECK-NEXT: ret i64 5
define internal i64 @test5c({i64,i64} %a) {
%b = extractvalue {i64,i64} %a, 0
ret i64 %b
}
;;======================== test6
define i64 @test6a() {
ret i64 0
}
define i64 @test6b() {
%a = call i64 @test6a()
ret i64 %a
}
; CHECK-LABEL: define i64 @test6b(
; CHECK: ret i64 0
;;======================== test7
%T = type {i32,i32}
define internal %T @test7a(i32 %A) {
%X = add i32 1, %A
%mrv0 = insertvalue %T undef, i32 %X, 0
%mrv1 = insertvalue %T %mrv0, i32 %A, 1
ret %T %mrv1
; CHECK-LABEL: @test7a(
; CHECK-NEXT: ret %T undef
}
define i32 @test7b() {
%X = call %T @test7a(i32 17)
%Y = extractvalue %T %X, 0
%Z = add i32 %Y, %Y
ret i32 %Z
; CHECK-LABEL: define i32 @test7b(
; CHECK-NEXT: call %T @test7a(i32 17)
; CHECK-NEXT: ret i32 36
}
;;======================== test8
define internal {} @test8a(i32 %A, i32* %P) {
store i32 %A, i32* %P
ret {} {}
; CHECK-LABEL: @test8a(
; CHECK-NEXT: store i32 5,
; CHECK-NEXT: ret
}
define void @test8b(i32* %P) {
%X = call {} @test8a(i32 5, i32* %P)
ret void
; CHECK-LABEL: define void @test8b(
; CHECK-NEXT: call {} @test8a
; CHECK-NEXT: ret void
}
;;======================== test9
@test9g = internal global { } zeroinitializer
define void @test9() {
entry:
%local_foo = alloca { }
load { }, { }* @test9g
store { } %0, { }* %local_foo
ret void
}
; CHECK-LABEL: define void @test9(
; CHECK-NEXT: entry:
; CHECK-NEXT: %local_foo = alloca {}
; CHECK-NEXT: store {} zeroinitializer, {}* %local_foo
; CHECK-NEXT: ret void
declare i32 @__gxx_personality_v0(...)
;;======================== test10
define i32 @test10a() nounwind {
entry:
%call = call i32 @test10b(i32 undef)
ret i32 %call
; CHECK-LABEL: define i32 @test10a(
; CHECK: ret i32 0
}
define internal i32 @test10b(i32 %x) nounwind {
entry:
%r = and i32 %x, 1
ret i32 %r
; CHECK-LABEL: define internal i32 @test10b(
; CHECK: ret i32 undef
}
;;======================== test11
define i64 @test11a() {
%xor = xor i64 undef, undef
ret i64 %xor
; CHECK-LABEL: define i64 @test11a
; CHECK: ret i64 0
}
define i64 @test11b() {
%call1 = call i64 @test11a()
%call2 = call i64 @llvm.ctpop.i64(i64 %call1)
ret i64 %call2
; CHECK-LABEL: define i64 @test11b
; CHECK: %[[call1:.*]] = call i64 @test11a()
; CHECK-NOT: call i64 @llvm.ctpop.i64
; CHECK-NEXT: ret i64 0
}
declare i64 @llvm.ctpop.i64(i64)
;;======================== test12
;; Ensure that a struct as an arg to a potentially constant-foldable
;; function does not crash SCCP (for now it'll just ignores it)
define i1 @test12() {
%c = call i1 @llvm.is.constant.sl_i32i32s({i32, i32} {i32 -1, i32 32})
ret i1 %c
; CHECK-LABEL: define i1 @test12
; CHECK: ret i1 %c
}
declare i1 @llvm.is.constant.sl_i32i32s({i32, i32} %a)