llvm-project/llvm/test/CodeGen/X86/tls-function-argument.ll
Fabian Ritter afa23ea037
[X86] Insert CALLSEQ when lowering GlobalTLSAddress for ELF targets (#113706)
When lowering a TLS address for an ELF target, we introduce a call to
obtain the TLS base address. So far, we do not insert CALLSEQ_START/END
markers around this call when it is generated, but use a custom inserter
to insert them in a later phase. This is problematic, since the TLS
address call can land in a CALLSEQ for another call before it is
wrapped in its own CALLSEQ. That results in nested CALLSEQs, which are
illegal and cause errors when expensive checks are enabled, e.g., in
issues #45574 and #98042.

This patch instead wraps each TLS address call in a CALLSEQ when it is
generated so that instruction selection can avoid nested CALLSEQs. This
is an alternative to PR #106965, which instead changes the custom
inserter to avoid generating CALLSEQs when the TLS address call is
already in a CALLSEQ.

This patch also effectively reverts commit
[228978c](228978c0dc),
which introduced the CustomInserter that so far added the CALLSEQ around
TLSAddrs.

Fixes #45574 and #98042.
2024-11-04 12:41:53 +01:00

31 lines
1.2 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=x86_64 -verify-machineinstrs -relocation-model=pic < %s | FileCheck %s
; Passing a pointer to thread-local storage to a function can be problematic
; since computing such addresses requires a function call that is introduced
; very late in instruction selection. We need to ensure that we don't introduce
; nested call sequence markers if this function call happens in a call sequence.
@TLS = internal thread_local global i64 zeroinitializer, align 8
declare void @bar(ptr)
define internal void @foo() {
; CHECK-LABEL: foo:
; CHECK: # %bb.0:
; CHECK-NEXT: pushq %rbx
; CHECK-NEXT: .cfi_def_cfa_offset 16
; CHECK-NEXT: .cfi_offset %rbx, -16
; CHECK-NEXT: leaq TLS@TLSLD(%rip), %rdi
; CHECK-NEXT: callq __tls_get_addr@PLT
; CHECK-NEXT: leaq TLS@DTPOFF(%rax), %rbx
; CHECK-NEXT: movq %rbx, %rdi
; CHECK-NEXT: callq bar@PLT
; CHECK-NEXT: movq %rbx, %rdi
; CHECK-NEXT: callq bar@PLT
; CHECK-NEXT: popq %rbx
; CHECK-NEXT: .cfi_def_cfa_offset 8
; CHECK-NEXT: retq
call void @bar(ptr @TLS)
call void @bar(ptr @TLS)
ret void
}