[LLVM][NVPTX] Add vector ConstantInt/FP support to bufferAggregateConstant. (#182544)
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index b69a0d2..6e8fb1c 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -1710,14 +1710,25 @@
Buffer->addByte(Val.extractBitsAsZExtValue(8, I * 8));
};
+ // Integer or floating point vector splats.
+ if (isa<ConstantInt, ConstantFP>(CPV)) {
+ if (auto *VTy = dyn_cast<FixedVectorType>(CPV->getType())) {
+ for (unsigned I : llvm::seq(VTy->getNumElements()))
+ bufferLEByte(CPV->getAggregateElement(I), 0, aggBuffer);
+ return;
+ }
+ }
+
// Integers of arbitrary width
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
+ assert(CI->getType()->isIntegerTy() && "Expected integer constant!");
ExtendBuffer(CI->getValue(), aggBuffer);
return;
}
// f128
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CPV)) {
+ assert(CFP->getType()->isFloatingPointTy() && "Expected fp constant!");
if (CFP->getType()->isFP128Ty()) {
ExtendBuffer(CFP->getValueAPF().bitcastToAPInt(), aggBuffer);
return;
diff --git a/llvm/test/CodeGen/NVPTX/globals_init.ll b/llvm/test/CodeGen/NVPTX/globals_init.ll
index c8d184a..06d103b 100644
--- a/llvm/test/CodeGen/NVPTX/globals_init.ll
+++ b/llvm/test/CodeGen/NVPTX/globals_init.ll
@@ -1,6 +1,8 @@
; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_20 | FileCheck %s
; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_20 | %ptxas-verify %}
+; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_20 -use-constant-int-for-fixed-length-splat -use-constant-fp-for-fixed-length-splat | FileCheck %s
+
; Make sure the globals constant initializers are not prone to host endianess
; issues.
@@ -29,3 +31,8 @@
; CHECK-DAG: .b8 GblU[12] = {7, 6, 0, 0, 5, 4, 3, 2, 1};
@GblU = global {i16, i32, i8} {i16 1543, i32 33752069, i8 1}
+; CHECK-DAG: .b8 Gblv4i16[8] = {205, 171, 205, 171, 205, 171, 205, 171};
+@Gblv4i16 = global <4 x i16> splat(i16 43981)
+
+; CHECK-DAG: .b8 Gblv4f32[16] = {0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63};
+@Gblv4f32 = global <4 x float> splat(float 1.0)