1; RUN: llc                             < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
2; RUN: llc -fast-isel -fast-isel-abort=1 < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
3; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu                             < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-LE
4; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -fast-isel -fast-isel-abort=1 < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-LE
5
6target triple = "powerpc64-unknown-linux-gnu"
7
8; Trivial patchpoint codegen
9;
10define i64 @trivial_patchpoint_codegen(i64 %p1, i64 %p2, i64 %p3, i64 %p4) {
11entry:
12; CHECK-LABEL: trivial_patchpoint_codegen:
13
14; CHECK: li 12, -8531
15; CHECK-NEXT: rldic 12, 12, 32, 16
16; CHECK-NEXT: oris 12, 12, 48879
17; CHECK-NEXT: ori 12, 12, 51966
18; CHECK-NEXT: mtctr 12
19; CHECK-NEXT: bctrl
20
21; CHECK: li 12, -8531
22; CHECK-NEXT: rldic 12, 12, 32, 16
23; CHECK-NEXT: oris 12, 12, 48879
24; CHECK-NEXT: ori 12, 12, 51967
25; CHECK-NEXT: mtctr 12
26; CHECK-NEXT: bctrl
27
28; CHECK: blr
29
30  %resolveCall2 = inttoptr i64 244837814094590 to i8*
31  %result = tail call i64 (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.i64(i64 2, i32 24, i8* %resolveCall2, i32 4, i64 %p1, i64 %p2, i64 %p3, i64 %p4)
32  %resolveCall3 = inttoptr i64 244837814094591 to i8*
33  tail call void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 3, i32 24, i8* %resolveCall3, i32 2, i64 %p1, i64 %result)
34  ret i64 %result
35}
36
37; Caller frame metadata with stackmaps. This should not be optimized
38; as a leaf function.
39;
40; CHECK-LABEL: caller_meta_leaf
41; CHECK-BE: stdu 1, -80(1)
42; CHECK-LE: stdu 1, -64(1)
43; CHECK: Ltmp
44; CHECK-BE: addi 1, 1, 80
45; CHECK-LE: addi 1, 1, 64
46; CHECK: blr
47
48define void @caller_meta_leaf() {
49entry:
50  %metadata = alloca i64, i32 3, align 8
51  store i64 11, i64* %metadata
52  store i64 12, i64* %metadata
53  store i64 13, i64* %metadata
54  call void (i64, i32, ...) @llvm.experimental.stackmap(i64 4, i32 0, i64* %metadata)
55  ret void
56}
57
58; Test patchpoints reusing the same TargetConstant.
59; <rdar:15390785> Assertion failed: (CI.getNumArgOperands() >= NumArgs + 4)
60; There is no way to verify this, since it depends on memory allocation.
61; But I think it's useful to include as a working example.
62define i64 @testLowerConstant(i64 %arg, i64 %tmp2, i64 %tmp10, i64* %tmp33, i64 %tmp79) {
63entry:
64  %tmp80 = add i64 %tmp79, -16
65  %tmp81 = inttoptr i64 %tmp80 to i64*
66  %tmp82 = load i64, i64* %tmp81, align 8
67  tail call void (i64, i32, ...) @llvm.experimental.stackmap(i64 14, i32 8, i64 %arg, i64 %tmp2, i64 %tmp10, i64 %tmp82)
68  tail call void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 15, i32 32, i8* null, i32 3, i64 %arg, i64 %tmp10, i64 %tmp82)
69  %tmp83 = load i64, i64* %tmp33, align 8
70  %tmp84 = add i64 %tmp83, -24
71  %tmp85 = inttoptr i64 %tmp84 to i64*
72  %tmp86 = load i64, i64* %tmp85, align 8
73  tail call void (i64, i32, ...) @llvm.experimental.stackmap(i64 17, i32 8, i64 %arg, i64 %tmp10, i64 %tmp86)
74  tail call void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 18, i32 32, i8* null, i32 3, i64 %arg, i64 %tmp10, i64 %tmp86)
75  ret i64 10
76}
77
78; Test small patchpoints that don't emit calls.
79define void @small_patchpoint_codegen(i64 %p1, i64 %p2, i64 %p3, i64 %p4) {
80entry:
81; CHECK-LABEL: small_patchpoint_codegen:
82; CHECK:      Ltmp
83; CHECK:      nop
84; CHECK-NEXT: nop
85; CHECK-NEXT: nop
86; CHECK-NEXT: nop
87; CHECK-NEXT: nop
88; CHECK-NOT:  nop
89; CHECK: blr
90  %result = tail call i64 (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.i64(i64 5, i32 20, i8* null, i32 2, i64 %p1, i64 %p2)
91  ret void
92}
93
94declare void @llvm.experimental.stackmap(i64, i32, ...)
95declare void @llvm.experimental.patchpoint.void(i64, i32, i8*, i32, ...)
96declare i64 @llvm.experimental.patchpoint.i64(i64, i32, i8*, i32, ...)
97
98