llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[mlir][spirv] Tensor arith.uitofp aborts in both convert-arith-to-spirv and convert-scf-to-spirv

Open lin334141-cell opened this issue 2 months ago • 2 comments

The crash was reproduced on the fixed revision below. The same minimized input aborts through two Pass entry points. I have not run a binary built from current main, so this report does not claim a current-main runtime reproduction.

Environment

  • llvm-project revision: 67005b724c917e1bdca50c82ecaa1b21a69244ed (LLVM 24.0.0git).
  • mlir-opt: Release build with LLVM_ENABLE_ASSERTIONS=ON; binary SHA-256 9b1858d58d1d2e0371e5d02ee65a88757ef9fa9cbbae571dd59737b52f0bd37a.
  • Current-main source snapshot inspected: b15daae148e77f1ad2e20990094ddbeb8cc598ac. ArithToSPIRV.cpp has the same Git blob as the tested revision; this is source inspection only.

Reproducer

Save as reproducer.mlir:

func.func @f(%x: tensor<2xi32>) -> tensor<2xf32> {
  %y = arith.uitofp %x : tensor<2xi32> to tensor<2xf32>
  return %y : tensor<2xf32>
}

The file's SHA-256 is 4c8af17fb5203326708fa34b6e74fb4cd993918dd2e3ada598e15d6511c62129.

Steps to reproduce

First, check the input without a conversion Pass:

mlir-opt --verify-each=true --mlir-disable-threading < reproducer.mlir

Then run either Pass independently:

mlir-opt --pass-pipeline='builtin.module(convert-arith-to-spirv)' --verify-each=true --mlir-disable-threading < reproducer.mlir
mlir-opt --pass-pipeline='builtin.module(convert-scf-to-spirv)' --verify-each=true --mlir-disable-threading < reproducer.mlir

These are the command-line arguments checked on the fixed revision above.

Actual behavior

The input-only check exits with code 0. For the minimized input, each conversion command was independently run twice. All four conversion runs aborted with SIGABRT (signal 6; return code -6 from Python's subprocess API), and their stdout was empty:

Pass Independent runs Observed result
convert-arith-to-spirv 2 SIGABRT, return code -6 in both runs
convert-scf-to-spirv 2 SIGABRT, return code -6 in both runs

The stderr assertion is:

mlir/lib/IR/Types.cpp:125: unsigned int mlir::Type::getIntOrFloatBitWidth() const:
Assertion `isIntOrFloat() && "only integers and floats have a bitwidth"' failed.

The captured stack includes mlir::Type::getIntOrFloatBitWidth() and OpConversionPattern<mlir::arith::UIToFPOp> in the ArithToSPIRV conversion. Both Pass entry points reach this same apparent failing conversion path.

Expected behavior

A valid tensor arith.uitofp should be lowered if supported, or the conversion should fail with a handled diagnostic. mlir-opt should not abort.

Analysis

On the tested revision, the IntToFPPattern implementation calls getIntOrFloatBitWidth() after type conversion without first establishing that the resulting operand type is a supported scalar/vector element type. This is a source-based hypothesis for the assertion, not a proven root cause.

Related issues

  • #178214 and PR #179009 concern tensor arith.trunci in ArithToSPIRV, a different conversion pattern.
  • #205233 concerns tensor arith.extui and a different failure mode.

I did not find an exact arith.uitofp tensor report in the targeted issue/PR search. This does not establish that no duplicate exists.

lin334141-cell avatar Sep 25 '26 06:09 lin334141-cell

@llvm/issue-subscribers-mlir

Author: lin334141-cell

## Environment
  • llvm-project revision: 67005b724c917e1bdca50c82ecaa1b21a69244ed (LLVM 24.0.0git).
  • mlir-opt: Release build with LLVM_ENABLE_ASSERTIONS=ON; binary SHA-256 9b1858d58d1d2e0371e5d02ee65a88757ef9fa9cbbae571dd59737b52f0bd37a.
  • A binary built from current main has not been run. At source snapshot b15daae148e77f1ad2e20990094ddbeb8cc598ac, ArithToSPIRV.cpp has the same Git blob as the tested revision; this is source inspection only.

Reproducer

Save as reproducer.mlir:

func.func @<!-- -->f(%x: tensor&lt;2xi32&gt;) -&gt; tensor&lt;2xf32&gt; {
  %y = arith.uitofp %x : tensor&lt;2xi32&gt; to tensor&lt;2xf32&gt;
  return %y : tensor&lt;2xf32&gt;
}

The input passes mlir-opt --verify-each=true --mlir-disable-threading &lt; reproducer.mlir with exit code 0. Its SHA-256 is 4c8af17fb5203326708fa34b6e74fb4cd993918dd2e3ada598e15d6511c62129.

Either command below aborts on the revision above:

mlir-opt --pass-pipeline='builtin.module(convert-arith-to-spirv)' --verify-each=true --mlir-disable-threading &lt; reproducer.mlir
mlir-opt --pass-pipeline='builtin.module(convert-scf-to-spirv)' --verify-each=true --mlir-disable-threading &lt; reproducer.mlir

Each command was independently run twice with this minimized input. All four runs ended in SIGABRT (signal 6, subprocess return code -6), with this assertion:

mlir/lib/IR/Types.cpp:125: unsigned int mlir::Type::getIntOrFloatBitWidth() const:
Assertion `isIntOrFloat() &amp;&amp; "only integers and floats have a bitwidth"' failed.

The stack includes mlir::Type::getIntOrFloatBitWidth() and OpConversionPattern&lt;mlir::arith::UIToFPOp&gt; in the ArithToSPIRV conversion. The two Pass names select the same apparent failing conversion path.

Expected behavior and source observation

A valid tensor arith.uitofp should either be lowered if supported or produce a normal conversion failure. mlir-opt should not abort.

The IntToFPPattern implementation calls getIntOrFloatBitWidth() after type conversion without first establishing that the resulting operand type is a supported scalar/vector element type. This is a source-based hypothesis for the assertion, not a proven root cause.

Related reports

  • #178214 and PR #179009 concern tensor arith.trunci in ArithToSPIRV, a different conversion pattern.
  • #205233 concerns tensor arith.extui and a different failure mode.

I did not find an exact arith.uitofp tensor report in the targeted issue/PR search. This does not establish that no duplicate exists.

@EugeneZelenko I'm working on this PR. =)

viniciusfdasilva avatar Sep 26 '26 04:09 viniciusfdasilva