Skip to content

Commit e6ae4e6

Browse files
authored
[PowerPC] Indicate that PPC32PICGOT clobbers LR (#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.
1 parent 94e4ef5 commit e6ae4e6

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
@@ -3235,7 +3235,8 @@ def PPC32GOT: PPCEmitTimePseudo<(outs gprc:$rD), (ins), "#PPC32GOT",
32353235

32363236
// Get the _GLOBAL_OFFSET_TABLE_ in PIC mode.
32373237
// This uses two output registers, the first as the real output, the second as a
3238-
// temporary register, used internally in code generation.
3238+
// temporary register, used internally in code generation. A "bl" also clobbers LR.
3239+
let Defs = [LR] in
32393240
def PPC32PICGOT: PPCEmitTimePseudo<(outs gprc:$rD, gprc:$rT), (ins), "#PPC32PICGOT",
32403241
[]>, NoEncode<"$rT">;
32413242

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)