llvm-project/llvm/test/CodeGen/X86/asm-modifier.ll
Fangrui Song d926ec35b7
[X86] Asm modifier %a: add (%rip) for 64-bit static relocation model
In GCC,

```
static int a;
int foo() {
  asm("# %a0" : : "i"(&a));
}
```

lowers to `# a(%rip)` regardless of the PIC mode. This PR follow suits
for ELF -fno-pic, matching ELF -fpic (asm-modifier-pic.ll) and Mach-O
(which defaults to PIC).

Close https://github.com/llvm/llvm-project/issues/139001

Pull Request: https://github.com/llvm/llvm-project/pull/139040
2025-05-09 11:54:01 +08:00

89 lines
2.4 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
; RUN: llc -mtriple=i686 < %s | FileCheck %s --check-prefixes=CHECK,X86
; RUN: llc -mtriple=x86_64 < %s | FileCheck %s --check-prefixes=CHECK,X64
;; Certain constraints should not be used for PIC. See asm-modifier-pic.ll for PIC-specific tests.
@var = internal global i32 0, align 4
define dso_local void @test_a() nounwind {
; X86-LABEL: test_a:
; X86: # %bb.0:
; X86-NEXT: #APP
; X86-NEXT: #TEST 42 var#
; X86-NEXT: #NO_APP
; X86-NEXT: retl
;
; X64-LABEL: test_a:
; X64: # %bb.0:
; X64-NEXT: #APP
; X64-NEXT: #TEST 42 var(%rip)#
; X64-NEXT: #NO_APP
; X64-NEXT: retq
tail call void asm sideeffect "#TEST ${0:a} ${1:a}#", "i,i"(i32 42, ptr @var)
ret void
}
define dso_local void @test_c() nounwind {
; CHECK-LABEL: test_c:
; CHECK: # %bb.0:
; CHECK-NEXT: #APP
; CHECK-NEXT: #TEST 42 var#
; CHECK-NEXT: #NO_APP
; CHECK-NEXT: ret{{[l|q]}}
tail call void asm sideeffect "#TEST ${0:c} ${1:c}#", "i,i"(i32 42, ptr @var)
ret void
}
define dso_local void @test_k() nounwind {
; CHECK-LABEL: test_k:
; CHECK: # %bb.0:
; CHECK-NEXT: #APP
; CHECK-NEXT: movl %fs:0, %eax
; CHECK-NEXT: #NO_APP
%tmp = tail call i64 asm "movl %fs:${1:a}, ${0:k}", "=q,irm,~{dirflag},~{fpsr},~{flags}"(i64 0)
unreachable
}
define dso_local void @test_n() nounwind {
; CHECK-LABEL: test_n:
; CHECK: # %bb.0:
; CHECK-NEXT: #APP
; CHECK-NEXT: #TEST 37
; CHECK-NEXT: #NO_APP
; CHECK-NEXT: ret{{[l|q]}}
tail call void asm sideeffect "#TEST ${0:n}", "i"(i32 -37)
ret void
}
define void @test_q() {
; CHECK-LABEL: test_q:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: #APP
; CHECK-NEXT: #TEST 0
; CHECK-NEXT: #NO_APP
; CHECK-NEXT: ret{{[l|q]}}
entry:
call void asm sideeffect "#TEST ${0:q}", "=*imr"( ptr elementtype( i64) null )
ret void
}
define void @test_V(ptr %p) {
; X86-LABEL: test_V:
; X86: # %bb.0: # %entry
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: #APP
; X86-NEXT: calll __x86_indirect_thunk_eax
; X86-NEXT: #NO_APP
; X86-NEXT: retl
;
; X64-LABEL: test_V:
; X64: # %bb.0: # %entry
; X64-NEXT: #APP
; X64-NEXT: callq __x86_indirect_thunk_rdi
; X64-NEXT: #NO_APP
; X64-NEXT: retq
entry:
tail call void asm sideeffect "call __x86_indirect_thunk_${0:V}", "r,~{dirflag},~{fpsr},~{flags}"(ptr %p)
ret void
}