pcrel-call-linkage-with-calls.ll 14.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names < %s \
; RUN:   | FileCheck %s --check-prefixes=CHECK-S,CHECK-ALL
; RUN: llc -verify-machineinstrs -target-abi=elfv2 -mtriple=powerpc64-- \
; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names < %s \
; RUN:   | FileCheck %s --check-prefixes=CHECK-S,CHECK-ALL
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
; RUN:   -mcpu=pwr9 -ppc-asm-full-reg-names < %s \
; RUN:   | FileCheck %s --check-prefixes=CHECK-P9,CHECK-ALL

@globalVar = common dso_local local_unnamed_addr global i32 0, align 4
@externGlobalVar = external local_unnamed_addr global i32, align 4
@indirectCall = common dso_local local_unnamed_addr global i32 (i32)* null, align 8

; This funcion needs to remain as noinline.
; The compiler needs to know this function is local but must be forced to call
; it. The only thing we really need to check here is that st_other=0 and
; so we make sure that there is no .localentry.
define dso_local signext i32 @localCall(i32 signext %a) local_unnamed_addr #0 {
; CHECK-ALL-LABEL: localCall:
; CHECK-S-NOT:   .localentry
; CHECK-S:         addi r3, r3, 5
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    blr
entry:
  %add = add nsw i32 %a, 5
  ret i32 %add
}

define dso_local signext i32 @DirectCallLocal1(i32 signext %a, i32 signext %b) local_unnamed_addr {
; CHECK-ALL-LABEL: DirectCallLocal1:
; CHECK-S:         .localentry     DirectCallLocal1
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -32(r1)
; CHECK-S-NEXT:    .cfi_def_cfa_offset 32
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    bl localCall@notoc
; CHECK-S-NEXT:    plwz r4, globalVar@PCREL(0), 1
; CHECK-S-NEXT:    mullw r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 32
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %add = add nsw i32 %b, %a
  %call = tail call signext i32 @localCall(i32 signext %add)
  %0 = load i32, i32* @globalVar, align 4
  %mul = mul nsw i32 %0, %call
  ret i32 %mul
}

define dso_local signext i32 @DirectCallLocal2(i32 signext %a, i32 signext %b) local_unnamed_addr {
; CHECK-ALL-LABEL: DirectCallLocal2:
; CHECK-S:         .localentry     DirectCallLocal2
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -32(r1)
; CHECK-S-NEXT:    .cfi_def_cfa_offset 32
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    bl localCall@notoc
; CHECK-S-NEXT:    pld r4, externGlobalVar@got@pcrel(0), 1
; CHECK-S-NEXT: .Lpcrel:
; CHECK-S-NEXT:    .reloc .Lpcrel-8,R_PPC64_PCREL_OPT,.-(.Lpcrel-8)
; CHECK-S-NEXT:    lwz r4, 0(r4)
; CHECK-S-NEXT:    mullw r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 32
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %add = add nsw i32 %b, %a
  %call = tail call signext i32 @localCall(i32 signext %add)
  %0 = load i32, i32* @externGlobalVar, align 4
  %mul = mul nsw i32 %0, %call
  ret i32 %mul
}

define dso_local signext i32 @DirectCallLocalNoGlobal(i32 signext %a, i32 signext %b) local_unnamed_addr {
; CHECK-ALL-LABEL: DirectCallLocalNoGlobal:
; CHECK-S:         .localentry DirectCallLocalNoGlobal, 1
; CHECK-S-NEXT:    # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    .cfi_def_cfa_offset 48
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    .cfi_offset r30, -16
; CHECK-S-NEXT:    std r30, -16(r1) # 8-byte Folded Spill
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -48(r1)
; CHECK-S-NEXT:    mr r30, r4
; CHECK-S-NEXT:    bl localCall@notoc
; CHECK-S-NEXT:    add r3, r3, r30
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 48
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    ld r30, -16(r1) # 8-byte Folded Reload
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %call = tail call signext i32 @localCall(i32 signext %a)
  %add = add nsw i32 %call, %b
  ret i32 %add
}

