1 ; RUN: llc -relocation-model=static -verify-machineinstrs < %s -mcpu=pwr7 | FileCheck %s 2 ; RUN: llc -relocation-model=static -verify-machineinstrs < %s -code-model=small -mcpu=pwr7 | FileCheck %s -check-prefix=SCM 3 4 target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64" 5 target triple = "powerpc64-unknown-linux-gnu" 6 7 8 define void @foo() nounwind noinline { 9 ret void 10 } 11 12 define weak void @foo_weak() nounwind { 13 ret void 14 } 15 16 ; Calls to local function does not require the TOC restore 'nop' 17 define void @test_direct() nounwind readnone { 18 ; CHECK-LABEL: test_direct: 19 tail call void @foo() nounwind 20 ; Because of tail call optimization, it can be 'b' instruction. 21 ; CHECK: [[BR:b[l]?]] foo 22 ; CHECK-NOT: nop 23 ret void 24 } 25 26 ; Calls to weak function requires a TOC restore 'nop' with the small codemodel 27 ; because the definition that gets choosen at link time may come from a 28 ; different section even though we have seen a weak definition in the same 29 ; section at compile time. 30 ; With large and medium codemodels no TOC restore is needed, since we know 31 ; whichever definition is choosen it resides within the same DSO boundaries and 32 ; therefore shares the same TOC. 33 define void @test_weak() nounwind readnone { 34 tail call void @foo_weak() nounwind 35 ; CHECK-LABEL: test_weak: 36 ; CHECK: b foo_weak 37 ; CHECK-NOT: nop 38 39 ; SCM-LABEL: test_weak: 40 ; SCM: bl foo_weak 41 ; SCM-NEXT: nop 42 ret void 43 } 44 45 ; Indirect calls requires a full stub creation 46 define void @test_indirect(void ()* nocapture %fp) nounwind { 47 ; CHECK-LABEL: test_indirect: 48 tail call void %fp() nounwind 49 ; CHECK: ld [[FP:[0-9]+]], 0(3) 50 ; CHECK: ld 11, 16(3) 51 ; CHECK: ld 2, 8(3) 52 ; CHECK-NEXT: mtctr [[FP]] 53 ; CHECK-NEXT: bctrl 54 ; CHECK-NEXT: ld 2, 40(1) 55 ret void 56 } 57 58 ; Absolute values must use the regular indirect call sequence 59 ; The main purpose of this test is to ensure that BLA is not 60 ; used on 64-bit SVR4 (as e.g. on Darwin). 61 define void @test_abs() nounwind { 62 ; CHECK-LABEL: test_abs: 63 tail call void inttoptr (i64 1024 to void ()*)() nounwind 64 ; CHECK: ld [[FP:[0-9]+]], 1024(0) 65 ; CHECK: ld 11, 1040(0) 66 ; CHECK: ld 2, 1032(0) 67 ; CHECK-NEXT: mtctr [[FP]] 68 ; CHECK-NEXT: bctrl 69 ; CHECK-NEXT: ld 2, 40(1) 70 ret void 71 } 72 73 declare double @sin(double) nounwind 74 75 ; External functions call should also have a 'nop' 76 define double @test_external(double %x) nounwind { 77 ; CHECK-LABEL: test_external: 78 %call = tail call double @sin(double %x) nounwind 79 ; CHECK: bl sin 80 ; CHECK-NEXT: nop 81 ret double %call 82 } 83 84 ; The 'ld 2, 40(1)' really must always come directly after the bctrl to make 85 ; the unwinding code in libgcc happy. 86 @g = external global void ()* 87 declare void @h(i64) 88 define void @test_indir_toc_reload(i64 %x) { 89 %1 = load void ()*, void ()** @g 90 call void %1() 91 call void @h(i64 %x) 92 ret void 93 94 ; CHECK-LABEL: @test_indir_toc_reload 95 ; CHECK: bctrl 96 ; CHECK-NEXT: ld 2, 40(1) 97 ; CHECK: blr 98 } 99 100