1 ; RUN: opt < %s -passes=gvn -S | FileCheck %s
3 %struct.anon = type { ptr, i32, i32, [3 x i32], ptr, ptr, ptr }
4 @debug = external constant i32 ; <ptr> [#uses=0]
5 @counters = external constant i32 ; <ptr> [#uses=1]
6 @trialx = external global [17 x i32] ; <ptr> [#uses=1]
7 @dummy1 = external global [7 x i32] ; <ptr> [#uses=0]
8 @dummy2 = external global [4 x i32] ; <ptr> [#uses=0]
9 @unacceptable = external global i32 ; <ptr> [#uses=0]
10 @isa = external global [13 x %struct.anon] ; <ptr> [#uses=3]
11 @.str = external constant [4 x i8] ; <ptr> [#uses=0]
12 @.str1 = external constant [3 x i8] ; <ptr> [#uses=0]
13 @.str2 = external constant [1 x i8] ; <ptr> [#uses=0]
14 @.str3 = external constant [4 x i8] ; <ptr> [#uses=0]
15 @.str4 = external constant [3 x i8] ; <ptr> [#uses=0]
16 @.str5 = external constant [4 x i8] ; <ptr> [#uses=0]
17 @.str6 = external constant [2 x i8] ; <ptr> [#uses=0]
18 @.str7 = external constant [4 x i8] ; <ptr> [#uses=0]
19 @.str8 = external constant [4 x i8] ; <ptr> [#uses=0]
20 @.str9 = external constant [4 x i8] ; <ptr> [#uses=0]
21 @.str10 = external constant [4 x i8] ; <ptr> [#uses=0]
22 @.str11 = external constant [2 x i8] ; <ptr> [#uses=0]
23 @.str12 = external constant [4 x i8] ; <ptr> [#uses=0]
24 @.str13 = external constant [2 x i8] ; <ptr> [#uses=0]
25 @.str14 = external constant [5 x i8] ; <ptr> [#uses=0]
26 @.str15 = external constant [5 x i8] ; <ptr> [#uses=0]
27 @.str16 = external constant [4 x i8] ; <ptr> [#uses=0]
28 @.str17 = external constant [4 x i8] ; <ptr> [#uses=0]
29 @.str18 = external constant [3 x i8] ; <ptr> [#uses=0]
30 @.str19 = external constant [4 x i8] ; <ptr> [#uses=0]
31 @.str20 = external constant [4 x i8] ; <ptr> [#uses=0]
32 @.str21 = external constant [4 x i8] ; <ptr> [#uses=0]
33 @.str22 = external constant [4 x i8] ; <ptr> [#uses=0]
34 @.str23 = external constant [5 x i8] ; <ptr> [#uses=0]
35 @.str24 = external constant [4 x i8] ; <ptr> [#uses=0]
36 @.str25 = external constant [6 x i8] ; <ptr> [#uses=0]
37 @.str26 = external constant [5 x i8] ; <ptr> [#uses=0]
38 @.str27 = external constant [6 x i8] ; <ptr> [#uses=0]
39 @r = external global [17 x i32] ; <ptr> [#uses=0]
40 @.str28 = external constant [3 x i8] ; <ptr> [#uses=0]
41 @.str29 = external constant [5 x i8] ; <ptr> [#uses=0]
42 @pgm = external global [5 x { i32, [3 x i32] }] ; <ptr> [#uses=4]
43 @.str30 = external constant [3 x i8] ; <ptr> [#uses=0]
44 @.str31 = external constant [13 x i8] ; <ptr> [#uses=0]
45 @.str32 = external constant [3 x i8] ; <ptr> [#uses=0]
46 @.str33 = external constant [4 x i8] ; <ptr> [#uses=0]
47 @.str34 = external constant [20 x i8] ; <ptr> [#uses=0]
48 @numi = external global i32 ; <ptr> [#uses=7]
49 @.str35 = external constant [10 x i8] ; <ptr> [#uses=0]
50 @counter = external global [5 x i32] ; <ptr> [#uses=2]
51 @itrialx.2510 = external global i32 ; <ptr> [#uses=0]
52 @.str36 = external constant [43 x i8] ; <ptr> [#uses=0]
53 @.str37 = external constant [42 x i8] ; <ptr> [#uses=0]
54 @corr_result = external global i32 ; <ptr> [#uses=0]
55 @.str38 = external constant [3 x i8] ; <ptr> [#uses=0]
56 @.str39 = external constant [5 x i8] ; <ptr> [#uses=0]
57 @.str40 = external constant [47 x i8] ; <ptr> [#uses=0]
58 @correct_result = external global [17 x i32] ; <ptr> [#uses=1]
59 @.str41 = external constant [46 x i8] ; <ptr> [#uses=0]
60 @.str42 = external constant [32 x i8] ; <ptr> [#uses=0]
61 @.str43 = external constant [44 x i8] ; <ptr> [#uses=1]
62 @.str44 = external constant [21 x i8] ; <ptr> [#uses=1]
63 @.str45 = external constant [12 x i8] ; <ptr> [#uses=1]
64 @.str46 = external constant [5 x i8] ; <ptr> [#uses=1]
65 @.str47 = external constant [12 x i8] ; <ptr> [#uses=1]
67 declare i32 @neg(i32, i32, i32)
69 declare i32 @Not(i32, i32, i32)
71 declare i32 @pop(i32, i32, i32)
73 declare i32 @nlz(i32, i32, i32)
75 declare i32 @rev(i32, i32, i32)
77 declare i32 @add(i32, i32, i32)
79 declare i32 @sub(i32, i32, i32)
81 declare i32 @mul(i32, i32, i32)
83 declare i32 @divide(i32, i32, i32)
85 declare i32 @divu(i32, i32, i32)
87 declare i32 @And(i32, i32, i32)
89 declare i32 @Or(i32, i32, i32)
91 declare i32 @Xor(i32, i32, i32)
93 declare i32 @rotl(i32, i32, i32)
95 declare i32 @shl(i32, i32, i32)
97 declare i32 @shr(i32, i32, i32)
99 declare i32 @shrs(i32, i32, i32)
101 declare i32 @cmpeq(i32, i32, i32)
103 declare i32 @cmplt(i32, i32, i32)
105 declare i32 @cmpltu(i32, i32, i32)
107 declare i32 @seleq(i32, i32, i32)
109 declare i32 @sellt(i32, i32, i32)
111 declare i32 @selle(i32, i32, i32)
113 declare void @print_expr(i32)
115 declare i32 @printf(ptr, ...)
117 declare i32 @putchar(i32)
119 declare void @print_pgm()
121 declare void @simulate_one_instruction(i32)
123 declare i32 @check(i32)
125 declare i32 @puts(ptr)
127 declare void @fix_operands(i32)
129 declare void @abort()
131 declare i32 @increment()
133 declare i32 @search()
135 define i32 @main(i32 %argc, ptr %argv) {
137 %argc_addr = alloca i32 ; <ptr> [#uses=1]
138 %argv_addr = alloca ptr ; <ptr> [#uses=1]
139 %retval = alloca i32, align 4 ; <ptr> [#uses=2]
140 %tmp = alloca i32, align 4 ; <ptr> [#uses=2]
141 %i = alloca i32, align 4 ; <ptr> [#uses=21]
142 %num_sol = alloca i32, align 4 ; <ptr> [#uses=4]
143 %total = alloca i32, align 4 ; <ptr> [#uses=4]
144 %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
145 store i32 %argc, ptr %argc_addr
146 store ptr %argv, ptr %argv_addr
147 store i32 0, ptr %num_sol
148 store i32 1, ptr @numi
151 bb: ; preds = %cond_next97
152 %tmp1 = load i32, ptr @numi ; <i32> [#uses=1]
153 %tmp2 = getelementptr [44 x i8], ptr @.str43, i32 0, i32 0 ; <ptr> [#uses=1]
154 %tmp3 = call i32 (ptr, ...) @printf( ptr %tmp2, i32 %tmp1 ) ; <i32> [#uses=0]
159 %tmp5 = load i32, ptr %i ; <i32> [#uses=1]
160 %tmp6 = load i32, ptr %i ; <i32> [#uses=1]
161 %tmp7 = getelementptr [17 x i32], ptr @trialx, i32 0, i32 %tmp6 ; <ptr> [#uses=1]
162 %tmp8 = load i32, ptr %tmp7 ; <i32> [#uses=1]
163 %tmp9 = call i32 @userfun( i32 %tmp8 ) ; <i32> [#uses=1]
164 %tmp10 = getelementptr [17 x i32], ptr @correct_result, i32 0, i32 %tmp5 ; <ptr> [#uses=1]
165 store i32 %tmp9, ptr %tmp10
166 %tmp11 = load i32, ptr %i ; <i32> [#uses=1]
167 %tmp12 = add i32 %tmp11, 1 ; <i32> [#uses=1]
168 store i32 %tmp12, ptr %i
171 bb13: ; preds = %bb4, %bb
172 %tmp14 = load i32, ptr %i ; <i32> [#uses=1]
173 %tmp15 = icmp sle i32 %tmp14, 16 ; <i1> [#uses=1]
174 %tmp1516 = zext i1 %tmp15 to i32 ; <i32> [#uses=1]
175 %toBool = icmp ne i32 %tmp1516, 0 ; <i1> [#uses=1]
176 br i1 %toBool, label %bb4, label %bb17
178 bb17: ; preds = %bb13
182 bb18: ; preds = %bb49
183 %tmp19 = load i32, ptr %i ; <i32> [#uses=1]
184 %tmp20 = getelementptr [5 x { i32, [3 x i32] }], ptr @pgm, i32 0, i32 %tmp19 ; <ptr> [#uses=1]
185 %tmp21 = getelementptr { i32, [3 x i32] }, ptr %tmp20, i32 0, i32 0 ; <ptr> [#uses=1]
186 store i32 0, ptr %tmp21
187 %tmp22 = load i32, ptr %i ; <i32> [#uses=1]
188 %tmp23 = getelementptr [13 x %struct.anon], ptr @isa, i32 0, i32 0 ; <ptr> [#uses=1]
189 %tmp24 = getelementptr %struct.anon, ptr %tmp23, i32 0, i32 3 ; <ptr> [#uses=1]
190 %tmp25 = getelementptr [3 x i32], ptr %tmp24, i32 0, i32 0 ; <ptr> [#uses=1]
191 %tmp26 = load i32, ptr %tmp25 ; <i32> [#uses=1]
192 %tmp27 = getelementptr [5 x { i32, [3 x i32] }], ptr @pgm, i32 0, i32 %tmp22 ; <ptr> [#uses=1]
193 %tmp28 = getelementptr { i32, [3 x i32] }, ptr %tmp27, i32 0, i32 1 ; <ptr> [#uses=1]
194 %tmp29 = getelementptr [3 x i32], ptr %tmp28, i32 0, i32 0 ; <ptr> [#uses=1]
195 store i32 %tmp26, ptr %tmp29
196 %tmp30 = load i32, ptr %i ; <i32> [#uses=1]
197 %tmp31 = getelementptr [13 x %struct.anon], ptr @isa, i32 0, i32 0 ; <ptr> [#uses=1]
198 %tmp32 = getelementptr %struct.anon, ptr %tmp31, i32 0, i32 3 ; <ptr> [#uses=1]
199 %tmp33 = getelementptr [3 x i32], ptr %tmp32, i32 0, i32 1 ; <ptr> [#uses=1]
200 %tmp34 = load i32, ptr %tmp33 ; <i32> [#uses=1]
201 %tmp35 = getelementptr [5 x { i32, [3 x i32] }], ptr @pgm, i32 0, i32 %tmp30 ; <ptr> [#uses=1]
202 %tmp36 = getelementptr { i32, [3 x i32] }, ptr %tmp35, i32 0, i32 1 ; <ptr> [#uses=1]
203 %tmp37 = getelementptr [3 x i32], ptr %tmp36, i32 0, i32 1 ; <ptr> [#uses=1]
204 store i32 %tmp34, ptr %tmp37
205 %tmp38 = load i32, ptr %i ; <i32> [#uses=1]
206 %tmp39 = getelementptr [13 x %struct.anon], ptr @isa, i32 0, i32 0 ; <ptr> [#uses=1]
207 %tmp40 = getelementptr %struct.anon, ptr %tmp39, i32 0, i32 3 ; <ptr> [#uses=1]
208 %tmp41 = getelementptr [3 x i32], ptr %tmp40, i32 0, i32 2 ; <ptr> [#uses=1]
209 %tmp42 = load i32, ptr %tmp41 ; <i32> [#uses=1]
210 %tmp43 = getelementptr [5 x { i32, [3 x i32] }], ptr @pgm, i32 0, i32 %tmp38 ; <ptr> [#uses=1]
211 %tmp44 = getelementptr { i32, [3 x i32] }, ptr %tmp43, i32 0, i32 1 ; <ptr> [#uses=1]
212 %tmp45 = getelementptr [3 x i32], ptr %tmp44, i32 0, i32 2 ; <ptr> [#uses=1]
213 store i32 %tmp42, ptr %tmp45
214 %tmp46 = load i32, ptr %i ; <i32> [#uses=1]
215 call void @fix_operands( i32 %tmp46 )
216 %tmp47 = load i32, ptr %i ; <i32> [#uses=1]
217 ; CHECK: %tmp47 = phi i32 [ %tmp48, %bb18 ], [ 0, %bb17 ]
218 %tmp48 = add i32 %tmp47, 1 ; <i32> [#uses=1]
219 store i32 %tmp48, ptr %i
222 bb49: ; preds = %bb18, %bb17
223 %tmp50 = load i32, ptr @numi ; <i32> [#uses=1]
224 %tmp51 = load i32, ptr %i ; <i32> [#uses=1]
225 %tmp52 = icmp slt i32 %tmp51, %tmp50 ; <i1> [#uses=1]
226 %tmp5253 = zext i1 %tmp52 to i32 ; <i32> [#uses=1]
227 %toBool54 = icmp ne i32 %tmp5253, 0 ; <i1> [#uses=1]
228 br i1 %toBool54, label %bb18, label %bb55
230 bb55: ; preds = %bb49
231 %tmp56 = call i32 @search( ) ; <i32> [#uses=1]
232 store i32 %tmp56, ptr %num_sol
233 %tmp57 = getelementptr [21 x i8], ptr @.str44, i32 0, i32 0 ; <ptr> [#uses=1]
234 %tmp58 = load i32, ptr %num_sol ; <i32> [#uses=1]
235 %tmp59 = call i32 (ptr, ...) @printf( ptr %tmp57, i32 %tmp58 ) ; <i32> [#uses=0]
236 %tmp60 = load i32, ptr @counters ; <i32> [#uses=1]
237 %tmp61 = icmp ne i32 %tmp60, 0 ; <i1> [#uses=1]
238 %tmp6162 = zext i1 %tmp61 to i32 ; <i32> [#uses=1]
239 %toBool63 = icmp ne i32 %tmp6162, 0 ; <i1> [#uses=1]
240 br i1 %toBool63, label %cond_true, label %cond_next
242 cond_true: ; preds = %bb55
243 store i32 0, ptr %total
244 %tmp64 = getelementptr [12 x i8], ptr @.str45, i32 0, i32 0 ; <ptr> [#uses=1]
245 %tmp65 = call i32 (ptr, ...) @printf( ptr %tmp64 ) ; <i32> [#uses=0]
249 bb66: ; preds = %bb79
250 %tmp67 = load i32, ptr %i ; <i32> [#uses=1]
251 %tmp68 = getelementptr [5 x i32], ptr @counter, i32 0, i32 %tmp67 ; <ptr> [#uses=1]
252 %tmp69 = load i32, ptr %tmp68 ; <i32> [#uses=1]
253 %tmp70 = getelementptr [5 x i8], ptr @.str46, i32 0, i32 0 ; <ptr> [#uses=1]
254 %tmp71 = call i32 (ptr, ...) @printf( ptr %tmp70, i32 %tmp69 ) ; <i32> [#uses=0]
255 %tmp72 = load i32, ptr %i ; <i32> [#uses=1]
256 %tmp73 = getelementptr [5 x i32], ptr @counter, i32 0, i32 %tmp72 ; <ptr> [#uses=1]
257 %tmp74 = load i32, ptr %tmp73 ; <i32> [#uses=1]
258 %tmp75 = load i32, ptr %total ; <i32> [#uses=1]
259 %tmp76 = add i32 %tmp74, %tmp75 ; <i32> [#uses=1]
260 store i32 %tmp76, ptr %total
261 %tmp77 = load i32, ptr %i ; <i32> [#uses=1]
262 %tmp78 = add i32 %tmp77, 1 ; <i32> [#uses=1]
263 store i32 %tmp78, ptr %i
266 bb79: ; preds = %bb66, %cond_true
267 %tmp80 = load i32, ptr @numi ; <i32> [#uses=1]
268 %tmp81 = load i32, ptr %i ; <i32> [#uses=1]
269 %tmp82 = icmp slt i32 %tmp81, %tmp80 ; <i1> [#uses=1]
270 %tmp8283 = zext i1 %tmp82 to i32 ; <i32> [#uses=1]
271 %toBool84 = icmp ne i32 %tmp8283, 0 ; <i1> [#uses=1]
272 br i1 %toBool84, label %bb66, label %bb85
274 bb85: ; preds = %bb79
275 %tmp86 = getelementptr [12 x i8], ptr @.str47, i32 0, i32 0 ; <ptr> [#uses=1]
276 %tmp87 = load i32, ptr %total ; <i32> [#uses=1]
277 %tmp88 = call i32 (ptr, ...) @printf( ptr %tmp86, i32 %tmp87 ) ; <i32> [#uses=0]
280 cond_next: ; preds = %bb85, %bb55
281 %tmp89 = load i32, ptr @numi ; <i32> [#uses=1]
282 %tmp90 = add i32 %tmp89, 1 ; <i32> [#uses=1]
283 store i32 %tmp90, ptr @numi
286 bb91: ; preds = %cond_next, %entry
287 %tmp92 = load i32, ptr @numi ; <i32> [#uses=1]
288 %tmp93 = icmp sgt i32 %tmp92, 5 ; <i1> [#uses=1]
289 %tmp9394 = zext i1 %tmp93 to i32 ; <i32> [#uses=1]
290 %toBool95 = icmp ne i32 %tmp9394, 0 ; <i1> [#uses=1]
291 br i1 %toBool95, label %cond_true96, label %cond_next97
293 cond_true96: ; preds = %bb91
296 cond_next97: ; preds = %bb91
297 %tmp98 = load i32, ptr %num_sol ; <i32> [#uses=1]
298 %tmp99 = icmp eq i32 %tmp98, 0 ; <i1> [#uses=1]
299 %tmp99100 = zext i1 %tmp99 to i32 ; <i32> [#uses=1]
300 %toBool101 = icmp ne i32 %tmp99100, 0 ; <i1> [#uses=1]
301 br i1 %toBool101, label %bb, label %bb102
303 bb102: ; preds = %cond_next97, %cond_true96
304 store i32 0, ptr %tmp
305 %tmp103 = load i32, ptr %tmp ; <i32> [#uses=1]
306 store i32 %tmp103, ptr %retval
309 return: ; preds = %bb102
310 %retval104 = load i32, ptr %retval ; <i32> [#uses=1]
314 declare i32 @userfun(i32)