Skip to content

Commit cc5d8a4

Browse files
[AArch64] fall back to SDAG for instructions with emulated TLS variables (#129215)
Fixes #126200 At the moment, GlobalISel is missing an implementation for emulated TLS variables. I fixed the issue by falling back to SDAG in this case, as I currently don't have the knowledge to implement it myself. Co-authored-by: Schaller, Sebastian <[email protected]>
1 parent 37374fb commit cc5d8a4

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2960,8 +2960,12 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
29602960
assert(OpFlags == AArch64II::MO_GOT);
29612961
} else {
29622962
GV = I.getOperand(1).getGlobal();
2963-
if (GV->isThreadLocal())
2963+
if (GV->isThreadLocal()) {
2964+
// We don't support instructions with emulated TLS variables yet
2965+
if (TM.useEmulatedTLS())
2966+
return false;
29642967
return selectTLSGlobalValue(I, MRI);
2968+
}
29652969
OpFlags = STI.ClassifyGlobalReference(GV, TM);
29662970
}
29672971

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -emulated-tls -mtriple aarch64-apple-darwin -global-isel -global-isel-abort=2 %s -o - 2>&1 | FileCheck %s
3+
4+
; This file checks that the fallback path for instructions with emulated TLS variables to selection dag works.
5+
6+
; CHECK: warning: Instruction selection used fallback path for main
7+
8+
@x = thread_local global i32 42, align 4
9+
10+
define i32 @main(i32 %argc, ptr %argv) {
11+
; CHECK-LABEL: main:
12+
; CHECK: ; %bb.0: ; %entry
13+
; CHECK-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
14+
; CHECK-NEXT: .cfi_def_cfa_offset 16
15+
; CHECK-NEXT: .cfi_offset w30, -8
16+
; CHECK-NEXT: .cfi_offset w29, -16
17+
; CHECK-NEXT: Lloh0:
18+
; CHECK-NEXT: adrp x0, ___emutls_v.x@PAGE
19+
; CHECK-NEXT: Lloh1:
20+
; CHECK-NEXT: add x0, x0, ___emutls_v.x@PAGEOFF
21+
; CHECK-NEXT: bl ___emutls_get_address
22+
; CHECK-NEXT: ldr w0, [x0]
23+
; CHECK-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
24+
; CHECK-NEXT: ret
25+
; CHECK-NEXT: .loh AdrpAdd Lloh0, Lloh1
26+
entry:
27+
%0 = load i32, ptr @x, align 4
28+
ret i32 %0
29+
}

0 commit comments

Comments
 (0)