[llvm] [SPIRV] Fix trunc nonstandard int types (PR #191393)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 04:52:45 PDT 2026


================
@@ -486,6 +501,39 @@ generateAssignInstrs(MachineFunction &MF, SPIRVGlobalRegistry *GR,
       ST->canUseExtension(SPIRV::Extension::SPV_KHR_bit_instructions) ||
       ST->canUseExtension(SPIRV::Extension::SPV_INTEL_int4);
 
+  if (!IsExtendedInts) {
+    // Some instructions' behavior relies on register size, e.g. G_TRUNC.
+    // Process them before general register widening.
+    for (MachineBasicBlock &MBB : MF) {
+      for (MachineInstr &MI : MBB) {
+        unsigned MIOp = MI.getOpcode();
+        if (MIOp == TargetOpcode::G_TRUNC) {
+          assert(MI.getNumOperands() == 2);
+
+          widenOperand(MI.getOperand(1), MRI); // SRC
+
+          unsigned OriginalDstWidth = widenOperand(MI.getOperand(0), MRI);
+          if (OriginalDstWidth != 0) {
----------------
idubinov wrote:

done

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


More information about the llvm-commits mailing list