1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc --mtriple=loongarch64 -mattr=+d --code-model=small < %s | \
3 ; RUN: FileCheck --check-prefix=SMALL %s
4 ; RUN: llc --mtriple=loongarch64 -mattr=+d --code-model=medium < %s | \
5 ; RUN: FileCheck --check-prefix=MEDIUM %s
6 ; RUN: llc --mtriple=loongarch64 -mattr=+d --code-model=large < %s | \
7 ; RUN: FileCheck --check-prefix=LARGE %s
9 declare void @llvm.memset.p0.i64(ptr, i8, i64, i1)
10 declare i32 @callee(i32)
12 define i32 @call_globaladdress(i32 %a) nounwind {
13 ; SMALL-LABEL: call_globaladdress:
15 ; SMALL-NEXT: addi.d $sp, $sp, -16
16 ; SMALL-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
17 ; SMALL-NEXT: bl %plt(callee)
18 ; SMALL-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
19 ; SMALL-NEXT: addi.d $sp, $sp, 16
22 ; MEDIUM-LABEL: call_globaladdress:
24 ; MEDIUM-NEXT: addi.d $sp, $sp, -16
25 ; MEDIUM-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
26 ; MEDIUM-NEXT: pcaddu18i $ra, %call36(callee)
27 ; MEDIUM-NEXT: jirl $ra, $ra, 0
28 ; MEDIUM-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
29 ; MEDIUM-NEXT: addi.d $sp, $sp, 16
32 ; LARGE-LABEL: call_globaladdress:
34 ; LARGE-NEXT: addi.d $sp, $sp, -16
35 ; LARGE-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
36 ; LARGE-NEXT: pcalau12i $ra, %got_pc_hi20(callee)
37 ; LARGE-NEXT: addi.d $t8, $zero, %got_pc_lo12(callee)
38 ; LARGE-NEXT: lu32i.d $t8, %got64_pc_lo20(callee)
39 ; LARGE-NEXT: lu52i.d $t8, $t8, %got64_pc_hi12(callee)
40 ; LARGE-NEXT: ldx.d $ra, $t8, $ra
41 ; LARGE-NEXT: jirl $ra, $ra, 0
42 ; LARGE-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
43 ; LARGE-NEXT: addi.d $sp, $sp, 16
45 %1 = call i32 @callee(i32 %a)
49 define void @call_external_sym(ptr %dst) {
50 ; SMALL-LABEL: call_external_sym:
51 ; SMALL: # %bb.0: # %entry
52 ; SMALL-NEXT: addi.d $sp, $sp, -16
53 ; SMALL-NEXT: .cfi_def_cfa_offset 16
54 ; SMALL-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
55 ; SMALL-NEXT: .cfi_offset 1, -8
56 ; SMALL-NEXT: ori $a2, $zero, 1000
57 ; SMALL-NEXT: move $a1, $zero
58 ; SMALL-NEXT: bl %plt(memset)
59 ; SMALL-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
60 ; SMALL-NEXT: addi.d $sp, $sp, 16
63 ; MEDIUM-LABEL: call_external_sym:
64 ; MEDIUM: # %bb.0: # %entry
65 ; MEDIUM-NEXT: addi.d $sp, $sp, -16
66 ; MEDIUM-NEXT: .cfi_def_cfa_offset 16
67 ; MEDIUM-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
68 ; MEDIUM-NEXT: .cfi_offset 1, -8
69 ; MEDIUM-NEXT: ori $a2, $zero, 1000
70 ; MEDIUM-NEXT: move $a1, $zero
71 ; MEDIUM-NEXT: pcaddu18i $ra, %call36(memset)
72 ; MEDIUM-NEXT: jirl $ra, $ra, 0
73 ; MEDIUM-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
74 ; MEDIUM-NEXT: addi.d $sp, $sp, 16
77 ; LARGE-LABEL: call_external_sym:
78 ; LARGE: # %bb.0: # %entry
79 ; LARGE-NEXT: addi.d $sp, $sp, -16
80 ; LARGE-NEXT: .cfi_def_cfa_offset 16
81 ; LARGE-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
82 ; LARGE-NEXT: .cfi_offset 1, -8
83 ; LARGE-NEXT: ori $a2, $zero, 1000
84 ; LARGE-NEXT: move $a1, $zero
85 ; LARGE-NEXT: pcalau12i $ra, %pc_hi20(memset)
86 ; LARGE-NEXT: addi.d $t8, $zero, %pc_lo12(memset)
87 ; LARGE-NEXT: lu32i.d $t8, %pc64_lo20(memset)
88 ; LARGE-NEXT: lu52i.d $t8, $t8, %pc64_hi12(memset)
89 ; LARGE-NEXT: add.d $ra, $t8, $ra
90 ; LARGE-NEXT: jirl $ra, $ra, 0
91 ; LARGE-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
92 ; LARGE-NEXT: addi.d $sp, $sp, 16
95 call void @llvm.memset.p0.i64(ptr %dst, i8 0, i64 1000, i1 false)
99 ;; Tail call with different codemodel.
100 declare i32 @callee_tail(i32 %i)
101 define i32 @caller_tail(i32 %i) nounwind {
102 ; SMALL-LABEL: caller_tail:
103 ; SMALL: # %bb.0: # %entry
104 ; SMALL-NEXT: b %plt(callee_tail)
106 ; MEDIUM-LABEL: caller_tail:
107 ; MEDIUM: # %bb.0: # %entry
108 ; MEDIUM-NEXT: pcaddu18i $t8, %call36(callee_tail)
109 ; MEDIUM-NEXT: jr $t8
111 ; LARGE-LABEL: caller_tail:
112 ; LARGE: # %bb.0: # %entry
113 ; LARGE-NEXT: pcalau12i $t7, %got_pc_hi20(callee_tail)
114 ; LARGE-NEXT: addi.d $t8, $zero, %got_pc_lo12(callee_tail)
115 ; LARGE-NEXT: lu32i.d $t8, %got64_pc_lo20(callee_tail)
116 ; LARGE-NEXT: lu52i.d $t8, $t8, %got64_pc_hi12(callee_tail)
117 ; LARGE-NEXT: ldx.d $t7, $t8, $t7
120 %r = tail call i32 @callee_tail(i32 %i)