Skip to content

[SPIRV] Unsigned division, remainder and comparison fail on emulated i8 and i16 #25316

Open

Description

@roberto-laudani

What happened?

Compiling an i8 arith.divui for Vulkan fails in iree-convert-to-spirv:

divui_i8.mlir:2:8: error: bitwidth emulation is not implemented yet on unsigned op pattern version
  %0 = arith.divui %lhs, %rhs : tensor<4xi8>
       ^
divui_i8.mlir:2:8: error: failed to legalize operation 'arith.divui': %57 = "arith.divui"(%37, %56) : (i8, i8) -> i8

The default Vulkan target has only the Shader capability (#spirv.vce<v1.3, [Shader], []>), so i8 and i16 are emulated in i32. The Arith to SPIR-V conversion rejects unsigned division, remainder and comparison on emulated types. On i8 and i16:

  • arith.remui and arith.ceildivui fail with the same error.
  • arith.cmpi with ult, ule, ugt or uge fails with bitwidth emulation is not implemented yet on unsigned op.
  • The signed versions of these ops compile, and so does arith.divui on i32.

Expected: these ops compile, as their signed versions do.

Steps to reproduce your issue

divui_i8.mlir:

func.func @divui_i8(%lhs: tensor<4xi8>, %rhs: tensor<4xi8>) -> tensor<4xi8> {
  %0 = arith.divui %lhs, %rhs : tensor<4xi8>
  return %0 : tensor<4xi8>
}
iree-compile --iree-hal-target-device=vulkan divui_i8.mlir -o divui_i8.vmfb

What component(s) does this issue relate to?

Compiler, MLIR

Version information

iree-base-compiler 3.15.0rc20261118 (a5031bf)

Additional context

The check is in upstream MLIR: spirv::ElementwiseOpPattern in mlir/lib/Conversion/SPIRVCommon/Pattern.h, and ElementwiseArithOpPattern, CeilDivUIOpPattern and CmpIOpPattern in mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp. arith-to-spirv-unsupported.mlir expects this error.

Since llvm/torch-mlir#4896, uint8 division lowers to arith.divui. With the torch-mlir bump in #25309, ONNX test_div_uint8 hits this error and is an expected compile failure on Vulkan.

Related: #25272.

Assisted by: Claude

Activity

  1. added
    bug 🐞
    codegen/spirv
    hal/vulkan
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞codegen/spirvhal/vulkan

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions