| 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 dso_local 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 dso_local 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 all code models |
| 27 |
; because the definition that gets choosen at link time may come from a |
| 28 |
; different compilation unit that was compiled with PC Relative and has no TOC. |
| 29 |
define dso_local void @test_weak() nounwind readnone { |
| 30 |
tail call void @foo_weak() nounwind |
| 31 |
; CHECK-LABEL: test_weak: |
| 32 |
; CHECK: bl foo_weak |
| 33 |
; CHECK-NEXT: nop |
| 34 |
|
| 35 |
; SCM-LABEL: test_weak: |
| 36 |
; SCM: bl foo_weak |
| 37 |
; SCM-NEXT: nop |
| 38 |
ret void |
| 39 |
} |
| 40 |
|
| 41 |
; Indirect calls requires a full stub creation |
| 42 |
define dso_local void @test_indirect(ptr nocapture %fp) nounwind { |
| 43 |
; CHECK-LABEL: test_indirect: |
| 44 |
tail call void %fp() nounwind |
| 45 |
; CHECK: ld 2, 8(3) |
| 46 |
; CHECK: ld 11, 16(3) |
| 47 |
; CHECK: ld [[FP:[0-9]+]], 0(3) |
| 48 |
; CHECK-NEXT: mtctr [[FP]] |
| 49 |
; CHECK-NEXT: bctrl |
| 50 |
; CHECK-NEXT: ld 2, 40(1) |
| 51 |
ret void |
| 52 |
} |
| 53 |
|
| 54 |
; Absolute values must use the regular indirect call sequence |
| 55 |
; The main purpose of this test is to ensure that BLA is not |
| 56 |
; used on 64-bit SVR4 (as e.g. on Darwin). |
| 57 |
define dso_local void @test_abs() nounwind { |
| 58 |
; CHECK-LABEL: test_abs: |
| 59 |
tail call void inttoptr (i64 1024 to ptr)() nounwind |
| 60 |
; CHECK: ld [[FP:[0-9]+]], 1024(0) |
| 61 |
; CHECK: ld 11, 1040(0) |
| 62 |
; CHECK-NEXT: mtctr [[FP]] |
| 63 |
; CHECK: ld 2, 1032(0) |
| 64 |
; CHECK-NEXT: bctrl |
| 65 |
; CHECK-NEXT: ld 2, 40(1) |
| 66 |
ret void |
| 67 |
} |
| 68 |
|
| 69 |
declare double @sin(double) nounwind |
| 70 |
|
| 71 |
; External functions call should also have a 'nop' |
| 72 |
define double @test_external(double %x) nounwind { |
| 73 |
; CHECK-LABEL: test_external: |
| 74 |
%call = tail call double @sin(double %x) nounwind |
| 75 |
; CHECK: bl sin |
| 76 |
; CHECK-NEXT: nop |
| 77 |
ret double %call |
| 78 |
} |
| 79 |
|
| 80 |
; The 'ld 2, 40(1)' really must always come directly after the bctrl to make |
| 81 |
; the unwinding code in libgcc happy. |
| 82 |
@g = external global ptr |
| 83 |
declare void @h(i64) |
| 84 |
define dso_local void @test_indir_toc_reload(i64 %x) { |
| 85 |
%1 = load ptr, ptr @g |
| 86 |
call void %1() |
| 87 |
call void @h(i64 %x) |
| 88 |
ret void |
| 89 |
|
| 90 |
; CHECK-LABEL: @test_indir_toc_reload |
| 91 |
; CHECK: bctrl |
| 92 |
; CHECK-NEXT: ld 2, 40(1) |
| 93 |
; CHECK: blr |
| 94 |
} |
| 95 |
|