[llvm] [SPIR-V] Emit valid SPIR-V code for integer sizes other than 8,16,32,64 (PR #94219)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 3 07:42:34 PDT 2024


================
@@ -90,27 +90,36 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeBool(MachineIRBuilder &MIRBuilder) {
       .addDef(createTypeVReg(MIRBuilder));
 }
 
-SPIRVType *SPIRVGlobalRegistry::getOpTypeInt(uint32_t Width,
-                                             MachineIRBuilder &MIRBuilder,
-                                             bool IsSigned) {
+unsigned SPIRVGlobalRegistry::adjustOpTypeIntWidth(unsigned Width) const {
   assert(Width <= 64 && "Unsupported integer width!");
-  const SPIRVSubtarget &ST =
-      cast<SPIRVSubtarget>(MIRBuilder.getMF().getSubtarget());
+  const SPIRVSubtarget &ST = cast<SPIRVSubtarget>(CurMF->getSubtarget());
   if (ST.canUseExtension(
-          SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers)) {
-    MIRBuilder.buildInstr(SPIRV::OpExtension)
-        .addImm(SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers);
-    MIRBuilder.buildInstr(SPIRV::OpCapability)
-        .addImm(SPIRV::Capability::ArbitraryPrecisionIntegersINTEL);
-  } else if (Width <= 8)
+          SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers))
+    return Width;
+  if (Width <= 8)
     Width = 8;
   else if (Width <= 16)
     Width = 16;
   else if (Width <= 32)
     Width = 32;
   else if (Width <= 64)
     Width = 64;
+  return Width;
----------------
Keenuts wrote:

Shall the last condition be removed, and this function always return 64 if width > 32? (given the assert above)

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


More information about the llvm-commits mailing list