xref: /aosp_15_r20/external/llvm/test/CodeGen/PowerPC/ppc64-calls.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=ppc64 -mcpu=pwr7 | FileCheck %s
2*9880d681SAndroid Build Coastguard Workertarget 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"
3*9880d681SAndroid Build Coastguard Workertarget triple = "powerpc64-unknown-linux-gnu"
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workerdefine void @foo() nounwind noinline {
7*9880d681SAndroid Build Coastguard Worker  ret void
8*9880d681SAndroid Build Coastguard Worker}
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Workerdefine weak void @foo_weak() nounwind {
11*9880d681SAndroid Build Coastguard Worker  ret void
12*9880d681SAndroid Build Coastguard Worker}
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker; Calls to local function does not require the TOC restore 'nop'
15*9880d681SAndroid Build Coastguard Workerdefine void @test_direct() nounwind readnone {
16*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_direct:
17*9880d681SAndroid Build Coastguard Worker  tail call void @foo() nounwind
18*9880d681SAndroid Build Coastguard Worker; Because of tail call optimization, it can be 'b' instruction.
19*9880d681SAndroid Build Coastguard Worker; CHECK: [[BR:b[l]?]] foo
20*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: nop
21*9880d681SAndroid Build Coastguard Worker  ret void
22*9880d681SAndroid Build Coastguard Worker}
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker; Calls to weak function requires a TOC restore 'nop' because they
25*9880d681SAndroid Build Coastguard Worker; may be overridden in a different module.
26*9880d681SAndroid Build Coastguard Workerdefine void @test_weak() nounwind readnone {
27*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_weak:
28*9880d681SAndroid Build Coastguard Worker  tail call void @foo_weak() nounwind
29*9880d681SAndroid Build Coastguard Worker; CHECK: bl foo
30*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: nop
31*9880d681SAndroid Build Coastguard Worker  ret void
32*9880d681SAndroid Build Coastguard Worker}
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Worker; Indirect calls requires a full stub creation
35*9880d681SAndroid Build Coastguard Workerdefine void @test_indirect(void ()* nocapture %fp) nounwind {
36*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_indirect:
37*9880d681SAndroid Build Coastguard Worker  tail call void %fp() nounwind
38*9880d681SAndroid Build Coastguard Worker; CHECK: ld [[FP:[0-9]+]], 0(3)
39*9880d681SAndroid Build Coastguard Worker; CHECK: ld 11, 16(3)
40*9880d681SAndroid Build Coastguard Worker; CHECK: ld 2, 8(3)
41*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: mtctr [[FP]]
42*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bctrl
43*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ld 2, 40(1)
44*9880d681SAndroid Build Coastguard Worker  ret void
45*9880d681SAndroid Build Coastguard Worker}
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker; Absolute values must use the regular indirect call sequence
48*9880d681SAndroid Build Coastguard Worker; The main purpose of this test is to ensure that BLA is not
49*9880d681SAndroid Build Coastguard Worker; used on 64-bit SVR4 (as e.g. on Darwin).
50*9880d681SAndroid Build Coastguard Workerdefine void @test_abs() nounwind {
51*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_abs:
52*9880d681SAndroid Build Coastguard Worker  tail call void inttoptr (i64 1024 to void ()*)() nounwind
53*9880d681SAndroid Build Coastguard Worker; CHECK: ld [[FP:[0-9]+]], 1024(0)
54*9880d681SAndroid Build Coastguard Worker; CHECK: ld 11, 1040(0)
55*9880d681SAndroid Build Coastguard Worker; CHECK: ld 2, 1032(0)
56*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: mtctr [[FP]]
57*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bctrl
58*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ld 2, 40(1)
59*9880d681SAndroid Build Coastguard Worker  ret void
60*9880d681SAndroid Build Coastguard Worker}
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Workerdeclare double @sin(double) nounwind
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Worker; External functions call should also have a 'nop'
65*9880d681SAndroid Build Coastguard Workerdefine double @test_external(double %x) nounwind {
66*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_external:
67*9880d681SAndroid Build Coastguard Worker  %call = tail call double @sin(double %x) nounwind
68*9880d681SAndroid Build Coastguard Worker; CHECK: bl sin
69*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: nop
70*9880d681SAndroid Build Coastguard Worker  ret double %call
71*9880d681SAndroid Build Coastguard Worker}
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Worker; The 'ld 2, 40(1)' really must always come directly after the bctrl to make
74*9880d681SAndroid Build Coastguard Worker; the unwinding code in libgcc happy.
75*9880d681SAndroid Build Coastguard Worker@g = external global void ()*
76*9880d681SAndroid Build Coastguard Workerdeclare void @h(i64)
77*9880d681SAndroid Build Coastguard Workerdefine void @test_indir_toc_reload(i64 %x) {
78*9880d681SAndroid Build Coastguard Worker  %1 = load void ()*, void ()** @g
79*9880d681SAndroid Build Coastguard Worker  call void %1()
80*9880d681SAndroid Build Coastguard Worker  call void @h(i64 %x)
81*9880d681SAndroid Build Coastguard Worker  ret void
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_indir_toc_reload
84*9880d681SAndroid Build Coastguard Worker; CHECK: bctrl
85*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ld 2, 40(1)
86*9880d681SAndroid Build Coastguard Worker; CHECK: blr
87*9880d681SAndroid Build Coastguard Worker}
88*9880d681SAndroid Build Coastguard Worker
89