define dso_local signext i32 @DirectCallExtern1(i32 signext %a, i32 signext %b) local_unnamed_addr {
; CHECK-ALL-LABEL: DirectCallExtern1:
; CHECK-S:         .localentry     DirectCallExtern1
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -32(r1)
; CHECK-S-NEXT:    .cfi_def_cfa_offset 32
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    bl externCall@notoc
; CHECK-S-NEXT:    plwz r4, globalVar@PCREL(0), 1
; CHECK-S-NEXT:    mullw r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 32
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %add = add nsw i32 %b, %a
  %call = tail call signext i32 @externCall(i32 signext %add)
  %0 = load i32, i32* @globalVar, align 4
  %mul = mul nsw i32 %0, %call
  ret i32 %mul
}

declare signext i32 @externCall(i32 signext) local_unnamed_addr

define dso_local signext i32 @DirectCallExtern2(i32 signext %a, i32 signext %b) local_unnamed_addr {
; CHECK-ALL-LABEL: DirectCallExtern2:
; CHECK-S:         .localentry     DirectCallExtern2
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -32(r1)
; CHECK-S-NEXT:    .cfi_def_cfa_offset 32
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    bl externCall@notoc
; CHECK-S-NEXT:    pld r4, externGlobalVar@got@pcrel(0), 1
; CHECK-S-NEXT:  .Lpcrel0:
; CHECK-S-NEXT:    .reloc .Lpcrel0-8,R_PPC64_PCREL_OPT,.-(.Lpcrel0-8)
; CHECK-S-NEXT:    lwz r4, 0(r4)
; CHECK-S-NEXT:    mullw r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 32
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %add = add nsw i32 %b, %a
  %call = tail call signext i32 @externCall(i32 signext %add)
  %0 = load i32, i32* @externGlobalVar, align 4
  %mul = mul nsw i32 %0, %call
  ret i32 %mul
}

define dso_local signext i32 @DirectCallExternNoGlobal(i32 signext %a, i32 signext %b) local_unnamed_addr {
; CHECK-ALL-LABEL: DirectCallExternNoGlobal:
; CHECK-S:         .localentry DirectCallExternNoGlobal, 1
; CHECK-P9:        .localentry DirectCallExternNoGlobal, .Lfunc_lep6-.Lfunc_gep6
; CHECK-ALL:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    .cfi_def_cfa_offset 48
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    .cfi_offset r30, -16
; CHECK-S-NEXT:    std r30, -16(r1) # 8-byte Folded Spill
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -48(r1)
; CHECK-S-NEXT:    mr r30, r4
; CHECK-S-NEXT:    bl externCall@notoc
; CHECK-S-NEXT:    add r3, r3, r30
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 48
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    ld r30, -16(r1) # 8-byte Folded Reload
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %call = tail call signext i32 @externCall(i32 signext %a)
  %add = add nsw i32 %call, %b
  ret i32 %add
}

define dso_local signext i32 @TailCallLocal1(i32 signext %a) local_unnamed_addr {
; CHECK-ALL-LABEL: TailCallLocal1:
; CHECK-S:         .localentry     TailCallLocal1
; CHECK-S:       # %bb.0: # %entry
; CHECK-S:         plwz r4, globalVar@PCREL(0), 1
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    b localCall@notoc
entry:
  %0 = load i32, i32* @globalVar, align 4
  %add = add nsw i32 %0, %a
  %call = tail call signext i32 @localCall(i32 signext %add)
  ret i32 %call
}

define dso_local signext i32 @TailCallLocal2(i32 signext %a) local_unnamed_addr {
; CHECK-ALL-LABEL: TailCallLocal2:
; CHECK-S:         .localentry     TailCallLocal2
; CHECK-S:       # %bb.0: # %entry
; CHECK-S:         pld r4, externGlobalVar@got@pcrel(0), 1
; CHECK-S-NEXT:  .Lpcrel1:
; CHECK-S-NEXT:    .reloc .Lpcrel1-8,R_PPC64_PCREL_OPT,.-(.Lpcrel1-8)
; CHECK-S-NEXT:    lwz r4, 0(r4)
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    b localCall@notoc
entry:
  %0 = load i32, i32* @externGlobalVar, align 4
  %add = add nsw i32 %0, %a
  %call = tail call signext i32 @localCall(i32 signext %add)
  ret i32 %call
}

