blob: ef2ec58b1f3e6be3c02ac128cd237ff950ba2c73 [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: llc < %s -mtriple=x86_64-linux -mattr=+slow-indirect-call | FileCheck %s --check-prefix=SLOW
; RUN: llc < %s -mtriple=x86_64-linux -mattr=-slow-indirect-call | FileCheck %s --check-prefix=NON-SLOW
; RUN: llc < %s -mtriple=x86_64-linux -mcpu=znver5 | FileCheck %s --check-prefix=SLOW
; RUN: llc < %s -mtriple=x86_64-linux -mcpu=znver4 | FileCheck %s --check-prefix=NON-SLOW
; RUN: llc < %s -mtriple=x86_64-linux -mcpu=znver6 | FileCheck %s --check-prefix=NON-SLOW
; RUN: llc < %s -mtriple=i686-linux -mattr=+slow-indirect-call | FileCheck %s --check-prefix=SLOW32
; RUN: llc < %s -mtriple=i686-linux -mattr=-slow-indirect-call | FileCheck %s --check-prefix=NON-SLOW32
@vtable = external dso_local global ptr
; Indirect call through a global function pointer. With slow-indirect-call the
; load must not be folded into the call.
define i32 @test_call_global() nounwind {
; SLOW-LABEL: test_call_global:
; SLOW: # %bb.0:
; SLOW-NEXT: pushq %rax
; SLOW-NEXT: movq vtable(%rip), %rax
; SLOW-NEXT: movl $42, %edi
; SLOW-NEXT: callq *%rax
; SLOW-NEXT: popq %rcx
; SLOW-NEXT: retq
;
; NON-SLOW-LABEL: test_call_global:
; NON-SLOW: # %bb.0:
; NON-SLOW-NEXT: pushq %rax
; NON-SLOW-NEXT: movl $42, %edi
; NON-SLOW-NEXT: callq *vtable(%rip)
; NON-SLOW-NEXT: popq %rcx
; NON-SLOW-NEXT: retq
;
; SLOW32-LABEL: test_call_global:
; SLOW32: # %bb.0:
; SLOW32-NEXT: subl $12, %esp
; SLOW32-NEXT: movl vtable, %eax
; SLOW32-NEXT: movl $42, (%esp)
; SLOW32-NEXT: calll *%eax
; SLOW32-NEXT: addl $12, %esp
; SLOW32-NEXT: retl
;
; NON-SLOW32-LABEL: test_call_global:
; NON-SLOW32: # %bb.0:
; NON-SLOW32-NEXT: subl $12, %esp
; NON-SLOW32-NEXT: movl $42, (%esp)
; NON-SLOW32-NEXT: calll *vtable
; NON-SLOW32-NEXT: addl $12, %esp
; NON-SLOW32-NEXT: retl
%fp = load ptr, ptr @vtable, align 8
%ret = call i32 %fp(i32 42)
ret i32 %ret
}
; Vtable dispatch: load vtable pointer, load function from vtable, call.
; The second load (vtable slot) must not be folded into the call.
define i32 @test_call_vtable(ptr %obj) nounwind {
; SLOW-LABEL: test_call_vtable:
; SLOW: # %bb.0:
; SLOW-NEXT: pushq %rax
; SLOW-NEXT: movq (%rdi), %rax
; SLOW-NEXT: movq (%rax), %rax
; SLOW-NEXT: callq *%rax
; SLOW-NEXT: popq %rcx
; SLOW-NEXT: retq
;
; NON-SLOW-LABEL: test_call_vtable:
; NON-SLOW: # %bb.0:
; NON-SLOW-NEXT: pushq %rax
; NON-SLOW-NEXT: movq (%rdi), %rax
; NON-SLOW-NEXT: callq *(%rax)
; NON-SLOW-NEXT: popq %rcx
; NON-SLOW-NEXT: retq
;
; SLOW32-LABEL: test_call_vtable:
; SLOW32: # %bb.0:
; SLOW32-NEXT: subl $12, %esp
; SLOW32-NEXT: movl {{[0-9]+}}(%esp), %eax
; SLOW32-NEXT: movl (%eax), %ecx
; SLOW32-NEXT: movl (%ecx), %ecx
; SLOW32-NEXT: movl %eax, (%esp)
; SLOW32-NEXT: calll *%ecx
; SLOW32-NEXT: addl $12, %esp
; SLOW32-NEXT: retl
;
; NON-SLOW32-LABEL: test_call_vtable:
; NON-SLOW32: # %bb.0:
; NON-SLOW32-NEXT: subl $12, %esp
; NON-SLOW32-NEXT: movl {{[0-9]+}}(%esp), %eax
; NON-SLOW32-NEXT: movl (%eax), %ecx
; NON-SLOW32-NEXT: movl %eax, (%esp)
; NON-SLOW32-NEXT: calll *(%ecx)
; NON-SLOW32-NEXT: addl $12, %esp
; NON-SLOW32-NEXT: retl
%vt = load ptr, ptr %obj, align 8
%fp = load ptr, ptr %vt, align 8
%ret = call i32 %fp(ptr %obj)
ret i32 %ret
}
; With minsize, the load should be folded even with slow-indirect-call.
; The minsize attribute overrides the slow-indirect-call guard during
; register allocation folding.
define i32 @test_call_minsize() nounwind minsize {
; SLOW-LABEL: test_call_minsize:
; SLOW: # %bb.0:
; SLOW-NEXT: pushq %rax
; SLOW-NEXT: pushq $42
; SLOW-NEXT: popq %rdi
; SLOW-NEXT: callq *vtable(%rip)
; SLOW-NEXT: popq %rcx
; SLOW-NEXT: retq
;
; NON-SLOW-LABEL: test_call_minsize:
; NON-SLOW: # %bb.0:
; NON-SLOW-NEXT: pushq %rax
; NON-SLOW-NEXT: pushq $42
; NON-SLOW-NEXT: popq %rdi
; NON-SLOW-NEXT: callq *vtable(%rip)
; NON-SLOW-NEXT: popq %rcx
; NON-SLOW-NEXT: retq
;
; SLOW32-LABEL: test_call_minsize:
; SLOW32: # %bb.0:
; SLOW32-NEXT: subl $12, %esp
; SLOW32-NEXT: movl vtable, %eax
; SLOW32-NEXT: movl $42, (%esp)
; SLOW32-NEXT: calll *%eax
; SLOW32-NEXT: addl $12, %esp
; SLOW32-NEXT: retl
;
; NON-SLOW32-LABEL: test_call_minsize:
; NON-SLOW32: # %bb.0:
; NON-SLOW32-NEXT: subl $12, %esp
; NON-SLOW32-NEXT: movl $42, (%esp)
; NON-SLOW32-NEXT: calll *vtable
; NON-SLOW32-NEXT: addl $12, %esp
; NON-SLOW32-NEXT: retl
%fp = load ptr, ptr @vtable, align 8
%ret = call i32 %fp(i32 42)
ret i32 %ret
}
; Tail calls should not be affected by slow-indirect-call. The load into the
; jump target should still be folded.
define void @test_tail_call(ptr %obj) nounwind {
; SLOW-LABEL: test_tail_call:
; SLOW: # %bb.0:
; SLOW-NEXT: movq (%rdi), %rax
; SLOW-NEXT: jmpq *(%rax) # TAILCALL
;
; NON-SLOW-LABEL: test_tail_call:
; NON-SLOW: # %bb.0:
; NON-SLOW-NEXT: movq (%rdi), %rax
; NON-SLOW-NEXT: jmpq *(%rax) # TAILCALL
;
; SLOW32-LABEL: test_tail_call:
; SLOW32: # %bb.0:
; SLOW32-NEXT: movl {{[0-9]+}}(%esp), %eax
; SLOW32-NEXT: movl (%eax), %eax
; SLOW32-NEXT: jmpl *(%eax) # TAILCALL
;
; NON-SLOW32-LABEL: test_tail_call:
; NON-SLOW32: # %bb.0:
; NON-SLOW32-NEXT: movl {{[0-9]+}}(%esp), %eax
; NON-SLOW32-NEXT: movl (%eax), %eax
; NON-SLOW32-NEXT: jmpl *(%eax) # TAILCALL
%vt = load ptr, ptr %obj, align 8
%fp = load ptr, ptr %vt, align 8
musttail call void %fp(ptr %obj)
ret void
}