1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=i386-linux | FileCheck %s -check-prefix=X86-32 2*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-linux | FileCheck %s -check-prefix=X86-64 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Workerdeclare i32 @get_val() 5*9880d681SAndroid Build Coastguard Workerdeclare void @use_val(i32) 6*9880d681SAndroid Build Coastguard Workerdeclare i1 @setjmp() 7*9880d681SAndroid Build Coastguard Workerdeclare void @longjmp() 8*9880d681SAndroid Build Coastguard Workerdeclare void @personality() 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Worker 11*9880d681SAndroid Build Coastguard Worker; Test that llc avoids reusing spill slots in functions that call 12*9880d681SAndroid Build Coastguard Worker; setjmp(), whether they use "call" or "invoke" for calling setjmp() 13*9880d681SAndroid Build Coastguard Worker; (PR18244). 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Workerdefine void @setjmp_caller() { 16*9880d681SAndroid Build Coastguard Worker; X86-32-LABEL: setjmp_caller: 17*9880d681SAndroid Build Coastguard Worker; X86-64-LABEL: setjmp_caller: 18*9880d681SAndroid Build Coastguard Worker; This code keeps enough variables live across the setjmp() call that 19*9880d681SAndroid Build Coastguard Worker; they don't all fit in registers and the compiler will allocate a 20*9880d681SAndroid Build Coastguard Worker; spill slot. 21*9880d681SAndroid Build Coastguard Worker %a1 = call i32 @get_val() 22*9880d681SAndroid Build Coastguard Worker %a2 = call i32 @get_val() 23*9880d681SAndroid Build Coastguard Worker %a3 = call i32 @get_val() 24*9880d681SAndroid Build Coastguard Worker %a4 = call i32 @get_val() 25*9880d681SAndroid Build Coastguard Worker %a5 = call i32 @get_val() 26*9880d681SAndroid Build Coastguard Worker %a6 = call i32 @get_val() 27*9880d681SAndroid Build Coastguard Worker %a7 = call i32 @get_val() 28*9880d681SAndroid Build Coastguard Worker %a8 = call i32 @get_val() 29*9880d681SAndroid Build Coastguard Worker; X86-32: movl %eax, [[SPILL_SLOT:[0-9]+]](%esp) 30*9880d681SAndroid Build Coastguard Worker; X86-32: calll get_val 31*9880d681SAndroid Build Coastguard Worker; X86-64: movl %eax, [[SPILL_SLOT:[0-9]+]](%rsp) 32*9880d681SAndroid Build Coastguard Worker; X86-64: callq get_val 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Worker %setjmp_result = call i1 @setjmp() returns_twice 35*9880d681SAndroid Build Coastguard Worker br i1 %setjmp_result, label %second, label %first 36*9880d681SAndroid Build Coastguard Worker; X86-32: calll setjmp 37*9880d681SAndroid Build Coastguard Worker; X86-64: callq setjmp 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Worker; Again, keep enough variables live that they need spill slots. Since 40*9880d681SAndroid Build Coastguard Worker; this function calls a returns_twice function (setjmp()), the 41*9880d681SAndroid Build Coastguard Worker; compiler should not reuse the spill slots. longjmp() can return to 42*9880d681SAndroid Build Coastguard Worker; where the first spill slots were still live. 43*9880d681SAndroid Build Coastguard Workerfirst: 44*9880d681SAndroid Build Coastguard Worker %b1 = call i32 @get_val() 45*9880d681SAndroid Build Coastguard Worker %b2 = call i32 @get_val() 46*9880d681SAndroid Build Coastguard Worker %b3 = call i32 @get_val() 47*9880d681SAndroid Build Coastguard Worker %b4 = call i32 @get_val() 48*9880d681SAndroid Build Coastguard Worker %b5 = call i32 @get_val() 49*9880d681SAndroid Build Coastguard Worker %b6 = call i32 @get_val() 50*9880d681SAndroid Build Coastguard Worker %b7 = call i32 @get_val() 51*9880d681SAndroid Build Coastguard Worker %b8 = call i32 @get_val() 52*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b1) 53*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b2) 54*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b3) 55*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b4) 56*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b5) 57*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b6) 58*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b7) 59*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b8) 60*9880d681SAndroid Build Coastguard Worker call void @longjmp() 61*9880d681SAndroid Build Coastguard Worker unreachable 62*9880d681SAndroid Build Coastguard Worker; X86-32-NOT: movl {{.*}}, [[SPILL_SLOT]](%esp) 63*9880d681SAndroid Build Coastguard Worker; X86-64-NOT: movl {{.*}}, [[SPILL_SLOT]](%rsp) 64*9880d681SAndroid Build Coastguard Worker 65*9880d681SAndroid Build Coastguard Workersecond: 66*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a1) 67*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a2) 68*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a3) 69*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a4) 70*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a5) 71*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a6) 72*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a7) 73*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a8) 74*9880d681SAndroid Build Coastguard Worker ret void 75*9880d681SAndroid Build Coastguard Worker} 76*9880d681SAndroid Build Coastguard Worker 77*9880d681SAndroid Build Coastguard Worker 78*9880d681SAndroid Build Coastguard Worker; This is the same as above, but using "invoke" rather than "call" to 79*9880d681SAndroid Build Coastguard Worker; call setjmp(). 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Workerdefine void @setjmp_invoker() personality void ()* @personality { 82*9880d681SAndroid Build Coastguard Worker; X86-32-LABEL: setjmp_invoker: 83*9880d681SAndroid Build Coastguard Worker; X86-64-LABEL: setjmp_invoker: 84*9880d681SAndroid Build Coastguard Worker %a1 = call i32 @get_val() 85*9880d681SAndroid Build Coastguard Worker %a2 = call i32 @get_val() 86*9880d681SAndroid Build Coastguard Worker %a3 = call i32 @get_val() 87*9880d681SAndroid Build Coastguard Worker %a4 = call i32 @get_val() 88*9880d681SAndroid Build Coastguard Worker %a5 = call i32 @get_val() 89*9880d681SAndroid Build Coastguard Worker %a6 = call i32 @get_val() 90*9880d681SAndroid Build Coastguard Worker %a7 = call i32 @get_val() 91*9880d681SAndroid Build Coastguard Worker %a8 = call i32 @get_val() 92*9880d681SAndroid Build Coastguard Worker; X86-32: movl %eax, [[SPILL_SLOT:[0-9]+]](%esp) 93*9880d681SAndroid Build Coastguard Worker; X86-32: calll get_val 94*9880d681SAndroid Build Coastguard Worker; X86-64: movl %eax, [[SPILL_SLOT:[0-9]+]](%rsp) 95*9880d681SAndroid Build Coastguard Worker; X86-64: callq get_val 96*9880d681SAndroid Build Coastguard Worker 97*9880d681SAndroid Build Coastguard Worker %setjmp_result = invoke i1 @setjmp() returns_twice 98*9880d681SAndroid Build Coastguard Worker to label %cont unwind label %lpad 99*9880d681SAndroid Build Coastguard Worker; X86-32: calll setjmp 100*9880d681SAndroid Build Coastguard Worker; X86-64: callq setjmp 101*9880d681SAndroid Build Coastguard Worker 102*9880d681SAndroid Build Coastguard Workercont: 103*9880d681SAndroid Build Coastguard Worker br i1 %setjmp_result, label %second, label %first 104*9880d681SAndroid Build Coastguard Worker 105*9880d681SAndroid Build Coastguard Workerlpad: 106*9880d681SAndroid Build Coastguard Worker %lp = landingpad { i8*, i32 } cleanup 107*9880d681SAndroid Build Coastguard Worker unreachable 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Workerfirst: 110*9880d681SAndroid Build Coastguard Worker %b1 = call i32 @get_val() 111*9880d681SAndroid Build Coastguard Worker %b2 = call i32 @get_val() 112*9880d681SAndroid Build Coastguard Worker %b3 = call i32 @get_val() 113*9880d681SAndroid Build Coastguard Worker %b4 = call i32 @get_val() 114*9880d681SAndroid Build Coastguard Worker %b5 = call i32 @get_val() 115*9880d681SAndroid Build Coastguard Worker %b6 = call i32 @get_val() 116*9880d681SAndroid Build Coastguard Worker %b7 = call i32 @get_val() 117*9880d681SAndroid Build Coastguard Worker %b8 = call i32 @get_val() 118*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b1) 119*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b2) 120*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b3) 121*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b4) 122*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b5) 123*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b6) 124*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b7) 125*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %b8) 126*9880d681SAndroid Build Coastguard Worker call void @longjmp() 127*9880d681SAndroid Build Coastguard Worker unreachable 128*9880d681SAndroid Build Coastguard Worker; X86-32-NOT: movl {{.*}}, [[SPILL_SLOT]](%esp) 129*9880d681SAndroid Build Coastguard Worker; X86-64-NOT: movl {{.*}}, [[SPILL_SLOT]](%rsp) 130*9880d681SAndroid Build Coastguard Worker 131*9880d681SAndroid Build Coastguard Workersecond: 132*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a1) 133*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a2) 134*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a3) 135*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a4) 136*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a5) 137*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a6) 138*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a7) 139*9880d681SAndroid Build Coastguard Worker call void @use_val(i32 %a8) 140*9880d681SAndroid Build Coastguard Worker ret void 141*9880d681SAndroid Build Coastguard Worker} 142