Index: lib/Target/NVPTX/NVPTXAsmPrinter.h =================================================================== --- lib/Target/NVPTX/NVPTXAsmPrinter.h +++ lib/Target/NVPTX/NVPTXAsmPrinter.h @@ -155,13 +155,13 @@ if (pos == nextSymbolPos) { const Value *v = Symbols[nSym]; const Value *v0 = SymbolsBeforeStripping[nSym]; + PointerType *PTy = dyn_cast(v0->getType()); + bool IsNonGenericPointer = false; // Is v0 a non-generic pointer? + if (PTy && PTy->getAddressSpace() != 0) { + IsNonGenericPointer = true; + } if (const GlobalValue *GVar = dyn_cast(v)) { MCSymbol *Name = AP.getSymbol(GVar); - PointerType *PTy = dyn_cast(v0->getType()); - bool IsNonGenericPointer = false; // Is v0 a non-generic pointer? - if (PTy && PTy->getAddressSpace() != 0) { - IsNonGenericPointer = true; - } if (EmitGeneric && !isa(v) && !IsNonGenericPointer) { O << "generic("; O << *Name; @@ -170,7 +170,13 @@ O << *Name; } } else if (const ConstantExpr *Cexpr = dyn_cast(v)) { - O << *AP.lowerConstant(Cexpr); + if (EmitGeneric && !IsNonGenericPointer) { + O << "generic("; + O << *AP.lowerConstant(Cexpr); + O << ")"; + } else { + O << *AP.lowerConstant(Cexpr); + } } else llvm_unreachable("symbol type unknown"); nSym++; Index: test/CodeGen/NVPTX/addrspacecast-gvar.ll =================================================================== --- test/CodeGen/NVPTX/addrspacecast-gvar.ll +++ test/CodeGen/NVPTX/addrspacecast-gvar.ll @@ -4,8 +4,10 @@ ; CHECK: .visible .global .align 4 .u32 g2 = generic(g); ; CHECK: .visible .global .align 4 .u32 g3 = g; ; CHECK: .visible .global .align 8 .u32 g4[2] = {0, generic(g)}; +; CHECK: .visible .global .align 8 .u32 g5[2] = {0, generic(g+8)}; @g = addrspace(1) global i32 42 @g2 = addrspace(1) global i32* addrspacecast (i32 addrspace(1)* @g to i32*) @g3 = addrspace(1) global i32 addrspace(1)* @g @g4 = constant {i32*, i32*} {i32* null, i32* addrspacecast (i32 addrspace(1)* @g to i32*)} +@g5 = constant {i32*, i32*} {i32* null, i32* addrspacecast (i32 addrspace(1)* getelementptr (i32, i32 addrspace(1)* @g, i32 2) to i32*)}