1 ; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECK32
2 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECK64
3 ; RUN: llc -mtriple=x86_64-pc-win32 -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECKWIN64
5 ; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+cmov %s -o /dev/null \
6 ; RUN: -print-after postrapseudos -filter-print-funcs pr26023 2>&1 \
7 ; RUN: | FileCheck %s --check-prefix=OPERAND32
8 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+cmov %s -o /dev/null \
9 ; RUN: -print-after postrapseudos -filter-print-funcs one64_minsize 2>&1 \
10 ; RUN: | FileCheck %s --check-prefix=OPERAND64
12 define i32 @one32_nooptsize() {
16 ; When not optimizing for size, use mov.
17 ; CHECK32-LABEL: one32_nooptsize:
18 ; CHECK32: movl $1, %eax
20 ; CHECK64-LABEL: one32_nooptsize:
21 ; CHECK64: movl $1, %eax
25 define i32 @one32() optsize {
29 ; CHECK32-LABEL: one32:
30 ; CHECK32: xorl %eax, %eax
31 ; CHECK32-NEXT: incl %eax
34 ; FIXME: Figure out the best approach in 64-bit mode.
35 ; CHECK64-LABEL: one32:
36 ; CHECK64: movl $1, %eax
40 define i32 @one32_pgso() !prof !14 {
44 ; CHECK32-LABEL: one32_pgso:
45 ; CHECK32: xorl %eax, %eax
46 ; CHECK32-NEXT: incl %eax
49 ; FIXME: Figure out the best approach in 64-bit mode.
50 ; CHECK64-LABEL: one32_pgso:
51 ; CHECK64: movl $1, %eax
55 define i32 @one32_minsize() minsize {
59 ; On 32-bit, xor-inc is preferred over push-pop.
60 ; CHECK32-LABEL: one32_minsize:
61 ; CHECK32: xorl %eax, %eax
62 ; CHECK32-NEXT: incl %eax
65 ; On 64-bit we don't do xor-inc yet, so push-pop it is. Note that we have to
66 ; pop into a 64-bit register even when we just need 32 bits.
67 ; CHECK64-LABEL: one32_minsize:
69 ; CHECK64: .cfi_adjust_cfa_offset 8
71 ; CHECK64: .cfi_adjust_cfa_offset -8
74 ; On Win64 we can't adjust the stack unless there's a frame pointer.
75 ; CHECKWIN64-LABEL: one32_minsize:
76 ; CHECKWIN64: movl $1, %eax
77 ; CHECKWIN64-NEXT: retq
80 define i32 @pr26023() minsize {
82 %x = alloca [120 x i8]
83 call void asm sideeffect "", "imr,~{memory},~{dirflag},~{fpsr},~{flags}"(ptr %x)
84 %arrayidx = getelementptr inbounds [120 x i8], ptr %x, i64 0, i64 119
85 store volatile i8 -2, ptr %arrayidx
86 call void asm sideeffect "", "r,~{dirflag},~{fpsr},~{flags}"(i32 5)
87 %0 = load volatile i8, ptr %arrayidx
88 %conv = sext i8 %0 to i32
91 ; The function writes to the redzone, so push/pop cannot be used.
92 ; CHECK64-LABEL: pr26023:
93 ; CHECK64: movl $5, %ecx
96 ; 32-bit X86 doesn't have a redzone.
97 ; CHECK32-LABEL: pr26023:
102 ; Check push/pop have implicit def/use of $esp
103 ; OPERAND32: PUSH32i 5, implicit-def $esp, implicit $esp
104 ; OPERAND32-NEXT: CFI_INSTRUCTION adjust_cfa_offset 4
105 ; OPERAND32-NEXT: renamable $ecx = POP32r implicit-def $esp, implicit $esp
106 ; OPERAND32-NEXT: CFI_INSTRUCTION adjust_cfa_offset -4
110 define i64 @one64_minsize() minsize {
113 ; On 64-bit we don't do xor-inc yet, so push-pop it is.
114 ; CHECK64-LABEL: one64_minsize:
116 ; CHECK64: .cfi_adjust_cfa_offset 8
118 ; CHECK64: .cfi_adjust_cfa_offset -8
121 ; On Win64 we can't adjust the stack unless there's a frame pointer.
122 ; CHECKWIN64-LABEL: one64_minsize:
123 ; CHECKWIN64: movl $1, %eax
124 ; CHECKWIN64-NEXT: retq
126 ; Check push/pop have implicit def/use of $rsp
127 ; OPERAND64: PUSH64i32 1, implicit-def $rsp, implicit $rsp
128 ; OPERAND64-NEXT: CFI_INSTRUCTION adjust_cfa_offset 8
129 ; OPERAND64-NEXT: $rax = POP64r implicit-def $rsp, implicit $rsp
130 ; OPERAND64-NEXT: CFI_INSTRUCTION adjust_cfa_offset -8
131 ; OPERAND64-NEXT: RET 0, $rax
134 define i32 @minus_one32() optsize {
138 ; CHECK32-LABEL: minus_one32:
139 ; CHECK32: xorl %eax, %eax
140 ; CHECK32-NEXT: decl %eax
144 define i32 @minus_one32_pgso() !prof !14 {
148 ; CHECK32-LABEL: minus_one32_pgso:
149 ; CHECK32: xorl %eax, %eax
150 ; CHECK32-NEXT: decl %eax
154 define i32 @minus_one32_minsize() minsize {
158 ; xor-dec is preferred over push-pop.
159 ; CHECK32-LABEL: minus_one32_minsize:
160 ; CHECK32: xorl %eax, %eax
161 ; CHECK32-NEXT: decl %eax
165 define i16 @one16() optsize {
169 ; CHECK32-LABEL: one16:
170 ; CHECK32: xorl %eax, %eax
171 ; CHECK32-NEXT: incl %eax
172 ; CHECK32-NEXT: # kill
176 define i16 @minus_one16() optsize {
180 ; CHECK32-LABEL: minus_one16:
181 ; CHECK32: xorl %eax, %eax
182 ; CHECK32-NEXT: decl %eax
183 ; CHECK32-NEXT: # kill
187 define i16 @one16_pgso() !prof !14 {
191 ; CHECK32-LABEL: one16_pgso:
192 ; CHECK32: xorl %eax, %eax
193 ; CHECK32-NEXT: incl %eax
194 ; CHECK32-NEXT: # kill
198 define i16 @minus_one16_pgso() !prof !14 {
202 ; CHECK32-LABEL: minus_one16_pgso:
203 ; CHECK32: xorl %eax, %eax
204 ; CHECK32-NEXT: decl %eax
205 ; CHECK32-NEXT: # kill
209 define i32 @minus_five32() minsize {
213 ; CHECK32-LABEL: minus_five32:
219 define i64 @minus_five64() minsize {
223 ; CHECK64-LABEL: minus_five64:
225 ; CHECK64: .cfi_adjust_cfa_offset 8
227 ; CHECK64: .cfi_adjust_cfa_offset -8
231 define i32 @rematerialize_minus_one() optsize {
233 ; Materialize -1 (thiscall forces it into %ecx).
234 tail call x86_thiscallcc void @f(i32 -1)
236 ; Clobber all registers except %esp, leaving nowhere to store the -1 besides
237 ; spilling it to the stack.
238 tail call void asm sideeffect "", "~{eax},~{ebx},~{ecx},~{edx},~{edi},~{esi},~{ebp},~{dirflag},~{fpsr},~{flags}"()
240 ; -1 should be re-materialized here instead of getting spilled above.
243 ; CHECK32-LABEL: rematerialize_minus_one
244 ; CHECK32: xorl %ecx, %ecx
245 ; CHECK32-NEXT: decl %ecx
247 ; CHECK32: xorl %eax, %eax
248 ; CHECK32-NEXT: decl %eax
253 define i32 @rematerialize_minus_one_eflags(i32 %x) optsize {
255 ; Materialize -1 (thiscall forces it into %ecx).
256 tail call x86_thiscallcc void @f(i32 -1)
258 ; Clobber all registers except %esp, leaving nowhere to store the -1 besides
259 ; spilling it to the stack.
260 tail call void asm sideeffect "", "~{eax},~{ebx},~{ecx},~{edx},~{edi},~{esi},~{ebp},~{dirflag},~{fpsr},~{flags}"()
263 %a = icmp ne i32 %x, 123
264 %b = zext i1 %a to i32
265 ; Cause -1 to be rematerialized right in front of the cmov, which needs eflags.
266 ; It must therefore not use the xor-dec lowering.
267 %c = select i1 %a, i32 %b, i32 -1
270 ; CHECK32-LABEL: rematerialize_minus_one_eflags
271 ; CHECK32: xorl %ecx, %ecx
272 ; CHECK32-NEXT: decl %ecx
282 define i32 @rematerialize_minus_one_pgso() !prof !14 {
284 ; Materialize -1 (thiscall forces it into %ecx).
285 tail call x86_thiscallcc void @f(i32 -1)
287 ; Clobber all registers except %esp, leaving nowhere to store the -1 besides
288 ; spilling it to the stack.
289 tail call void asm sideeffect "", "~{eax},~{ebx},~{ecx},~{edx},~{edi},~{esi},~{ebp},~{dirflag},~{fpsr},~{flags}"()
291 ; -1 should be re-materialized here instead of getting spilled above.
294 ; CHECK32-LABEL: rematerialize_minus_one_pgso
295 ; CHECK32: xorl %ecx, %ecx
296 ; CHECK32-NEXT: decl %ecx
298 ; CHECK32: xorl %eax, %eax
299 ; CHECK32-NEXT: decl %eax
304 define i32 @rematerialize_minus_one_eflags_pgso(i32 %x) !prof !14 {
306 ; Materialize -1 (thiscall forces it into %ecx).
307 tail call x86_thiscallcc void @f(i32 -1)
309 ; Clobber all registers except %esp, leaving nowhere to store the -1 besides
310 ; spilling it to the stack.
311 tail call void asm sideeffect "", "~{eax},~{ebx},~{ecx},~{edx},~{edi},~{esi},~{ebp},~{dirflag},~{fpsr},~{flags}"()
314 %a = icmp ne i32 %x, 123
315 %b = zext i1 %a to i32
316 ; Cause -1 to be rematerialized right in front of the cmov, which needs eflags.
317 ; It must therefore not use the xor-dec lowering.
318 %c = select i1 %a, i32 %b, i32 -1
321 ; CHECK32-LABEL: rematerialize_minus_one_eflags_pgso
322 ; CHECK32: xorl %ecx, %ecx
323 ; CHECK32-NEXT: decl %ecx
333 declare x86_thiscallcc void @f(i32)
335 !llvm.module.flags = !{!0}
336 !0 = !{i32 1, !"ProfileSummary", !1}
337 !1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
338 !2 = !{!"ProfileFormat", !"InstrProf"}
339 !3 = !{!"TotalCount", i64 10000}
340 !4 = !{!"MaxCount", i64 10}
341 !5 = !{!"MaxInternalCount", i64 1}
342 !6 = !{!"MaxFunctionCount", i64 1000}
343 !7 = !{!"NumCounts", i64 3}
344 !8 = !{!"NumFunctions", i64 3}
345 !9 = !{!"DetailedSummary", !10}
346 !10 = !{!11, !12, !13}
347 !11 = !{i32 10000, i64 100, i32 1}
348 !12 = !{i32 999000, i64 100, i32 1}
349 !13 = !{i32 999999, i64 1, i32 2}
350 !14 = !{!"function_entry_count", i64 0}