[all-commits] [llvm/llvm-project] 53fec0: [mlir][arith] Fix APInt bitwidth mismatch crash in...
Anutosh Bhat via All-commits
all-commits at lists.llvm.org
Mon Jun 22 21:34:34 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 53fec04cc23de825ed6ae1c84dea5d45b746fba9
https://github.com/llvm/llvm-project/commit/53fec04cc23de825ed6ae1c84dea5d45b746fba9
Author: Anutosh Bhat <andersonbhat491 at gmail.com>
Date: 2026-06-23 (Tue, 23 Jun 2026)
Changed paths:
M mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
M mlir/test/Dialect/Arith/int-range-opts-crash.mlir
Log Message:
-----------
[mlir][arith] Fix APInt bitwidth mismatch crash in int-range-optimizations (#205110)
Fixes https://github.com/llvm/llvm-project/issues/204909
When an op's `areTypesCompatible()` hook accepts integers of different
widths across a region boundary, the range analysis can propagate a
constant range whose APInt bitwidth does not match the IR type of the
destination value.
This caused `IntegerAttr::get` to `assert` in
`maybeReplaceWithConstant`.
Fix by bailing out in `maybeReplaceWithConstant` when the bitwidths
mismatch, and adding the same check to the needsReplacing lambda in
matchAndRewrite.
The second guard is necessary to mirror the existing isIntOrIndex()
guard — without it the pattern claims success without changing the IR,
causing the greedy rewrite driver to loop.
We should now see
```
anutosh491 at Anutoshs-MacBook-Air mlir-build % ./bin/mlir-opt -int-range-optimizations bin/a.mlir
module {
func.func @m0() -> i32 {
%c1_i64 = arith.constant 1 : i64
%c0_i32 = arith.constant 0 : i32
%0 = "test.region_types_compat"(%c0_i32) ({
^bb0(%arg0: i64):
test.types_compat_yield %c1_i64 : i64
}) : (i32) -> i32
return %0 : i32
}
}
```
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list