[llvm] [SPIR-V] Emit ceil(Bitwidth / 32) words during OpConstant creation (PR #180218)

Marcos Maronas via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 9 07:07:08 PST 2026


================
@@ -171,15 +171,17 @@ void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB) {
     // Asm Printer needs this info to print 64-bit operands correctly
     MIB.getInstr()->setAsmPrinterFlag(SPIRV::ASM_PRINTER_WIDTH64);
     return;
-  } else if (Bitwidth <= 128) {
-    uint32_t LowBits = Imm.getRawData()[0] & 0xffffffff;
-    uint32_t MidBits0 = (Imm.getRawData()[0] >> 32) & 0xffffffff;
-    uint32_t MidBits1 = Imm.getRawData()[1] & 0xffffffff;
-    uint32_t HighBits = (Imm.getRawData()[1] >> 32) & 0xffffffff;
-    MIB.addImm(LowBits).addImm(MidBits0).addImm(MidBits1).addImm(HighBits);
+  } else {
+    // Emit ceil(Bitwidth / 32) words to conform SPIR-V spec.
----------------
maarquitos14 wrote:

This is a nice little piece of code. I'm wondering if it would be of any use elsewhere,  if so it can be converted into a utility function.

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


More information about the llvm-commits mailing list