define dso_local signext i32 @TailCallLocalNoGlobal(i32 signext %a) local_unnamed_addr {
; CHECK-ALL-LABEL: TailCallLocalNoGlobal:
; CHECK-S:         .localentry TailCallLocalNoGlobal, 1
; CHECK-P9:        .localentry TailCallLocalNoGlobal, .Lfunc_lep9-.Lfunc_gep9
; CHECK-ALL:       # %bb.0: # %entry
; CHECK-S:         b localCall@notoc
entry:
  %call = tail call signext i32 @localCall(i32 signext %a)
  ret i32 %call
}

define dso_local signext i32 @TailCallExtern1(i32 signext %a) local_unnamed_addr {
; CHECK-ALL-LABEL: TailCallExtern1:
; CHECK-S:         .localentry     TailCallExtern1
; CHECK-S:       # %bb.0: # %entry
; CHECK-S:         plwz r4, globalVar@PCREL(0), 1
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    b externCall@notoc
entry:
  %0 = load i32, i32* @globalVar, align 4
  %add = add nsw i32 %0, %a
  %call = tail call signext i32 @externCall(i32 signext %add)
  ret i32 %call
}

define dso_local signext i32 @TailCallExtern2(i32 signext %a) local_unnamed_addr {
; CHECK-ALL-LABEL: TailCallExtern2:
; CHECK-S:         .localentry     TailCallExtern2
; CHECK-S:       # %bb.0: # %entry
; CHECK-S:         pld r4, externGlobalVar@got@pcrel(0), 1
; CHECK-S-NEXT:  .Lpcrel2:
; CHECK-S-NEXT:    .reloc .Lpcrel2-8,R_PPC64_PCREL_OPT,.-(.Lpcrel2-8)
; CHECK-S-NEXT:    lwz r4, 0(r4)
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    b externCall@notoc
entry:
  %0 = load i32, i32* @externGlobalVar, align 4
  %add = add nsw i32 %0, %a
  %call = tail call signext i32 @externCall(i32 signext %add)
  ret i32 %call
}

define dso_local signext i32 @TailCallExternNoGlobal(i32 signext %a) local_unnamed_addr {
; CHECK-ALL-LABEL: TailCallExternNoGlobal:
; CHECK-S:         .localentry TailCallExternNoGlobal, 1
; CHECK-S-NEXT:  # %bb.0: # %entry
; CHECK-S-NEXT:    b externCall@notoc
; CHECK-S-NEXT:    #TC_RETURNd8 externCall@notoc
entry:
  %call = tail call signext i32 @externCall(i32 signext %a)
  ret i32 %call
}

define dso_local signext i32 @IndirectCall1(i32 signext %a, i32 signext %b) local_unnamed_addr {
; CHECK-ALL-LABEL: IndirectCall1:
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -32(r1)
; CHECK-S-NEXT:    .cfi_def_cfa_offset 32
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    pld r12, indirectCall@PCREL(0), 1
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    mtctr r12
; CHECK-S-NEXT:    bctrl
; CHECK-S-NEXT:    plwz r4, globalVar@PCREL(0), 1
; CHECK-S-NEXT:    mullw r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 32
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %add = add nsw i32 %b, %a
  %0 = load i32 (i32)*, i32 (i32)** @indirectCall, align 8
  %call = tail call signext i32 %0(i32 signext %add)
  %1 = load i32, i32* @globalVar, align 4
  %mul = mul nsw i32 %1, %call
  ret i32 %mul
}

