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