Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -87,6 +87,7 @@ #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSection.h" +#include "llvm/MC/MCSectionCOFF.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" @@ -2663,6 +2664,26 @@ /// GetCPISymbol - Return the symbol for the specified constant pool entry. MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const { + if (getSubtargetInfo().getTargetTriple().isKnownWindowsMSVCEnvironment()) { + const MachineConstantPoolEntry &CPE = + MF->getConstantPool()->getConstants()[CPID]; + if (!CPE.isMachineConstantPoolEntry() && CPE.getType() && + CPE.getType()->isSized()) { + const DataLayout &DL = MF->getDataLayout(); + SectionKind Kind = CPE.getSectionKind(&DL); + const Constant *C = CPE.Val.ConstVal; + unsigned Align = CPE.Alignment; + if (const MCSectionCOFF *S = dyn_cast( + getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) { + if (MCSymbol *Sym = S->getCOMDATSymbol()) { + if (Sym->isUndefined()) + OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global); + return Sym; + } + } + } + } + const DataLayout &DL = getDataLayout(); return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) + "CPI" + Twine(getFunctionNumber()) + "_" + Index: lib/Target/AArch64/AArch64AsmPrinter.cpp =================================================================== --- lib/Target/AArch64/AArch64AsmPrinter.cpp +++ lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -242,9 +242,7 @@ Twine(getDataLayout().getLinkerPrivateGlobalPrefix()) + "CPI" + Twine(getFunctionNumber()) + "_" + Twine(CPID)); - return OutContext.getOrCreateSymbol( - Twine(getDataLayout().getPrivateGlobalPrefix()) + "CPI" + - Twine(getFunctionNumber()) + "_" + Twine(CPID)); + return AsmPrinter::GetCPISymbol(CPID); } void AArch64AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNum, Index: lib/Target/X86/X86AsmPrinter.h =================================================================== --- lib/Target/X86/X86AsmPrinter.h +++ lib/Target/X86/X86AsmPrinter.h @@ -130,9 +130,6 @@ unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override; - /// Return the symbol for the specified constant pool entry. - MCSymbol *GetCPISymbol(unsigned CPID) const override; - bool doInitialization(Module &M) override { SMShadowTracker.reset(0); SM.reset(); Index: lib/Target/X86/X86AsmPrinter.cpp =================================================================== --- lib/Target/X86/X86AsmPrinter.cpp +++ lib/Target/X86/X86AsmPrinter.cpp @@ -608,29 +608,6 @@ OutStreamer->EmitAssemblerFlag(MCAF_Code16); } -MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const { - if (Subtarget->isTargetKnownWindowsMSVC()) { - const MachineConstantPoolEntry &CPE = - MF->getConstantPool()->getConstants()[CPID]; - if (!CPE.isMachineConstantPoolEntry()) { - const DataLayout &DL = MF->getDataLayout(); - SectionKind Kind = CPE.getSectionKind(&DL); - const Constant *C = CPE.Val.ConstVal; - unsigned Align = CPE.Alignment; - if (const MCSectionCOFF *S = dyn_cast( - getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) { - if (MCSymbol *Sym = S->getCOMDATSymbol()) { - if (Sym->isUndefined()) - OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global); - return Sym; - } - } - } - } - - return AsmPrinter::GetCPISymbol(CPID); -} - static void emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel, MachineModuleInfoImpl::StubValueTy &MCSym) { Index: test/CodeGen/AArch64/win_cst_pool.ll =================================================================== --- test/CodeGen/AArch64/win_cst_pool.ll +++ test/CodeGen/AArch64/win_cst_pool.ll @@ -1,8 +1,19 @@ +; RUN: llc < %s -mtriple=aarch64-win32-msvc | FileCheck %s ; RUN: llc < %s -mtriple=aarch64-win32-gnu | FileCheck -check-prefix=MINGW %s define double @double() { ret double 0x0000000000800000 } +; CHECK: .globl __real@0000000000800000 +; CHECK-NEXT: .section .rdata,"dr",discard,__real@0000000000800000 +; CHECK-NEXT: .p2align 3 +; CHECK-NEXT: __real@0000000000800000: +; CHECK-NEXT: .xword 8388608 +; CHECK: double: +; CHECK: adrp x8, __real@0000000000800000 +; CHECK-NEXT: ldr d0, [x8, __real@0000000000800000] +; CHECK-NEXT: ret + ; MINGW: .section .rdata,"dr" ; MINGW-NEXT: .p2align 3 ; MINGW-NEXT: [[LABEL:\.LC.*]]: