[X86][AsmPrinter] PrintSymbolOperand: prefer to lower ELF MO_GlobalAddress to .Lfoo...
authorFangrui Song <maskray@google.com>
Sat, 15 Feb 2020 19:40:10 +0000 (11:40 -0800)
committerFangrui Song <maskray@google.com>
Sat, 15 Feb 2020 21:45:29 +0000 (13:45 -0800)
llvm/lib/Target/X86/X86AsmPrinter.cpp
llvm/test/CodeGen/X86/semantic-interposition-asm.ll [new file with mode: 0644]

index eeb3d9d..f526e9f 100644 (file)
@@ -124,7 +124,7 @@ void X86AsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
         MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
       GVSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
     else
-      GVSym = getSymbol(GV);
+      GVSym = getSymbolPreferLocal(*GV);
 
     // Handle dllimport linkage.
     if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
diff --git a/llvm/test/CodeGen/X86/semantic-interposition-asm.ll b/llvm/test/CodeGen/X86/semantic-interposition-asm.ll
new file mode 100644 (file)
index 0000000..a9c1895
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: llc -mtriple=x86_64 -relocation-model=pic < %s | FileCheck %s
+
+;; Test that we use the local alias for dso_local globals in inline assembly.
+
+@mxcsr0 = dso_local global i32 0
+@mxcsr1 = dso_preemptable global i32 1
+
+define <2 x double> @foo(<2 x double> %a, <2 x double> %b) {
+; CHECK-LABEL: foo:
+; CHECK:        movq mxcsr1@GOTPCREL(%rip), %rax
+; CHECK:        #APP
+; CHECK-NEXT:   ldmxcsr .Lmxcsr0$local(%rip)
+; CHECK-NEXT:   addpd %xmm1, %xmm0
+; CHECK-NEXT:   ldmxcsr (%rax)
+; CHECK-NEXT:   #NO_APP
+entry:
+  %0 = call <2 x double> asm sideeffect "ldmxcsr $2; addpd $1, $0; ldmxcsr $3",
+         "=x,x,*m,*m,0,~{dirflag},~{fpsr},~{flags}"(
+           <2 x double> %b, i32* nonnull @mxcsr0, i32* nonnull @mxcsr1, <2 x double> %a)
+  ret <2 x double> %0
+}