Index: llvm/include/llvm/MC/MCAsmInfo.h =================================================================== --- llvm/include/llvm/MC/MCAsmInfo.h +++ llvm/include/llvm/MC/MCAsmInfo.h @@ -482,6 +482,10 @@ /// For example, foo(plt) instead of foo@plt. Defaults to false. bool UseParensForSymbolVariant = false; + /// True if the target uses parens for symbol names starting with + /// '$' character to distinguish them from absolute names. + bool UseParensForDollarSignNames = true; + /// True if the target supports flags in ".loc" directive, false if only /// location is allowed. bool SupportsExtendedDwarfLocDirective = true; @@ -792,6 +796,9 @@ bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; } bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; } bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; } + bool useParensForDollarSignNames() const { + return UseParensForDollarSignNames; + } bool supportsExtendedDwarfLocDirective() const { return SupportsExtendedDwarfLocDirective; } Index: llvm/lib/MC/MCExpr.cpp =================================================================== --- llvm/lib/MC/MCExpr.cpp +++ llvm/lib/MC/MCExpr.cpp @@ -73,10 +73,15 @@ case MCExpr::SymbolRef: { const MCSymbolRefExpr &SRE = cast(*this); const MCSymbol &Sym = SRE.getSymbol(); + // Parenthesize names that start with $ so that they don't look like // absolute names. - bool UseParens = - !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$'; + bool UseParens = false; + if (MAI && MAI->useParensForDollarSignNames()) { + UseParens = + !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$'; + } + if (UseParens) { OS << '('; Sym.print(OS, MAI); Index: llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp =================================================================== --- llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp +++ llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp @@ -58,4 +58,8 @@ // ptxas does not support DWARF `.file fileno directory filename' // syntax as of v11.X. EnableDwarfFileDirectoryDefault = false; + + // Avoid using parens for identifiers starting with $ - ptxas does + // not expect them. + UseParensForDollarSignNames = false; } Index: llvm/test/CodeGen/NVPTX/no-extra-parens.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/NVPTX/no-extra-parens.ll @@ -0,0 +1,14 @@ +; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s + +; ptxas has no special meaning for '$' character, so it should be used +; without parens. + +@"$str" = private addrspace(1) constant [4 x i8] c"str\00" + +declare void @str2(i8* %str) +define void @str1() { +entry: +;; CHECK: mov.u64 %rd{{[0-9]+}}, $str; + tail call void @str2(i8* getelementptr ([4 x i8], [4 x i8]* addrspacecast ([4 x i8] addrspace(1)* @"$str" to [4 x i8]*), i64 0, i64 0)) + ret void +}