define dso_local signext i32 @IndirectCall2(i32 signext %a, i32 signext %b) local_unnamed_addr {
; CHECK-ALL-LABEL: IndirectCall2:
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -32(r1)
; CHECK-S-NEXT:    .cfi_def_cfa_offset 32
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    pld r12, indirectCall@PCREL(0), 1
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    mtctr r12
; CHECK-S-NEXT:    bctrl
; CHECK-S-NEXT:    pld r4, externGlobalVar@got@pcrel(0), 1
; CHECK-S-NEXT:  .Lpcrel3:
; CHECK-S-NEXT:    .reloc .Lpcrel3-8,R_PPC64_PCREL_OPT,.-(.Lpcrel3-8)
; CHECK-S-NEXT:    lwz r4, 0(r4)
; CHECK-S-NEXT:    mullw r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 32
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %add = add nsw i32 %b, %a
  %0 = load i32 (i32)*, i32 (i32)** @indirectCall, align 8
  %call = tail call signext i32 %0(i32 signext %add)
  %1 = load i32, i32* @externGlobalVar, align 4
  %mul = mul nsw i32 %1, %call
  ret i32 %mul
}

define dso_local signext i32 @IndirectCall3(i32 signext %a, i32 signext %b, i32 (i32)* nocapture %call_param) local_unnamed_addr {
; CHECK-ALL-LABEL: IndirectCall3:
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -32(r1)
; CHECK-S-NEXT:    .cfi_def_cfa_offset 32
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    mtctr r5
; CHECK-S-NEXT:    add r3, r4, r3
; CHECK-S-NEXT:    mr r12, r5
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    bctrl
; CHECK-S-NEXT:    plwz r4, globalVar@PCREL(0), 1
; CHECK-S-NEXT:    mullw r3, r4, r3
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 32
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %add = add nsw i32 %b, %a
  %call = tail call signext i32 %call_param(i32 signext %add)
  %0 = load i32, i32* @globalVar, align 4
  %mul = mul nsw i32 %0, %call
  ret i32 %mul
}

define dso_local signext i32 @IndirectCallNoGlobal(i32 signext %a, i32 signext %b, i32 (i32)* nocapture %call_param) local_unnamed_addr {
; CHECK-ALL-LABEL: IndirectCallNoGlobal:
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mflr r0
; CHECK-S-NEXT:    .cfi_def_cfa_offset 48
; CHECK-S-NEXT:    .cfi_offset lr, 16
; CHECK-S-NEXT:    .cfi_offset r30, -16
; CHECK-S-NEXT:    std r30, -16(r1) # 8-byte Folded Spill
; CHECK-S-NEXT:    std r0, 16(r1)
; CHECK-S-NEXT:    stdu r1, -48(r1)
; CHECK-S-NEXT:    mtctr r5
; CHECK-S-NEXT:    mr r12, r5
; CHECK-S-NEXT:    mr r30, r4
; CHECK-S-NEXT:    bctrl
; CHECK-S-NEXT:    add r3, r3, r30
; CHECK-S-NEXT:    extsw r3, r3
; CHECK-S-NEXT:    addi r1, r1, 48
; CHECK-S-NEXT:    ld r0, 16(r1)
; CHECK-S-NEXT:    ld r30, -16(r1) # 8-byte Folded Reload
; CHECK-S-NEXT:    mtlr r0
; CHECK-S-NEXT:    blr
entry:
  %call = tail call signext i32 %call_param(i32 signext %a)
  %add = add nsw i32 %call, %b
  ret i32 %add
}

define dso_local signext i32 @IndirectCallOnly(i32 signext %a, i32 (i32)* nocapture %call_param) local_unnamed_addr {
; CHECK-ALL-LABEL: IndirectCallOnly:
; CHECK-S:       # %bb.0: # %entry
; CHECK-S-NEXT:    mtctr r4
; CHECK-S-NEXT:    mr r12, r4
; CHECK-S-NEXT:    bctr
; CHECK-S-NEXT:    #TC_RETURNr8 ctr
entry:
  %call = tail call signext i32 %call_param(i32 signext %a)
  ret i32 %call
}

attributes #0 = { noinline }