For amdgcn target Clang generates addrspacecast to represent null pointers in private and local address spaces.
In LLVM codegen, the static variable initializer is lowered by virtual function AsmPrinter::lowerConstant which is target generic. Since addrspacecast is target specific, AsmPrinter::lowerConstant is unable to lower addrspacecast in the null pointer representation.
This patch overrides AsmPrinter::lowerConstant with AMDGPUAsmPrinter::lowerConstant, which is able to lower the target-specific addrspacecast in the null pointer representation so that -1 is correctly emitted in codeobject as initial value for null pointers.
We should factor the constant folding of pointers into a single place. The same logic is already repeated in SIISelLowering and I have a need of it in another place.
Maybe we should put a constant fold pointer helper in AMDGPUTargetMachine?