1; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py 2; RUN: llc -O0 -mtriple=mipsel-linux-gnu -global-isel -stop-after=irtranslator -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=MIPS32 3; RUN: llc -O0 -mtriple=mipsel-linux-gnu -global-isel -stop-after=irtranslator -relocation-model=pic -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=MIPS32_PIC 4 5declare i32 @f(i32 %a, i32 %b); 6 7define i32 @call_global(i32 %a0, i32 %a1, i32 %x, i32 %y) { 8 ; MIPS32-LABEL: name: call_global 9 ; MIPS32: bb.1.entry: 10 ; MIPS32: liveins: $a0, $a1, $a2, $a3 11 ; MIPS32: [[COPY:%[0-9]+]]:_(s32) = COPY $a0 12 ; MIPS32: [[COPY1:%[0-9]+]]:_(s32) = COPY $a1 13 ; MIPS32: [[COPY2:%[0-9]+]]:_(s32) = COPY $a2 14 ; MIPS32: [[COPY3:%[0-9]+]]:_(s32) = COPY $a3 15 ; MIPS32: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp 16 ; MIPS32: $a0 = COPY [[COPY2]](s32) 17 ; MIPS32: $a1 = COPY [[COPY3]](s32) 18 ; MIPS32: JAL @f, csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $v0 19 ; MIPS32: [[COPY4:%[0-9]+]]:_(s32) = COPY $v0 20 ; MIPS32: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp 21 ; MIPS32: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY4]], [[COPY4]] 22 ; MIPS32: $v0 = COPY [[ADD]](s32) 23 ; MIPS32: RetRA implicit $v0 24 ; MIPS32_PIC-LABEL: name: call_global 25 ; MIPS32_PIC: bb.1.entry: 26 ; MIPS32_PIC: liveins: $a0, $a1, $a2, $a3, $t9, $v0 27 ; MIPS32_PIC: [[ADDu:%[0-9]+]]:gpr32 = ADDu $v0, $t9 28 ; MIPS32_PIC: [[COPY:%[0-9]+]]:_(s32) = COPY $a0 29 ; MIPS32_PIC: [[COPY1:%[0-9]+]]:_(s32) = COPY $a1 30 ; MIPS32_PIC: [[COPY2:%[0-9]+]]:_(s32) = COPY $a2 31 ; MIPS32_PIC: [[COPY3:%[0-9]+]]:_(s32) = COPY $a3 32 ; MIPS32_PIC: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp 33 ; MIPS32_PIC: [[GV:%[0-9]+]]:gpr32(p0) = G_GLOBAL_VALUE target-flags(mips-got-call) @f 34 ; MIPS32_PIC: $a0 = COPY [[COPY2]](s32) 35 ; MIPS32_PIC: $a1 = COPY [[COPY3]](s32) 36 ; MIPS32_PIC: $gp = COPY [[ADDu]] 37 ; MIPS32_PIC: JALRPseudo [[GV]](p0), csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $gp, implicit-def $v0 38 ; MIPS32_PIC: [[COPY4:%[0-9]+]]:_(s32) = COPY $v0 39 ; MIPS32_PIC: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp 40 ; MIPS32_PIC: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY4]], [[COPY4]] 41 ; MIPS32_PIC: $v0 = COPY [[ADD]](s32) 42 ; MIPS32_PIC: RetRA implicit $v0 43entry: 44 %z = call i32 @f(i32 %x, i32 %y) 45 %doublez = add i32 %z, %z 46 ret i32 %doublez 47} 48 49define internal i32 @f_with_local_linkage(i32 %x, i32 %y) { 50 ; MIPS32-LABEL: name: f_with_local_linkage 51 ; MIPS32: bb.1.entry: 52 ; MIPS32: liveins: $a0, $a1 53 ; MIPS32: [[COPY:%[0-9]+]]:_(s32) = COPY $a0 54 ; MIPS32: [[COPY1:%[0-9]+]]:_(s32) = COPY $a1 55 ; MIPS32: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY1]], [[COPY]] 56 ; MIPS32: $v0 = COPY [[ADD]](s32) 57 ; MIPS32: RetRA implicit $v0 58 ; MIPS32_PIC-LABEL: name: f_with_local_linkage 59 ; MIPS32_PIC: bb.1.entry: 60 ; MIPS32_PIC: liveins: $a0, $a1 61 ; MIPS32_PIC: [[COPY:%[0-9]+]]:_(s32) = COPY $a0 62 ; MIPS32_PIC: [[COPY1:%[0-9]+]]:_(s32) = COPY $a1 63 ; MIPS32_PIC: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY1]], [[COPY]] 64 ; MIPS32_PIC: $v0 = COPY [[ADD]](s32) 65 ; MIPS32_PIC: RetRA implicit $v0 66entry: 67 %add = add i32 %y, %x 68 ret i32 %add 69} 70 71define i32 @call_global_with_local_linkage(i32 %a0, i32 %a1, i32 %x, i32 %y) { 72 ; MIPS32-LABEL: name: call_global_with_local_linkage 73 ; MIPS32: bb.1.entry: 74 ; MIPS32: liveins: $a0, $a1, $a2, $a3 75 ; MIPS32: [[COPY:%[0-9]+]]:_(s32) = COPY $a0 76 ; MIPS32: [[COPY1:%[0-9]+]]:_(s32) = COPY $a1 77 ; MIPS32: [[COPY2:%[0-9]+]]:_(s32) = COPY $a2 78 ; MIPS32: [[COPY3:%[0-9]+]]:_(s32) = COPY $a3 79 ; MIPS32: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp 80 ; MIPS32: $a0 = COPY [[COPY2]](s32) 81 ; MIPS32: $a1 = COPY [[COPY3]](s32) 82 ; MIPS32: JAL @f_with_local_linkage, csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $v0 83 ; MIPS32: [[COPY4:%[0-9]+]]:_(s32) = COPY $v0 84 ; MIPS32: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp 85 ; MIPS32: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY4]], [[COPY4]] 86 ; MIPS32: $v0 = COPY [[ADD]](s32) 87 ; MIPS32: RetRA implicit $v0 88 ; MIPS32_PIC-LABEL: name: call_global_with_local_linkage 89 ; MIPS32_PIC: bb.1.entry: 90 ; MIPS32_PIC: liveins: $a0, $a1, $a2, $a3, $t9, $v0 91 ; MIPS32_PIC: [[ADDu:%[0-9]+]]:gpr32 = ADDu $v0, $t9 92 ; MIPS32_PIC: [[COPY:%[0-9]+]]:_(s32) = COPY $a0 93 ; MIPS32_PIC: [[COPY1:%[0-9]+]]:_(s32) = COPY $a1 94 ; MIPS32_PIC: [[COPY2:%[0-9]+]]:_(s32) = COPY $a2 95 ; MIPS32_PIC: [[COPY3:%[0-9]+]]:_(s32) = COPY $a3 96 ; MIPS32_PIC: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp 97 ; MIPS32_PIC: [[GV:%[0-9]+]]:gpr32(p0) = G_GLOBAL_VALUE @f_with_local_linkage 98 ; MIPS32_PIC: $a0 = COPY [[COPY2]](s32) 99 ; MIPS32_PIC: $a1 = COPY [[COPY3]](s32) 100 ; MIPS32_PIC: $gp = COPY [[ADDu]] 101 ; MIPS32_PIC: JALRPseudo [[GV]](p0), csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $gp, implicit-def $v0 102 ; MIPS32_PIC: [[COPY4:%[0-9]+]]:_(s32) = COPY $v0 103 ; MIPS32_PIC: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp 104 ; MIPS32_PIC: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY4]], [[COPY4]] 105 ; MIPS32_PIC: $v0 = COPY [[ADD]](s32) 106 ; MIPS32_PIC: RetRA implicit $v0 107entry: 108 %z = call i32 @f_with_local_linkage(i32 %x, i32 %y) 109 %doublez = add i32 %z, %z 110 ret i32 %doublez 111} 112 113define i32 @call_reg(i32 (i32, i32)* %f_ptr, i32 %x, i32 %y) { 114 ; MIPS32-LABEL: name: call_reg 115 ; MIPS32: bb.1.entry: 116 ; MIPS32: liveins: $a0, $a1, $a2 117 ; MIPS32: [[COPY:%[0-9]+]]:gpr32(p0) = COPY $a0 118 ; MIPS32: [[COPY1:%[0-9]+]]:_(s32) = COPY $a1 119 ; MIPS32: [[COPY2:%[0-9]+]]:_(s32) = COPY $a2 120 ; MIPS32: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp 121 ; MIPS32: $a0 = COPY [[COPY1]](s32) 122 ; MIPS32: $a1 = COPY [[COPY2]](s32) 123 ; MIPS32: JALRPseudo [[COPY]](p0), csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $v0 124 ; MIPS32: [[COPY3:%[0-9]+]]:_(s32) = COPY $v0 125 ; MIPS32: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp 126 ; MIPS32: $v0 = COPY [[COPY3]](s32) 127 ; MIPS32: RetRA implicit $v0 128 ; MIPS32_PIC-LABEL: name: call_reg 129 ; MIPS32_PIC: bb.1.entry: 130 ; MIPS32_PIC: liveins: $a0, $a1, $a2 131 ; MIPS32_PIC: [[COPY:%[0-9]+]]:gpr32(p0) = COPY $a0 132 ; MIPS32_PIC: [[COPY1:%[0-9]+]]:_(s32) = COPY $a1 133 ; MIPS32_PIC: [[COPY2:%[0-9]+]]:_(s32) = COPY $a2 134 ; MIPS32_PIC: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp 135 ; MIPS32_PIC: $a0 = COPY [[COPY1]](s32) 136 ; MIPS32_PIC: $a1 = COPY [[COPY2]](s32) 137 ; MIPS32_PIC: JALRPseudo [[COPY]](p0), csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $v0 138 ; MIPS32_PIC: [[COPY3:%[0-9]+]]:_(s32) = COPY $v0 139 ; MIPS32_PIC: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp 140 ; MIPS32_PIC: $v0 = COPY [[COPY3]](s32) 141 ; MIPS32_PIC: RetRA implicit $v0 142entry: 143 %call = call i32 %f_ptr(i32 %x, i32 %y) 144 ret i32 %call 145} 146 147declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1 immarg) 148 149define void @call_symbol(i8* nocapture readonly %src, i8* nocapture %dest, i32 signext %length) { 150 ; MIPS32-LABEL: name: call_symbol 151 ; MIPS32: bb.1.entry: 152 ; MIPS32: liveins: $a0, $a1, $a2 153 ; MIPS32: [[COPY:%[0-9]+]]:_(p0) = COPY $a0 154 ; MIPS32: [[COPY1:%[0-9]+]]:_(p0) = COPY $a1 155 ; MIPS32: [[COPY2:%[0-9]+]]:_(s32) = COPY $a2 156 ; MIPS32: G_MEMCPY [[COPY1]](p0), [[COPY]](p0), [[COPY2]](s32), 0 :: (store 1 into %ir.dest), (load 1 from %ir.src) 157 ; MIPS32: RetRA 158 ; MIPS32_PIC-LABEL: name: call_symbol 159 ; MIPS32_PIC: bb.1.entry: 160 ; MIPS32_PIC: liveins: $a0, $a1, $a2 161 ; MIPS32_PIC: [[COPY:%[0-9]+]]:_(p0) = COPY $a0 162 ; MIPS32_PIC: [[COPY1:%[0-9]+]]:_(p0) = COPY $a1 163 ; MIPS32_PIC: [[COPY2:%[0-9]+]]:_(s32) = COPY $a2 164 ; MIPS32_PIC: G_MEMCPY [[COPY1]](p0), [[COPY]](p0), [[COPY2]](s32), 0 :: (store 1 into %ir.dest), (load 1 from %ir.src) 165 ; MIPS32_PIC: RetRA 166entry: 167 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %dest, i8* align 1 %src, i32 %length, i1 false) 168 ret void 169} 170 171declare void @f_with_void_ret(); 172 173define void @call_f_with_void_ret() { 174 ; MIPS32-LABEL: name: call_f_with_void_ret 175 ; MIPS32: bb.1.entry: 176 ; MIPS32: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp 177 ; MIPS32: JAL @f_with_void_ret, csr_o32, implicit-def $ra, implicit-def $sp 178 ; MIPS32: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp 179 ; MIPS32: RetRA 180 ; MIPS32_PIC-LABEL: name: call_f_with_void_ret 181 ; MIPS32_PIC: bb.1.entry: 182 ; MIPS32_PIC: liveins: $t9, $v0 183 ; MIPS32_PIC: [[ADDu:%[0-9]+]]:gpr32 = ADDu $v0, $t9 184 ; MIPS32_PIC: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp 185 ; MIPS32_PIC: [[GV:%[0-9]+]]:gpr32(p0) = G_GLOBAL_VALUE target-flags(mips-got-call) @f_with_void_ret 186 ; MIPS32_PIC: $gp = COPY [[ADDu]] 187 ; MIPS32_PIC: JALRPseudo [[GV]](p0), csr_o32, implicit-def $ra, implicit-def $sp, implicit-def $gp 188 ; MIPS32_PIC: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp 189 ; MIPS32_PIC: RetRA 190entry: 191 call void @f_with_void_ret() 192 ret void 193} 194