Issue |
140328
|
Summary |
[mlir][arith] Erroneous canonicalization pattern for `arith.addi`
|
Labels |
mlir:arith
|
Assignees |
|
Reporter |
math-fehr
|
When running `mlir-opt --canonicalize` (https://godbolt.org/z/6q9ehf7q7), the following program:
```
func.func @foo(%x : i2) -> i2 {
%c-1 = arith.constant -1 : i2
%c-2 = arith.constant -2 : i2
%temp = arith.addi %x, %c-2 overflow<nsw> : i2
%res = arith.addi %temp, %c-1 overflow<nsw> : i2
func.return %res : i2
}
```
gets compiled into the following program:
```
func.func @foo(%arg0: i2) -> i2 {
%c1_i2 = arith.constant 1 : i2
%0 = arith.addi %arg0, %c1_i2 overflow<nsw> : i2
return %0 : i2
}
```
Note that while I use `i2` for the example, there is equivalent issues for any integer sizes (besides 1). Reminder, the allowed values are `-2, -1, 0, 1` for `i2`.
When the input is 1, the first program will return `-2`, while the second program will return `poison`.
I played a bit with the alive-like tool I am working on, and what I'm getting is that [this canonicalization pattern](https://github.com/llvm/llvm-project/blob/f7ef8dcbad9d5ac6cf2a8917d5ce03564fdfd0d8/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td#L43) is buggy whenever the two input adds have only the `nsw` flag, or if one has the `nsw` flag and the other has the `nsw` and `nuw` flag.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs