Skip to content

Commit bc08104

Browse files
cuvipertru
authored andcommitted
[PowerPC] Indicate that PPC32PICGOT clobbers LR (llvm#154654)
This pseudo-instruction emits a local `bl` writing LR, so that must be saved and restored for the function to return to the right place. If not, we'll return to the inline `.long` that the `bl` stepped over. This fixes the `SIGILL` seen in rayon-rs/rayon#1268. (cherry picked from commit e6ae4e6)
1 parent 3e406bb commit bc08104

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

llvm/lib/Target/PowerPC/PPCInstrInfo.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3252,7 +3252,8 @@ def PPC32GOT: PPCEmitTimePseudo<(outs gprc:$rD), (ins), "#PPC32GOT",
32523252

32533253
// Get the _GLOBAL_OFFSET_TABLE_ in PIC mode.
32543254
// This uses two output registers, the first as the real output, the second as a
3255-
// temporary register, used internally in code generation.
3255+
// temporary register, used internally in code generation. A "bl" also clobbers LR.
3256+
let Defs = [LR] in
32563257
def PPC32PICGOT: PPCEmitTimePseudo<(outs gprc:$rD, gprc:$rT), (ins), "#PPC32PICGOT",
32573258
[]>, NoEncode<"$rT">;
32583259

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc -verify-machineinstrs -relocation-model=pic < %s | FileCheck %s
2+
3+
target triple = "powerpc-unknown-linux-gnu"
4+
5+
; Test that LR is preserved when PPC32PICGOT clobbers it with a local "bl".
6+
7+
@TLS = external thread_local global i8
8+
9+
; CHECK-LABEL: tls_addr:
10+
; CHECK: mflr [[SAVED_REG:[0-9]+]]
11+
12+
; CHECK: bl [[JUMP:\.L[[:alnum:]_]+]]
13+
; CHECK-NEXT: [[OFFSET:\.L[[:alnum:]_]+]]:
14+
; CHECK-NEXT: .long _GLOBAL_OFFSET_TABLE_-[[OFFSET]]
15+
; CHECK-NEXT: [[JUMP]]
16+
; CHECK-NEXT: mflr {{[0-9]+}}
17+
18+
; CHECK: mtlr [[SAVED_REG]]
19+
; CHECK-NEXT: blr
20+
21+
define ptr @tls_addr() unnamed_addr {
22+
%1 = call ptr @llvm.threadlocal.address.p0(ptr @TLS)
23+
ret ptr %1
24+
}
25+
26+
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull)
27+
28+
!llvm.module.flags = !{!0, !1}
29+
30+
!0 = !{i32 8, !"PIC Level", i32 2}
31+
!1 = !{i32 7, !"PIE Level", i32 2}

0 commit comments

Comments
 (0)