Open
Description
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 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.