1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s -check-prefix=NORMAL -check-prefix=NORMALFP 2*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-windows | FileCheck %s -check-prefix=NOPUSH 3*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s -check-prefix=NOPUSH -check-prefix=NORMALFP 4*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -no-x86-call-frame-opt | FileCheck %s -check-prefix=NOPUSH 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Workerdeclare void @seven_params(i32 %a, i64 %b, i32 %c, i64 %d, i32 %e, i64 %f, i32 %g) 7*9880d681SAndroid Build Coastguard Workerdeclare void @ten_params(i32 %a, i64 %b, i32 %c, i64 %d, i32 %e, i64 %f, i32 %g, i64 %h, i32 %i, i64 %j) 8*9880d681SAndroid Build Coastguard Workerdeclare void @ten_params_ptr(i32 %a, i64 %b, i32 %c, i64 %d, i32 %e, i64 %f, i32 %g, i8* %h, i32 %i, i64 %j) 9*9880d681SAndroid Build Coastguard Workerdeclare void @cannot_push(float %a, float %b, float %c, float %d, float %e, float %f, float %g, float %h, float %i) 10*9880d681SAndroid Build Coastguard Worker 11*9880d681SAndroid Build Coastguard Worker; We should get pushes for the last 4 parameters. Test that the 12*9880d681SAndroid Build Coastguard Worker; in-register parameters are all in the right places, and check 13*9880d681SAndroid Build Coastguard Worker; that the stack manipulations are correct and correctly 14*9880d681SAndroid Build Coastguard Worker; described by the DWARF directives. Test that the switch 15*9880d681SAndroid Build Coastguard Worker; to disable the optimization works and that the optimization 16*9880d681SAndroid Build Coastguard Worker; doesn't kick in on Windows64 where it is not allowed. 17*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test1 18*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq 19*9880d681SAndroid Build Coastguard Worker; NORMAL-DAG: movl $1, %edi 20*9880d681SAndroid Build Coastguard Worker; NORMAL-DAG: movl $2, %esi 21*9880d681SAndroid Build Coastguard Worker; NORMAL-DAG: movl $3, %edx 22*9880d681SAndroid Build Coastguard Worker; NORMAL-DAG: movl $4, %ecx 23*9880d681SAndroid Build Coastguard Worker; NORMAL-DAG: movl $5, %r8d 24*9880d681SAndroid Build Coastguard Worker; NORMAL-DAG: movl $6, %r9d 25*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $10 26*9880d681SAndroid Build Coastguard Worker; NORMAL: .cfi_adjust_cfa_offset 8 27*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $9 28*9880d681SAndroid Build Coastguard Worker; NORMAL: .cfi_adjust_cfa_offset 8 29*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $8 30*9880d681SAndroid Build Coastguard Worker; NORMAL: .cfi_adjust_cfa_offset 8 31*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $7 32*9880d681SAndroid Build Coastguard Worker; NORMAL: .cfi_adjust_cfa_offset 8 33*9880d681SAndroid Build Coastguard Worker; NORMAL: callq ten_params 34*9880d681SAndroid Build Coastguard Worker; NORMAL: addq $32, %rsp 35*9880d681SAndroid Build Coastguard Worker; NORMAL: .cfi_adjust_cfa_offset -32 36*9880d681SAndroid Build Coastguard Worker; NORMAL: popq 37*9880d681SAndroid Build Coastguard Worker; NORMAL: retq 38*9880d681SAndroid Build Coastguard Worker; NOPUSH-LABEL: test1 39*9880d681SAndroid Build Coastguard Worker; NOPUSH-NOT: pushq 40*9880d681SAndroid Build Coastguard Worker; NOPUSH: retq 41*9880d681SAndroid Build Coastguard Workerdefine void @test1() { 42*9880d681SAndroid Build Coastguard Workerentry: 43*9880d681SAndroid Build Coastguard Worker call void @ten_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7, i64 8, i32 9, i64 10) 44*9880d681SAndroid Build Coastguard Worker ret void 45*9880d681SAndroid Build Coastguard Worker} 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Worker; The presence of a frame pointer should not prevent pushes. But we 48*9880d681SAndroid Build Coastguard Worker; don't need the CFI directives in that case. 49*9880d681SAndroid Build Coastguard Worker; Also check that we generate the right pushes for >8bit immediates. 50*9880d681SAndroid Build Coastguard Worker; NORMALFP-LABEL: test2 51*9880d681SAndroid Build Coastguard Worker; NORMALFP: pushq $10000 52*9880d681SAndroid Build Coastguard Worker; NORMALFP-NEXT: pushq $9000 53*9880d681SAndroid Build Coastguard Worker; NORMALFP-NEXT: pushq $8000 54*9880d681SAndroid Build Coastguard Worker; NORMALFP-NEXT: pushq $7000 55*9880d681SAndroid Build Coastguard Worker; NORMALFP-NEXT: callq {{_?}}ten_params 56*9880d681SAndroid Build Coastguard Workerdefine void @test2(i32 %k) { 57*9880d681SAndroid Build Coastguard Workerentry: 58*9880d681SAndroid Build Coastguard Worker %a = alloca i32, i32 %k 59*9880d681SAndroid Build Coastguard Worker call void @ten_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7000, i64 8000, i32 9000, i64 10000) 60*9880d681SAndroid Build Coastguard Worker ret void 61*9880d681SAndroid Build Coastguard Worker} 62*9880d681SAndroid Build Coastguard Worker 63*9880d681SAndroid Build Coastguard Worker; Parameters 7 & 8 should push a 64-bit register. 64*9880d681SAndroid Build Coastguard Worker; TODO: Note that the regular expressions disallow r8 and r9. That's fine for 65*9880d681SAndroid Build Coastguard Worker; now, because the pushes will always follow the moves into r8 and r9. 66*9880d681SAndroid Build Coastguard Worker; Eventually, though, we want to be able to schedule the pushes better. 67*9880d681SAndroid Build Coastguard Worker; In this example, it will save two copies, because we have to move the 68*9880d681SAndroid Build Coastguard Worker; incoming parameters out of %rdi and %rsi to make room for the outgoing 69*9880d681SAndroid Build Coastguard Worker; parameters. 70*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test3 71*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $10000 72*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $9000 73*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq %r{{..}} 74*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq %r{{..}} 75*9880d681SAndroid Build Coastguard Worker; NORMAL: callq ten_params 76*9880d681SAndroid Build Coastguard Workerdefine void @test3(i32 %a, i64 %b) { 77*9880d681SAndroid Build Coastguard Workerentry: 78*9880d681SAndroid Build Coastguard Worker call void @ten_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 %a, i64 %b, i32 9000, i64 10000) 79*9880d681SAndroid Build Coastguard Worker ret void 80*9880d681SAndroid Build Coastguard Worker} 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Worker; Check that we avoid the optimization for just one push. 83*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test4 84*9880d681SAndroid Build Coastguard Worker; NORMAL: movl $7, (%rsp) 85*9880d681SAndroid Build Coastguard Worker; NORMAL: callq seven_params 86*9880d681SAndroid Build Coastguard Workerdefine void @test4() { 87*9880d681SAndroid Build Coastguard Workerentry: 88*9880d681SAndroid Build Coastguard Worker call void @seven_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7) 89*9880d681SAndroid Build Coastguard Worker ret void 90*9880d681SAndroid Build Coastguard Worker} 91*9880d681SAndroid Build Coastguard Worker 92*9880d681SAndroid Build Coastguard Worker; Check that pushing link-time constant addresses works correctly 93*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test5 94*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $10 95*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $9 96*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $ext 97*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $7 98*9880d681SAndroid Build Coastguard Worker; NORMAL: callq ten_params_ptr 99*9880d681SAndroid Build Coastguard Worker@ext = external constant i8 100*9880d681SAndroid Build Coastguard Workerdefine void @test5() { 101*9880d681SAndroid Build Coastguard Workerentry: 102*9880d681SAndroid Build Coastguard Worker call void @ten_params_ptr(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7, i8* @ext, i32 9, i64 10) 103*9880d681SAndroid Build Coastguard Worker ret void 104*9880d681SAndroid Build Coastguard Worker} 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker; Check that we fuse 64-bit loads but not 32-bit loads into PUSH mem. 107*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test6 108*9880d681SAndroid Build Coastguard Worker; NORMAL: movq %rsi, [[REG64:%.+]] 109*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $10 110*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $9 111*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq ([[REG64]]) 112*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq {{%r..}} 113*9880d681SAndroid Build Coastguard Worker; NORMAL: callq ten_params 114*9880d681SAndroid Build Coastguard Workerdefine void @test6(i32* %p32, i64* %p64) { 115*9880d681SAndroid Build Coastguard Workerentry: 116*9880d681SAndroid Build Coastguard Worker %v32 = load i32, i32* %p32 117*9880d681SAndroid Build Coastguard Worker %v64 = load i64, i64* %p64 118*9880d681SAndroid Build Coastguard Worker call void @ten_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 %v32, i64 %v64, i32 9, i64 10) 119*9880d681SAndroid Build Coastguard Worker ret void 120*9880d681SAndroid Build Coastguard Worker} 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Worker; Fold stack-relative loads into the push with correct offsets. 123*9880d681SAndroid Build Coastguard Worker; Do the same for an indirect call whose address is loaded from the stack. 124*9880d681SAndroid Build Coastguard Worker; On entry, %p7 is at 8(%rsp) and %p8 is at 16(%rsp). Prior to the call 125*9880d681SAndroid Build Coastguard Worker; sequence, 72 bytes are allocated to the stack, 48 for register saves and 126*9880d681SAndroid Build Coastguard Worker; 24 for local storage and alignment, so %p7 is at 80(%rsp) and %p8 is at 127*9880d681SAndroid Build Coastguard Worker; 88(%rsp). The call address can be stored anywhere in the local space but 128*9880d681SAndroid Build Coastguard Worker; happens to be stored at 8(%rsp). Each push bumps these offsets up by 129*9880d681SAndroid Build Coastguard Worker; 8 bytes. 130*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test7 131*9880d681SAndroid Build Coastguard Worker; NORMAL: movq %r{{.*}}, 8(%rsp) {{.*Spill$}} 132*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq 88(%rsp) 133*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $9 134*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq 96(%rsp) 135*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $7 136*9880d681SAndroid Build Coastguard Worker; NORMAL: callq *40(%rsp) 137*9880d681SAndroid Build Coastguard Workerdefine void @test7(i64 %p1, i64 %p2, i64 %p3, i64 %p4, i64 %p5, i64 %p6, i64 %p7, i64 %p8) { 138*9880d681SAndroid Build Coastguard Workerentry: 139*9880d681SAndroid Build Coastguard Worker %stack_fptr = alloca void (i32, i64, i32, i64, i32, i64, i32, i64, i32, i64)* 140*9880d681SAndroid Build Coastguard Worker store void (i32, i64, i32, i64, i32, i64, i32, i64, i32, i64)* @ten_params, void (i32, i64, i32, i64, i32, i64, i32, i64, i32, i64)** %stack_fptr 141*9880d681SAndroid Build Coastguard Worker %ten_params_ptr = load volatile void (i32, i64, i32, i64, i32, i64, i32, i64, i32, i64)*, void (i32, i64, i32, i64, i32, i64, i32, i64, i32, i64)** %stack_fptr 142*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "nop", "~{ax},~{bx},~{cx},~{dx},~{bp},~{si},~{di},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15}"() 143*9880d681SAndroid Build Coastguard Worker call void (i32, i64, i32, i64, i32, i64, i32, i64, i32, i64) %ten_params_ptr(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7, i64 %p7, i32 9, i64 %p8) 144*9880d681SAndroid Build Coastguard Worker ret void 145*9880d681SAndroid Build Coastguard Worker} 146*9880d681SAndroid Build Coastguard Worker 147*9880d681SAndroid Build Coastguard Worker; We can't fold the load from the global into the push because of 148*9880d681SAndroid Build Coastguard Worker; interference from the store 149*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test8 150*9880d681SAndroid Build Coastguard Worker; NORMAL: movq the_global(%rip), [[REG:%r.+]] 151*9880d681SAndroid Build Coastguard Worker; NORMAL: movq $42, the_global 152*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $10 153*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $9 154*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq [[REG]] 155*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $7 156*9880d681SAndroid Build Coastguard Worker; NORMAL: callq ten_params 157*9880d681SAndroid Build Coastguard Worker@the_global = external global i64 158*9880d681SAndroid Build Coastguard Workerdefine void @test8() { 159*9880d681SAndroid Build Coastguard Worker %myload = load i64, i64* @the_global 160*9880d681SAndroid Build Coastguard Worker store i64 42, i64* @the_global 161*9880d681SAndroid Build Coastguard Worker call void @ten_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7, i64 %myload, i32 9, i64 10) 162*9880d681SAndroid Build Coastguard Worker ret void 163*9880d681SAndroid Build Coastguard Worker} 164*9880d681SAndroid Build Coastguard Worker 165*9880d681SAndroid Build Coastguard Worker 166*9880d681SAndroid Build Coastguard Worker; Converting one function call to use pushes negatively affects 167*9880d681SAndroid Build Coastguard Worker; other calls that pass arguments on the stack without pushes. 168*9880d681SAndroid Build Coastguard Worker; If the cost outweighs the benefit, avoid using pushes. 169*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test9 170*9880d681SAndroid Build Coastguard Worker; NORMAL: callq cannot_push 171*9880d681SAndroid Build Coastguard Worker; NORMAL-NOT: push 172*9880d681SAndroid Build Coastguard Worker; NORMAL: callq ten_params 173*9880d681SAndroid Build Coastguard Workerdefine void @test9(float %p1) { 174*9880d681SAndroid Build Coastguard Worker call void @cannot_push(float 1.0e0, float 2.0e0, float 3.0e0, float 4.0e0, float 5.0e0, float 6.0e0, float 7.0e0, float 8.0e0, float %p1) 175*9880d681SAndroid Build Coastguard Worker call void @ten_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7, i64 8, i32 9, i64 10) 176*9880d681SAndroid Build Coastguard Worker call void @cannot_push(float 1.0e0, float 2.0e0, float 3.0e0, float 4.0e0, float 5.0e0, float 6.0e0, float 7.0e0, float 8.0e0, float %p1) 177*9880d681SAndroid Build Coastguard Worker ret void 178*9880d681SAndroid Build Coastguard Worker} 179*9880d681SAndroid Build Coastguard Worker 180*9880d681SAndroid Build Coastguard Worker; But if the benefit outweighs the cost, use pushes. 181*9880d681SAndroid Build Coastguard Worker; NORMAL-LABEL: test10 182*9880d681SAndroid Build Coastguard Worker; NORMAL: callq cannot_push 183*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $10 184*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $9 185*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $8 186*9880d681SAndroid Build Coastguard Worker; NORMAL: pushq $7 187*9880d681SAndroid Build Coastguard Worker; NORMAL: callq ten_params 188*9880d681SAndroid Build Coastguard Workerdefine void @test10(float %p1) { 189*9880d681SAndroid Build Coastguard Worker call void @ten_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7, i64 8, i32 9, i64 10) 190*9880d681SAndroid Build Coastguard Worker call void @cannot_push(float 1.0e0, float 2.0e0, float 3.0e0, float 4.0e0, float 5.0e0, float 6.0e0, float 7.0e0, float 8.0e0, float %p1) 191*9880d681SAndroid Build Coastguard Worker call void @ten_params(i32 1, i64 2, i32 3, i64 4, i32 5, i64 6, i32 7, i64 8, i32 9, i64 10) 192*9880d681SAndroid Build Coastguard Worker ret void 193*9880d681SAndroid Build Coastguard Worker} 194