[PATCH] D101872: [AArch64][ELF] Prefer to lower MC_GlobalAddress operands to .Lfoo$local
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 4 16:43:39 PDT 2021
MaskRay created this revision.
MaskRay added reviewers: dmgreen, efriedma, peter.smith.
Herald added subscribers: danielkiss, pengfei, hiraditya, kristof.beyls.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Similar to X86 D73230 <https://reviews.llvm.org/D73230> & 46788a21f9152be3950e57dc526454655682bdd4 <https://reviews.llvm.org/rG46788a21f9152be3950e57dc526454655682bdd4>
With this change, we can set dso_local in clang's -fpic -fno-semantic-interposition mode,
for default visibility external linkage non-ifunc-non-COMDAT definitions.
Note: the 'S' inline assembly constraint refers to an absolute symbolic address
or a label reference (D46745 <https://reviews.llvm.org/D46745>).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101872
Files:
llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
llvm/test/CodeGen/AArch64/elf-globals-pic.ll
llvm/test/CodeGen/AArch64/semantic-interposition-asm.ll
Index: llvm/test/CodeGen/AArch64/semantic-interposition-asm.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/semantic-interposition-asm.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64 -relocation-model=pic < %s | FileCheck %s
+
+;; Test that we use the local alias for dso_local globals in inline assembly.
+
+ at gv0 = dso_local global i32 0
+ at gv1 = dso_preemptable global i32 1
+
+define i32 @load() nounwind {
+; CHECK-LABEL: load:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: //APP
+; CHECK-NEXT: adrp x0, .Lgv0$local
+; CHECK-NEXT: ldr w0, [x0, :lo12:.Lgv0$local]
+; CHECK-NEXT: adrp x8, gv1
+; CHECK-NEXT: ldr w8, [x8, :lo12:gv1]
+; CHECK-NEXT: add x0, x8, x0
+; CHECK-NEXT: //NO_APP
+; CHECK-NEXT: // kill: def $w0 killed $w0 killed $x0
+; CHECK-NEXT: ret
+entry:
+ %0 = tail call i64 asm "adrp $0, $1\0Aldr ${0:w}, [$0, :lo12:$1]\0Aadrp x8, $2\0Aldr w8, [x8, :lo12:$2]\0Aadd $0,x8,$0", "=r,S,S,~{x8}"(i32* nonnull @gv0, i32* nonnull @gv1)
+ %conv = trunc i64 %0 to i32
+ ret i32 %conv
+}
Index: llvm/test/CodeGen/AArch64/elf-globals-pic.ll
===================================================================
--- llvm/test/CodeGen/AArch64/elf-globals-pic.ll
+++ llvm/test/CodeGen/AArch64/elf-globals-pic.ll
@@ -70,3 +70,16 @@
%val = load i64, i64* %addr
ret i64 %val
}
+
+ at var_dsolocal = dso_local global i64 0, align 8
+
+define i64 @test_dsolocal(i64 %new) nounwind {
+ %val = load i64, i64* @var_dsolocal, align 8
+ store i64 %new, i64* @var_dsolocal
+ ret i64 %val
+; CHECK-PIC-LABEL: test_dsolocal:
+; CHECK-PIC-NEXT: // %bb.0:
+; CHECK-PIC-NEXT: adrp {{x[0-9]+}}, .Lvar_dsolocal$local
+; CHECK-PIC-NEXT: ldr {{x[0-9]+}}, [{{x[0-9]+}}, :lo12:.Lvar_dsolocal$local]
+; CHECK-PIC-NEXT: str x0, [{{x[0-9]+}}, :lo12:.Lvar_dsolocal$local]
+}
Index: llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
+++ llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
@@ -39,7 +39,7 @@
unsigned TargetFlags = MO.getTargetFlags();
const Triple &TheTriple = Printer.TM.getTargetTriple();
if (!TheTriple.isOSBinFormatCOFF())
- return Printer.getSymbol(GV);
+ return Printer.getSymbolPreferLocal(*GV);
assert(TheTriple.isOSWindows() &&
"Windows is the only supported COFF target");
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -589,7 +589,7 @@
void AsmPrinter::PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS) {
assert(MO.isGlobal() && "caller should check MO.isGlobal");
- getSymbol(MO.getGlobal())->print(OS, MAI);
+ getSymbolPreferLocal(*MO.getGlobal())->print(OS, MAI);
printOffset(MO.getOffset(), OS);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101872.342907.patch
Type: text/x-patch
Size: 3062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210504/03d3dab2/attachment.bin>
More information about the llvm-commits
mailing list