diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/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); } diff --git a/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp b/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp --- a/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp +++ b/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"); diff --git a/llvm/test/CodeGen/AArch64/elf-globals-pic.ll b/llvm/test/CodeGen/AArch64/elf-globals-pic.ll --- a/llvm/test/CodeGen/AArch64/elf-globals-pic.ll +++ b/llvm/test/CodeGen/AArch64/elf-globals-pic.ll @@ -70,3 +70,16 @@ %val = load i64, i64* %addr ret i64 %val } + +@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] +} diff --git a/llvm/test/CodeGen/AArch64/semantic-interposition-asm.ll b/llvm/test/CodeGen/AArch64/semantic-interposition-asm.ll new file mode 100644 --- /dev/null +++ b/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. + +@gv0 = dso_local global i32 0 +@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 +}