Home | History | Annotate | Download | only in X86
      1 ; RUN: llc -verify-machineinstrs -stack-symbol-ordering=0 < %s | FileCheck %s
      2 
      3 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
      4 target triple = "x86_64-pc-linux-gnu"
      5 
      6 ; This test is checking to make sure that we reuse the same stack slots
      7 ; for GC values spilled over two different call sites.  Since the order
      8 ; of GC arguments differ, niave lowering code would insert loads and 
      9 ; stores to rearrange items on the stack.  We need to make sure (for
     10 ; performance) that this doesn't happen.
     11 define i32 @back_to_back_calls(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c) #1 gc "statepoint-example" {
     12 ; CHECK-LABEL: back_to_back_calls
     13 ; The exact stores don't matter, but there need to be three stack slots created
     14 ; CHECK-DAG: movq	%rdi, 16(%rsp)
     15 ; CHECK-DAG: movq	%rdx, 8(%rsp)
     16 ; CHECK-DAG: movq	%rsi, (%rsp)
     17 ; There should be no more than three moves
     18 ; CHECK-NOT: movq
     19   %safepoint_token = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c)
     20   %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 12)
     21   %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 13)
     22   %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 14)
     23 ; CHECK: callq
     24 ; This is the key check.  There should NOT be any memory moves here
     25 ; CHECK-NOT: movq
     26   %safepoint_token2 = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 addrspace(1)* %c1, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1)
     27   %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 12, i32 14)
     28   %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 12, i32 13)
     29   %c2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 12, i32 12)
     30 ; CHECK: callq
     31   ret i32 1
     32 }
     33 
     34 ; This test simply checks that minor changes in vm state don't prevent slots
     35 ; being reused for gc values.  
     36 define i32 @reserve_first(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c) #1 gc "statepoint-example" {
     37 ; CHECK-LABEL: reserve_first
     38 ; The exact stores don't matter, but there need to be three stack slots created
     39 ; CHECK-DAG: movq	%rdi, 16(%rsp)
     40 ; CHECK-DAG: movq	%rdx, 8(%rsp)
     41 ; CHECK-DAG: movq	%rsi, (%rsp)
     42   %safepoint_token = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c)
     43   %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 12)
     44   %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 13)
     45   %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 14)
     46 ; CHECK: callq
     47 ; This is the key check.  There should NOT be any memory moves here
     48 ; CHECK-NOT: movq
     49   %safepoint_token2 = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 addrspace(1)* %a1, i32 0, i32 addrspace(1)* %c1, i32 0, i32 0, i32 addrspace(1)* %c1, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1)
     50   %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 12, i32 14)
     51   %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 12, i32 13)
     52   %c2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 12, i32 12)
     53 ; CHECK: callq
     54   ret i32 1
     55 }
     56 
     57 ; Check that we reuse the same stack slot across multiple calls.  The use of
     58 ; more than two calls here is critical.  We've had a bug which allowed reuse
     59 ; exactly once which went undetected for a long time.
     60 define i32 @back_to_back_deopt(i32 %a, i32 %b, i32 %c) #1 
     61   gc "statepoint-example" {
     62 ; CHECK-LABEL: back_to_back_deopt
     63 ; The exact stores don't matter, but there need to be three stack slots created
     64 ; CHECK-DAG: movl	%edi, 12(%rsp)
     65 ; CHECK-DAG: movl	%esi, 8(%rsp)
     66 ; CHECK-DAG: movl	%edx, 4(%rsp)
     67 ; CHECK: callq
     68 ; CHECK-DAG: movl	%ebx, 12(%rsp)
     69 ; CHECK-DAG: movl	%ebp, 8(%rsp)
     70 ; CHECK-DAG: movl	%r14d, 4(%rsp)
     71 ; CHECK: callq
     72 ; CHECK-DAG: movl	%ebx, 12(%rsp)
     73 ; CHECK-DAG: movl	%ebp, 8(%rsp)
     74 ; CHECK-DAG: movl	%r14d, 4(%rsp)
     75 ; CHECK: callq
     76 ; CHECK-DAG: movl	%ebx, 12(%rsp)
     77 ; CHECK-DAG: movl	%ebp, 8(%rsp)
     78 ; CHECK-DAG: movl	%r14d, 4(%rsp)
     79 ; CHECK: callq
     80   call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 3, i32 %a, i32 %b, i32 %c)
     81 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 3, i32 %a, i32 %b, i32 %c)
     82 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 3, i32 %a, i32 %b, i32 %c)
     83 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 3, i32 %a, i32 %b, i32 %c)
     84   ret i32 1
     85 }
     86 
     87 ; Test that stack slots are reused for invokes
     88 define i32 @back_to_back_invokes(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c) #1 gc "statepoint-example" personality i32 ()* @"personality_function" {
     89 ; CHECK-LABEL: back_to_back_invokes
     90 entry:
     91   ; The exact stores don't matter, but there need to be three stack slots created
     92   ; CHECK-DAG: movq	%rdi, 16(%rsp)
     93   ; CHECK-DAG: movq	%rdx, 8(%rsp)
     94   ; CHECK-DAG: movq	%rsi, (%rsp)
     95   ; CHECK: callq
     96   %safepoint_token = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c)
     97                    to label %normal_return unwind label %exceptional_return
     98 
     99 normal_return:
    100   %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 12)
    101   %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 13)
    102   %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 12, i32 14)
    103   ; Should work even through bitcasts
    104   %c1.casted = bitcast i32 addrspace(1)* %c1 to i8 addrspace(1)*
    105   ; This is the key check.  There should NOT be any memory moves here
    106   ; CHECK-NOT: movq
    107   ; CHECK: callq
    108   %safepoint_token2 = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i8 addrspace(1)* %c1.casted, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1)
    109                     to label %normal_return2 unwind label %exceptional_return2
    110 
    111 normal_return2:
    112   %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 12, i32 14)
    113   %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 12, i32 13)
    114   %c2 = tail call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token2, i32 12, i32 12)
    115   ret i32 1
    116 
    117 exceptional_return:
    118   %landing_pad = landingpad { i8*, i32 }
    119           cleanup
    120   ret i32 0
    121 
    122 exceptional_return2:
    123   %landing_pad2 = landingpad { i8*, i32 }
    124           cleanup
    125   ret i32 0
    126 }
    127 
    128 ; Function Attrs: nounwind
    129 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32) #3
    130 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32) #3
    131 
    132 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
    133 
    134 declare i32 @"personality_function"()
    135 
    136 attributes #1 = { uwtable }
    137