[llvm] [SPIR-V] Fix sub-byte argument type mismatch in call lowering (PR #189893)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 00:04:18 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Arseniy Obolenskiy (aobolensk)

<details>
<summary>Changes</summary>

Remove the `MRI->setType()` call in lowerFormalArguments that was overriding the vreg LLT with the SPIR-V type's LLT, causing a type mismatch when sub-byte integer arguments (e.g. i2, i4) were preliminary widened to i8

related to https://github.com/llvm/llvm-project/issues/188703

---
Full diff: https://github.com/llvm/llvm-project/pull/189893.diff


4 Files Affected:

- (modified) llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp (-1) 
- (modified) llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse-subbyte.ll (+4-7) 
- (modified) llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse_i2.ll (+4-7) 
- (added) llvm/test/CodeGen/SPIRV/transcoding/subbyte-arg-type-mismatch.ll (+16) 


``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
index bc6418f2ceceb..1defbc5fabb72 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
@@ -395,7 +395,6 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
     assert(VRegs[i].size() == 1 && "Formal arg has multiple vregs");
     Register ArgReg = VRegs[i][0];
     MRI->setRegClass(ArgReg, GR->getRegClass(ArgTypeVRegs[i]));
-    MRI->setType(ArgReg, GR->getRegType(ArgTypeVRegs[i]));
     auto MIB = MIRBuilder.buildInstr(SPIRV::OpFunctionParameter)
                    .addDef(ArgReg)
                    .addUse(GR->getSPIRVTypeID(ArgTypeVRegs[i]));
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse-subbyte.ll b/llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse-subbyte.ll
index 280f586891717..5d3f77cc9075a 100644
--- a/llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse-subbyte.ll
+++ b/llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse-subbyte.ll
@@ -1,14 +1,11 @@
 ; The goal of the test case is to ensure valid SPIR-V code emision
 ; on translation of integers with bit width less than 8.
 
-; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %}
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %}
 
-; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %}
-
-; TODO: This test currently fails with LLVM_ENABLE_EXPENSIVE_CHECKS enabled
-; XFAIL: expensive_checks
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %}
 
 ; CHECK-SPIRV: OpCapability BitInstructions
 ; CHECK-SPIRV: OpExtension "SPV_KHR_bit_instructions"
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse_i2.ll b/llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse_i2.ll
index 9d6a5e0dc0d32..200355ec0326f 100644
--- a/llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse_i2.ll
+++ b/llvm/test/CodeGen/SPIRV/transcoding/OpBitReverse_i2.ll
@@ -1,14 +1,11 @@
 ; The goal of the test case is to ensure that there's no crash
 ; on translation of integers with bit width less than 8.
 
-; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %}
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %}
 
-; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV
-; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %}
-
-; TODO: This test currently fails with LLVM_ENABLE_EXPENSIVE_CHECKS enabled
-; XFAIL: expensive_checks
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s --spirv-ext=+SPV_KHR_bit_instructions -o - -filetype=obj | spirv-val %}
 
 ; CHECK-SPIRV: OpCapability BitInstructions
 ; CHECK-SPIRV: OpExtension "SPV_KHR_bit_instructions"
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/subbyte-arg-type-mismatch.ll b/llvm/test/CodeGen/SPIRV/transcoding/subbyte-arg-type-mismatch.ll
new file mode 100644
index 0000000000000..0f1b364524a7f
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/transcoding/subbyte-arg-type-mismatch.ll
@@ -0,0 +1,16 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: %[[#CharTy:]] = OpTypeInt 8 0
+; CHECK: %[[#FnTy:]] = OpTypeFunction %[[#CharTy]] %[[#CharTy]] %[[#CharTy]]
+; CHECK: %[[#Fn:]] = OpFunction %[[#CharTy]] None %[[#FnTy]]
+; CHECK: %[[#A:]] = OpFunctionParameter %[[#CharTy]]
+; CHECK: %[[#B:]] = OpFunctionParameter %[[#CharTy]]
+; CHECK: %[[#Res:]] = OpIAdd %[[#CharTy]] %[[#A]] %[[#B]]
+; CHECK: OpReturnValue %[[#Res]]
+
+define spir_func i2 @add_i2(i2 %a, i2 %b) {
+entry:
+  %r = add i2 %a, %b
+  ret i2 %r
+}

``````````

</details>


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


More information about the llvm-commits mailing list