[llvm] [NVPTX] Basic support for fp128 as a storage type (PR #136006)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 16 15:49:06 PDT 2025


================
@@ -1682,31 +1673,39 @@ void NVPTXAsmPrinter::bufferLEByte(const Constant *CPV, int Bytes,
 void NVPTXAsmPrinter::bufferAggregateConstant(const Constant *CPV,
                                               AggBuffer *aggBuffer) {
   const DataLayout &DL = getDataLayout();
-  int Bytes;
 
-  // Integers of arbitrary width
-  if (const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
-    APInt Val = CI->getValue();
-    for (unsigned I = 0, E = DL.getTypeAllocSize(CPV->getType()); I < E; ++I) {
+  auto ExtendBuffer = [](APInt Val, AggBuffer *Buffer) {
+    for (unsigned _ : llvm::seq(Val.getBitWidth() / 8)) {
       uint8_t Byte = Val.getLoBits(8).getZExtValue();
-      aggBuffer->addBytes(&Byte, 1, 1);
+      Buffer->addBytes(&Byte, 1, 1);
       Val.lshrInPlace(8);
     }
----------------
Artem-B wrote:

Hmm. Now that `lshrInPlace` stands out as a sore thumb. We want Nth byte of the value, and there's really no point shifting it piecemeal, when we already have the index available as the loop variable.

All we need is `Buffer->addBytes(Val.lshr(I*8).trunc(8).getZExtValue(), 1, 1);`

https://github.com/llvm/llvm-project/pull/136006


More information about the llvm-commits mailing list