blob: 94501b5764e88137bbd588f67efbd92dc18127a5 [file] [log] [blame]
Reid Kleckner93fc5202015-12-03 20:46:59 +00001; RUN: llc < %s -enable-shrink-wrap=true | FileCheck %s
2
3; chkstk cannot come before the usual prologue, since it adjusts ESP.
Reid Kleckner8de35fe2016-02-17 00:17:33 +00004; If chkstk is used in the prologue, we also have to be careful about preserving
5; EAX if it is used.
Reid Kleckner93fc5202015-12-03 20:46:59 +00006
7target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
8target triple = "i686-pc-windows-msvc18.0.0"
9
10%struct.S = type { [12 x i8] }
11
Reid Kleckner65f9d9c2016-03-02 19:20:59 +000012define x86_thiscallcc void @call_inalloca(i1 %x) {
Reid Kleckner93fc5202015-12-03 20:46:59 +000013entry:
14 %argmem = alloca inalloca <{ %struct.S }>, align 4
15 %argidx1 = getelementptr inbounds <{ %struct.S }>, <{ %struct.S }>* %argmem, i32 0, i32 0, i32 0, i32 0
16 %argidx2 = getelementptr inbounds <{ %struct.S }>, <{ %struct.S }>* %argmem, i32 0, i32 0, i32 0, i32 1
17 store i8 42, i8* %argidx2, align 4
18 br i1 %x, label %bb1, label %bb2
19
20bb1:
21 store i8 42, i8* %argidx1, align 4
22 br label %bb2
23
24bb2:
25 call void @inalloca_params(<{ %struct.S }>* inalloca nonnull %argmem)
26 ret void
27}
28
29; CHECK-LABEL: _call_inalloca: # @call_inalloca
30; CHECK: pushl %ebp
31; CHECK: movl %esp, %ebp
32; CHECK: movl $12, %eax
33; CHECK: calll __chkstk
34; CHECK: calll _inalloca_params
35; CHECK: movl %ebp, %esp
36; CHECK: popl %ebp
37; CHECK: retl
38
39declare void @inalloca_params(<{ %struct.S }>* inalloca)
Reid Kleckner8de35fe2016-02-17 00:17:33 +000040
41declare i32 @doSomething(i32, i32*)
42
43; In this test case, we force usage of EAX before the prologue, and have to
44; compensate before calling __chkstk. It would also be valid for us to avoid
45; shrink wrapping in this case.
46
47define x86_fastcallcc i32 @use_eax_before_prologue(i32 inreg %a, i32 inreg %b) {
48 %tmp = alloca i32, i32 1024, align 4
49 %tmp2 = icmp slt i32 %a, %b
50 br i1 %tmp2, label %true, label %false
51
52true:
53 store i32 %a, i32* %tmp, align 4
54 %tmp4 = call i32 @doSomething(i32 0, i32* %tmp)
55 br label %false
56
57false:
58 %tmp.0 = phi i32 [ %tmp4, %true ], [ %a, %0 ]
59 ret i32 %tmp.0
60}
61
62; CHECK-LABEL: @use_eax_before_prologue@8: # @use_eax_before_prologue
63; CHECK: movl %ecx, %eax
64; CHECK: cmpl %edx, %eax
65; CHECK: jge LBB1_2
66; CHECK: pushl %eax
Hans Wennborg65969772016-03-30 23:38:01 +000067; CHECK: movl $4092, %eax
Reid Kleckner8de35fe2016-02-17 00:17:33 +000068; CHECK: calll __chkstk
Hans Wennborg65969772016-03-30 23:38:01 +000069; CHECK: movl 4092(%esp), %eax
Reid Kleckner8de35fe2016-02-17 00:17:33 +000070; CHECK: calll _doSomething
71; CHECK: LBB1_2:
72; CHECK: retl