[NVPTX] Fix constant expression initializers for global variables
authorAndrew Savonichev <andrew.savonichev@gmail.com>
Mon, 13 Jun 2022 16:05:50 +0000 (19:05 +0300)
committerAndrew Savonichev <andrew.savonichev@gmail.com>
Mon, 3 Oct 2022 21:29:42 +0000 (00:29 +0300)
commitd420110a1e9d620632d47366d569d234026b9e0e
tree516dd2a9ac7f80372d2d3c66966e4e58612da9c1
parent5585d99835e83cca79ead9f0d90fcfab927391d5
[NVPTX] Fix constant expression initializers for global variables

Before this patch the code in printScalarConstant was unable to handle
nested constant expressions like (gep (addrspacecast ptr)) and crashed
with:

LLVM ERROR: Unsupported expression in static initializer:
  addrspacecast ([4 x i8] addrspace(1)* @ga to [4 x i8]*)

We can use lowerConstantForGV instead which is a customized version of
lowerConstant that supports generic() and nested expressions.

Differential Revision: https://reviews.llvm.org/D127878
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/test/CodeGen/NVPTX/addrspacecast-gvar.ll