[CodeGenPrepare][AddressingModeMatcher] Fix a think-o for the sext(zext) -> zext...
[oota-llvm.git] / test / CodeGen / X86 / codegen-prepare-addrmode-sext.ll
1 ; RUN: opt -S -codegenprepare %s -o - | FileCheck %s
2 ; RUN: opt -S -codegenprepare -addr-sink-using-gep=1 %s -o - | FileCheck -check-prefix=CHECK-GEP %s
3 ; This file tests the different cases what are involved when codegen prepare
4 ; tries to get sign extension out of the way of addressing mode.
5 ; This tests require an actual target as addressing mode decisions depends
6 ; on the target.
7
8 target datalayout = "e-i64:64-f80:128-s:64-n8:16:32:64-S128"
9 target triple = "x86_64-apple-macosx"
10
11
12 ; Check that we correctly promote both operands of the promotable add.
13 ; CHECK-LABEL: @twoArgsPromotion
14 ; CHECK: [[ARG1SEXT:%[a-zA-Z_0-9-]+]] = sext i32 %arg1 to i64
15 ; CHECK: [[ARG2SEXT:%[a-zA-Z_0-9-]+]] = sext i32 %arg2 to i64
16 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT]], [[ARG2SEXT]]
17 ; CHECK: inttoptr i64 [[PROMOTED]] to i8*
18 ; CHECK: ret
19 define i8 @twoArgsPromotion(i32 %arg1, i32 %arg2) {
20   %add = add nsw i32 %arg1, %arg2 
21   %sextadd = sext i32 %add to i64
22   %base = inttoptr i64 %sextadd to i8*
23   %res = load i8* %base
24   ret i8 %res
25 }
26
27 ; Check that we do not promote both operands of the promotable add when
28 ; the instruction will not be folded into the addressing mode.
29 ; Otherwise, we will increase the number of instruction executed.
30 ; (This is a heuristic of course, because the new sext could have been
31 ; merged with something else.)
32 ; CHECK-LABEL: @twoArgsNoPromotion
33 ; CHECK: add nsw i32 %arg1, %arg2
34 ; CHECK: ret
35 define i8 @twoArgsNoPromotion(i32 %arg1, i32 %arg2, i8* %base) {
36   %add = add nsw i32 %arg1, %arg2 
37   %sextadd = sext i32 %add to i64
38   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
39   %res = load i8* %arrayidx
40   ret i8 %res
41 }
42
43 ; Check that we do not promote when the related instruction does not have
44 ; the nsw flag.
45 ; CHECK-LABEL: @noPromotion
46 ; CHECK-NOT: add i64
47 ; CHECK: ret
48 define i8 @noPromotion(i32 %arg1, i32 %arg2, i8* %base) {
49   %add = add i32 %arg1, %arg2 
50   %sextadd = sext i32 %add to i64
51   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
52   %res = load i8* %arrayidx
53   ret i8 %res
54 }
55
56 ; Check that we correctly promote constant arguments.
57 ; CHECK-LABEL: @oneArgPromotion
58 ; CHECK: [[ARG1SEXT:%[a-zA-Z_0-9-]+]] = sext i32 %arg1 to i64
59 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT]], 1
60 ; CHECK: getelementptr inbounds i8* %base, i64 [[PROMOTED]]
61 ; CHECK: ret
62 define i8 @oneArgPromotion(i32 %arg1, i8* %base) {
63   %add = add nsw i32 %arg1, 1 
64   %sextadd = sext i32 %add to i64
65   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
66   %res = load i8* %arrayidx
67   ret i8 %res
68 }
69
70 ; Check that we are able to merge a sign extension with a zero extension.
71 ; CHECK-LABEL: @oneArgPromotionZExt
72 ; CHECK: [[ARG1ZEXT:%[a-zA-Z_0-9-]+]] = zext i8 %arg1 to i64
73 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1ZEXT]], 1
74 ; CHECK: getelementptr inbounds i8* %base, i64 [[PROMOTED]]
75 ; CHECK: ret
76 define i8 @oneArgPromotionZExt(i8 %arg1, i8* %base) {
77   %zext = zext i8 %arg1 to i32
78   %add = add nsw i32 %zext, 1 
79   %sextadd = sext i32 %add to i64
80   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
81   %res = load i8* %arrayidx
82   ret i8 %res
83 }
84
85 ; Check that we do not promote truncate when we cannot determine the
86 ; bits that are dropped.
87 ; CHECK-LABEL: @oneArgPromotionBlockTrunc1
88 ; CHECK: [[ARG1TRUNC:%[a-zA-Z_0-9-]+]] = trunc i32 %arg1 to i8
89 ; CHECK: [[ARG1SEXT:%[a-zA-Z_0-9-]+]] = sext i8 [[ARG1TRUNC]] to i64
90 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT]], 1
91 ; CHECK: getelementptr inbounds i8* %base, i64 [[PROMOTED]]
92 ; CHECK: ret
93 define i8 @oneArgPromotionBlockTrunc1(i32 %arg1, i8* %base) {
94   %trunc = trunc i32 %arg1 to i8
95   %add = add nsw i8 %trunc, 1 
96   %sextadd = sext i8 %add to i64
97   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
98   %res = load i8* %arrayidx
99   ret i8 %res
100 }
101
102 ; Check that we do not promote truncate when we cannot determine all the
103 ; bits that are dropped.
104 ; CHECK-LABEL: @oneArgPromotionBlockTrunc2
105 ; CHECK: [[ARG1SEXT:%[a-zA-Z_0-9-]+]] = sext i16 %arg1 to i32
106 ; CHECK: [[ARG1TRUNC:%[a-zA-Z_0-9-]+]] = trunc i32 [[ARG1SEXT]] to i8
107 ; CHECK: [[ARG1SEXT64:%[a-zA-Z_0-9-]+]] = sext i8 [[ARG1TRUNC]] to i64
108 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT64]], 1
109 ; CHECK: getelementptr inbounds i8* %base, i64 [[PROMOTED]]
110 ; CHECK: ret
111 define i8 @oneArgPromotionBlockTrunc2(i16 %arg1, i8* %base) {
112   %sextarg1 = sext i16 %arg1 to i32
113   %trunc = trunc i32 %sextarg1 to i8
114   %add = add nsw i8 %trunc, 1 
115   %sextadd = sext i8 %add to i64
116   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
117   %res = load i8* %arrayidx
118   ret i8 %res
119 }
120
121 ; Check that we are able to promote truncate when we know all the bits
122 ; that are dropped.
123 ; CHECK-LABEL: @oneArgPromotionPassTruncKeepSExt
124 ; CHECK: [[ARG1SEXT:%[a-zA-Z_0-9-]+]] = sext i1 %arg1 to i64
125 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT]], 1
126 ; CHECK: getelementptr inbounds i8* %base, i64 [[PROMOTED]]
127 ; CHECK: ret
128 define i8 @oneArgPromotionPassTruncKeepSExt(i1 %arg1, i8* %base) {
129   %sextarg1 = sext i1 %arg1 to i32
130   %trunc = trunc i32 %sextarg1 to i8
131   %add = add nsw i8 %trunc, 1 
132   %sextadd = sext i8 %add to i64
133   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
134   %res = load i8* %arrayidx
135   ret i8 %res
136 }
137
138 ; On X86 truncate are free. Check that we are able to promote the add
139 ; to be used as addressing mode and that we insert a truncate for the other
140 ; use. 
141 ; CHECK-LABEL: @oneArgPromotionTruncInsert
142 ; CHECK: [[ARG1SEXT:%[a-zA-Z_0-9-]+]] = sext i8 %arg1 to i64
143 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT]], 1
144 ; CHECK: [[TRUNC:%[a-zA-Z_0-9-]+]] = trunc i64 [[PROMOTED]] to i8
145 ; CHECK: [[GEP:%[a-zA-Z_0-9-]+]] = getelementptr inbounds i8* %base, i64 [[PROMOTED]]
146 ; CHECK: [[LOAD:%[a-zA-Z_0-9-]+]] = load i8* [[GEP]]
147 ; CHECK: add i8 [[LOAD]], [[TRUNC]]
148 ; CHECK: ret
149 define i8 @oneArgPromotionTruncInsert(i8 %arg1, i8* %base) {
150   %add = add nsw i8 %arg1, 1 
151   %sextadd = sext i8 %add to i64
152   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
153   %res = load i8* %arrayidx
154   %finalres = add i8 %res, %add
155   ret i8 %finalres
156 }
157
158 ; Cannot sext from a larger type than the promoted type.
159 ; CHECK-LABEL: @oneArgPromotionLargerType
160 ; CHECK: [[ARG1TRUNC:%[a-zA-Z_0-9-]+]] = trunc i128 %arg1 to i8
161 ; CHECK: [[ARG1SEXT64:%[a-zA-Z_0-9-]+]] = sext i8 [[ARG1TRUNC]] to i64
162 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT64]], 1
163 ; CHECK: getelementptr inbounds i8* %base, i64 [[PROMOTED]]
164 ; CHECK: ret
165 define i8 @oneArgPromotionLargerType(i128 %arg1, i8* %base) {
166   %trunc = trunc i128 %arg1 to i8
167   %add = add nsw i8 %trunc, 1 
168   %sextadd = sext i8 %add to i64
169   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
170   %res = load i8* %arrayidx
171   %finalres = add i8 %res, %add
172   ret i8 %finalres
173 }
174
175 ; Use same inserted trunc
176 ; On X86 truncate are free. Check that we are able to promote the add
177 ; to be used as addressing mode and that we insert a truncate for
178 ; *all* the other uses. 
179 ; CHECK-LABEL: @oneArgPromotionTruncInsertSeveralUse
180 ; CHECK: [[ARG1SEXT:%[a-zA-Z_0-9-]+]] = sext i8 %arg1 to i64
181 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT]], 1
182 ; CHECK: [[TRUNC:%[a-zA-Z_0-9-]+]] = trunc i64 [[PROMOTED]] to i8
183 ; CHECK: [[GEP:%[a-zA-Z_0-9-]+]] = getelementptr inbounds i8* %base, i64 [[PROMOTED]]
184 ; CHECK: [[LOAD:%[a-zA-Z_0-9-]+]] = load i8* [[GEP]]
185 ; CHECK: [[ADDRES:%[a-zA-Z_0-9-]+]] = add i8 [[LOAD]], [[TRUNC]]
186 ; CHECK: add i8 [[ADDRES]], [[TRUNC]]
187 ; CHECK: ret
188 define i8 @oneArgPromotionTruncInsertSeveralUse(i8 %arg1, i8* %base) {
189   %add = add nsw i8 %arg1, 1 
190   %sextadd = sext i8 %add to i64
191   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
192   %res = load i8* %arrayidx
193   %almostfinalres = add i8 %res, %add
194   %finalres = add i8 %almostfinalres, %add
195   ret i8 %finalres
196 }
197
198 ; Check that the promoted instruction is used for all uses of the original
199 ; sign extension.
200 ; CHECK-LABEL: @oneArgPromotionSExtSeveralUse
201 ; CHECK: [[ARG1SEXT:%[a-zA-Z_0-9-]+]] = sext i8 %arg1 to i64
202 ; CHECK: [[PROMOTED:%[a-zA-Z_0-9-]+]] = add nsw i64 [[ARG1SEXT]], 1
203 ; CHECK: [[GEP:%[a-zA-Z_0-9-]+]] = getelementptr inbounds i8* %base, i64 [[PROMOTED]]
204 ; CHECK: [[LOAD:%[a-zA-Z_0-9-]+]] = load i8* [[GEP]]
205 ; CHECK: [[ADDRES:%[a-zA-Z_0-9-]+]] = zext i8 [[LOAD]] to i64
206 ; CHECK: add i64 [[ADDRES]], [[PROMOTED]]
207 ; CHECK: ret
208 define i64 @oneArgPromotionSExtSeveralUse(i8 %arg1, i8* %base) {
209   %add = add nsw i8 %arg1, 1 
210   %sextadd = sext i8 %add to i64
211   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
212   %res = load i8* %arrayidx
213   %almostfinalres = zext i8 %res to i64
214   %finalres = add i64 %almostfinalres, %sextadd
215   ret i64 %finalres
216 }
217
218 ; Check all types of rollback mechanism.
219 ; For this test, the sign extension stays in place.
220 ; However, the matching process goes until promoting both the operands
221 ; of the first promotable add implies.
222 ; At this point the rollback mechanism kicks in and restores the states
223 ; until the addressing mode matcher is able to match something: in that
224 ; case promote nothing.
225 ; Along the way, the promotion mechanism involves:
226 ; - Mutating the type of %promotableadd1 and %promotableadd2.
227 ; - Creating a sext for %arg1 and %arg2.
228 ; - Creating a trunc for a use of %promotableadd1.
229 ; - Replacing a bunch of uses.
230 ; - Setting the operands of the promoted instruction with the promoted values.
231 ; - Moving instruction around (mainly sext when promoting instruction).
232 ; Each type of those promotions has to be undo at least once during this
233 ; specific test. 
234 ; CHECK-LABEL: @twoArgsPromotionNest
235 ; CHECK: [[ORIG:%[a-zA-Z_0-9-]+]] = add nsw i32 %arg1, %arg2
236 ; CHECK: [[ADD:%[a-zA-Z_0-9-]+]] = add nsw i32 [[ORIG]], [[ORIG]]
237 ; CHECK: [[SEXT:%[a-zA-Z_0-9-]+]] = sext i32 [[ADD]] to i64
238 ; CHECK: getelementptr inbounds i8* %base, i64 [[SEXT]]
239 ; CHECK: ret
240 define i8 @twoArgsPromotionNest(i32 %arg1, i32 %arg2, i8* %base) {
241   %promotableadd1 = add nsw i32 %arg1, %arg2
242   %promotableadd2 = add nsw i32 %promotableadd1, %promotableadd1 
243   %sextadd = sext i32 %promotableadd2 to i64
244   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
245   %res = load i8* %arrayidx
246   ret i8 %res
247 }
248
249 ; Test the InstructionRemover undo, which was the only one not
250 ; kicked in the previous test.
251 ; The matcher first promotes the add, removes the trunc and promotes
252 ; the sext of arg1.
253 ; Then, the matcher cannot use an addressing mode r + r + r, thus it
254 ; rolls back. 
255 ; CHECK-LABEL: @twoArgsNoPromotionRemove
256 ; CHECK: [[SEXTARG1:%[a-zA-Z_0-9-]+]] = sext i1 %arg1 to i32
257 ; CHECK: [[TRUNC:%[a-zA-Z_0-9-]+]] = trunc i32 [[SEXTARG1]] to i8
258 ; CHECK: [[ADD:%[a-zA-Z_0-9-]+]] = add nsw i8 [[TRUNC]], %arg2
259 ; CHECK: [[SEXT:%[a-zA-Z_0-9-]+]] = sext i8 [[ADD]] to i64
260 ; CHECK: getelementptr inbounds i8* %base, i64 [[SEXT]]
261 ; CHECK: ret
262 define i8 @twoArgsNoPromotionRemove(i1 %arg1, i8 %arg2, i8* %base) {
263   %sextarg1 = sext i1 %arg1 to i32
264   %trunc = trunc i32 %sextarg1 to i8
265   %add = add nsw i8 %trunc, %arg2 
266   %sextadd = sext i8 %add to i64
267   %arrayidx = getelementptr inbounds i8* %base, i64 %sextadd
268   %res = load i8* %arrayidx
269   ret i8 %res
270 }
271
272 ; Ensure that when the profitability checks kicks in, the IR is not modified
273 ; will IgnoreProfitability is on.
274 ; The profitabily check happens when a candidate instruction has several uses.
275 ; The matcher will create a new matcher for each use and check if the
276 ; instruction is in the list of the matched instructions of this new matcher.
277 ; All changes made by the new matchers must be dropped before pursuing
278 ; otherwise the state of the original matcher will be wrong.
279 ;
280 ; Without the profitability check, when checking for the second use of
281 ; arrayidx, the matcher promotes everything all the way to %arg1, %arg2.
282 ; Check that we did not promote anything in the final matching.
283 ;
284 ; <rdar://problem/16020230>
285 ; CHECK-LABEL: @checkProfitability
286 ; CHECK-NOT: {{%[a-zA-Z_0-9-]+}} = sext i32 %arg1 to i64
287 ; CHECK-NOT: {{%[a-zA-Z_0-9-]+}} = sext i32 %arg2 to i64
288 ; CHECK: [[SHL:%[a-zA-Z_0-9-]+]] = shl nsw i32 %arg1, 1
289 ; CHECK: [[ADD:%[a-zA-Z_0-9-]+]] = add nsw i32 [[SHL]], %arg2
290 ; CHECK: [[SEXTADD:%[a-zA-Z_0-9-]+]] = sext i32 [[ADD]] to i64
291 ; BB then
292 ; CHECK: [[BASE1:%[a-zA-Z_0-9-]+]] = add i64 [[SEXTADD]], 48
293 ; CHECK: [[ADDR1:%[a-zA-Z_0-9-]+]] = inttoptr i64 [[BASE1]] to i32*
294 ; CHECK: load i32* [[ADDR1]]
295 ; BB else
296 ; CHECK: [[BASE2:%[a-zA-Z_0-9-]+]] = add i64 [[SEXTADD]], 48
297 ; CHECK: [[ADDR2:%[a-zA-Z_0-9-]+]] = inttoptr i64 [[BASE2]] to i32*
298 ; CHECK: load i32* [[ADDR2]]
299 ; CHECK: ret
300 ; CHECK-GEP-LABEL: @checkProfitability
301 ; CHECK-GEP-NOT: {{%[a-zA-Z_0-9-]+}} = sext i32 %arg1 to i64
302 ; CHECK-GEP-NOT: {{%[a-zA-Z_0-9-]+}} = sext i32 %arg2 to i64
303 ; CHECK-GEP: [[SHL:%[a-zA-Z_0-9-]+]] = shl nsw i32 %arg1, 1
304 ; CHECK-GEP: [[ADD:%[a-zA-Z_0-9-]+]] = add nsw i32 [[SHL]], %arg2
305 ; CHECK-GEP: [[SEXTADD:%[a-zA-Z_0-9-]+]] = sext i32 [[ADD]] to i64
306 ; BB then
307 ; CHECK-GEP: [[BASE1:%[a-zA-Z_0-9-]+]] = inttoptr i64 [[SEXTADD]] to i32*
308 ; CHECK-GEP: [[BCC1:%[a-zA-Z_0-9-]+]] = bitcast i32* [[BASE1]] to i8*
309 ; CHECK-GEP: [[FULL1:%[a-zA-Z_0-9-]+]] = getelementptr i8* [[BCC1]], i64 48
310 ; CHECK-GEP: [[ADDR1:%[a-zA-Z_0-9-]+]] = bitcast i8* [[FULL1]] to i32*
311 ; CHECK-GEP: load i32* [[ADDR1]]
312 ; BB else
313 ; CHECK-GEP: [[BASE2:%[a-zA-Z_0-9-]+]] = inttoptr i64 [[SEXTADD]] to i32*
314 ; CHECK-GEP: [[BCC2:%[a-zA-Z_0-9-]+]] = bitcast i32* [[BASE2]] to i8*
315 ; CHECK-GEP: [[FULL2:%[a-zA-Z_0-9-]+]] = getelementptr i8* [[BCC2]], i64 48
316 ; CHECK-GEP: [[ADDR2:%[a-zA-Z_0-9-]+]] = bitcast i8* [[FULL2]] to i32*
317 ; CHECK-GEP: load i32* [[ADDR2]]
318 ; CHECK-GEP: ret
319 define i32 @checkProfitability(i32 %arg1, i32 %arg2, i1 %test) {
320   %shl = shl nsw i32 %arg1, 1
321   %add1 = add nsw i32 %shl, %arg2
322   %sextidx1 = sext i32 %add1 to i64
323   %tmpptr = inttoptr i64 %sextidx1 to i32*
324   %arrayidx1 = getelementptr i32* %tmpptr, i64 12
325   br i1 %test, label %then, label %else
326 then: 
327   %res1 = load i32* %arrayidx1
328   br label %end
329 else:
330   %res2 = load i32* %arrayidx1
331   br label %end
332 end:
333   %tmp = phi i32 [%res1, %then], [%res2, %else]
334   %res = add i32 %tmp, %add1
335   %addr = inttoptr i32 %res to i32*
336   %final = load i32* %addr
337   ret i32 %final
338 }
339
340 %struct.dns_packet = type { i32, i32, %union.anon }
341 %union.anon = type { i32 }
342
343 @a = common global i32 0, align 4
344 @b = common global i16 0, align 2
345
346 ; We used to crash on this function because we did not return the right
347 ; promoted instruction for %conv.i.
348 ; Make sure we generate the right code now.
349 ; CHECK-LABEL: @fn3
350 ; %conv.i is used twice and only one of its use is being promoted.
351 ; Use it at the starting point for the matching.
352 ; CHECK: %conv.i = zext i16 [[PLAIN_OPND:%[.a-zA-Z_0-9-]+]] to i32
353 ; CHECK-NEXT: [[PROMOTED_CONV:%[.a-zA-Z_0-9-]+]] = zext i16 [[PLAIN_OPND]] to i64
354 ; CHECK-NEXT: [[BASE:%[a-zA-Z_0-9-]+]] = ptrtoint %struct.dns_packet* %P to i64
355 ; CHECK-NEXT: [[ADD:%[a-zA-Z_0-9-]+]] = add i64 [[BASE]], [[PROMOTED_CONV]]
356 ; CHECK-NEXT: [[ADDR:%[a-zA-Z_0-9-]+]] = add i64 [[ADD]], 7
357 ; CHECK-NEXT: [[CAST:%[a-zA-Z_0-9-]+]] = inttoptr i64 [[ADDR]] to i8*
358 ; CHECK-NEXT: load i8* [[CAST]], align 1
359 define signext i16 @fn3(%struct.dns_packet* nocapture readonly %P) {
360 entry:
361   %tmp = getelementptr inbounds %struct.dns_packet* %P, i64 0, i32 2
362   %data.i.i = bitcast %union.anon* %tmp to [0 x i8]*
363   br label %while.body.i.i
364
365 while.body.i.i:                                   ; preds = %while.body.i.i, %entry
366   %src.addr.0.i.i = phi i16 [ 0, %entry ], [ %inc.i.i, %while.body.i.i ]
367   %inc.i.i = add i16 %src.addr.0.i.i, 1
368   %idxprom.i.i = sext i16 %src.addr.0.i.i to i64
369   %arrayidx.i.i = getelementptr inbounds [0 x i8]* %data.i.i, i64 0, i64 %idxprom.i.i
370   %tmp1 = load i8* %arrayidx.i.i, align 1
371   %conv2.i.i = zext i8 %tmp1 to i32
372   %and.i.i = and i32 %conv2.i.i, 15
373   store i32 %and.i.i, i32* @a, align 4
374   %tobool.i.i = icmp eq i32 %and.i.i, 0
375   br i1 %tobool.i.i, label %while.body.i.i, label %fn1.exit.i
376
377 fn1.exit.i:                                       ; preds = %while.body.i.i
378   %inc.i.i.lcssa = phi i16 [ %inc.i.i, %while.body.i.i ]
379   %conv.i = zext i16 %inc.i.i.lcssa to i32
380   %sub.i = add nsw i32 %conv.i, -1
381   %idxprom.i = sext i32 %sub.i to i64
382   %arrayidx.i = getelementptr inbounds [0 x i8]* %data.i.i, i64 0, i64 %idxprom.i
383   %tmp2 = load i8* %arrayidx.i, align 1
384   %conv2.i = sext i8 %tmp2 to i16
385   store i16 %conv2.i, i16* @b, align 2
386   %sub4.i = sub nsw i32 0, %conv.i
387   %conv5.i = zext i16 %conv2.i to i32
388   %cmp.i = icmp sgt i32 %conv5.i, %sub4.i
389   br i1 %cmp.i, label %if.then.i, label %fn2.exit
390
391 if.then.i:                                        ; preds = %fn1.exit.i
392   %end.i = getelementptr inbounds %struct.dns_packet* %P, i64 0, i32 1
393   %tmp3 = load i32* %end.i, align 4
394   %sub7.i = add i32 %tmp3, 65535
395   %conv8.i = trunc i32 %sub7.i to i16
396   br label %fn2.exit
397
398 fn2.exit:                                         ; preds = %if.then.i, %fn1.exit.i
399   %retval.0.i = phi i16 [ %conv8.i, %if.then.i ], [ undef, %fn1.exit.i ]
400   ret i16 %retval.0.i
401 }