[MLIR] Missed Optimization: remui elimination with a sign-bit-set constant divisor
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The `int-range-optimizations` optimization in `arith` dialect appears to miss a redundant `arith.remui` when the unsigned divisor is interpreted as a negative signed constant.
Here, `%x` is in `[0, 63]`, and the divisor’s unsigned value is `200`, so `%r` can be replaced with `%x`. However, `DeleteTrivialRem` reads the divisor through `getConstantIntValue` and rejects it at `modulus <= 0`.
### Code Example
**example.mlir**
```mlir
func.func @remui_unsigned_modulus(%arg: i8) -> i8 {
%mask = arith.constant 63 : i8
%modulus = arith.constant -56 : i8 // Unsigned value: 200.
%x = arith.andi %arg, %mask : i8
%r = arith.remui %x, %modulus : i8
return %r : i8
}
```
### Command
```bash
mlir-opt example.mlir --int-range-optimizations
```
Version: 6f54fe6b6fb22f8a335fd19b94049fc769dfea25
Contributor guide
Research direction
Start by locating DeleteTrivialRem in the arith int-range-optimizations implementation and inspect how getConstantIntValue handles the sign-bit-set divisor. Run mlir-opt example.mlir --int-range-optimizations with the supplied example, then verify that the redundant arith.remui is eliminated for the unsigned divisor value 200.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100