| Issue |
83530
|
| Summary |
Inconsistent results when using --arith-unsigned-when-equivalent
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
wangyongj1a
|
I have the following MLIR program:
test.mlir:
```
module {
func.func @func1() {
%c1506825994_i64 = arith.constant 1506825994 : i64
%c1111530998_i64 = arith.constant 1111530998 : i64
%c1357835903_i64 = arith.constant 1357835903 : i64
%c4995493184_i64 = arith.constant 4995493184 : i64
%false = arith.constant false
%21 = scf.if %false -> (i64) { //the result should be 1111530998
scf.yield %c4995493184_i64 : i64
} else {
scf.yield %c1111530998_i64 : i64
}
// 1357835903 % 1111530998 = 246304905
%22 = arith.remui %c1357835903_i64, %21 : i64 //the result should be 246304905
// 246304905 or 1357835903 = 1592721151
// 1110101011100101000010001001 or 1010000111011101110111001111111 = 1011110111011101111111011111111
%26 = arith.ori %22, %c1357835903_i64 : i64 //the result should be 1592721151
// 1011110111011101111111011111111 xor 1506825994(1011001110100000101011100001010) = 0000111001111101010100111110101(121547253)
%57 = arith.xori %26, %c1506825994_i64 : i64 //the result should be 121547253
// 121547253 - 1111530998 = -989983745
%67 = arith.subi %57, %c1111530998_i64 : i64 //the result should be -989983745
// min(-989983745, 1506825994)
%169 = arith.minsi %67, %c1506825994_i64 : i64 //the result should be -989983745
vector.print %169 : i64
return
}
}
```
When I tried ```mlir-opt --convert-scf-to-cf --convert-cf-to-llvm --arith-unsigned-when-equivalent test.mlir```, then the program was optimized to :
```
module {
func.func @func1() {
%c1506825994_i64 = arith.constant 1506825994 : i64
%c1111530998_i64 = arith.constant 1111530998 : i64
%c1357835903_i64 = arith.constant 1357835903 : i64
%c4995493184_i64 = arith.constant 4995493184 : i64
%false = arith.constant false
llvm.cond_br %false, ^bb1, ^bb2
^bb1: // pred: ^bb0
llvm.br ^bb3(%c4995493184_i64 : i64)
^bb2: // pred: ^bb0
llvm.br ^bb3(%c1111530998_i64 : i64)
^bb3(%0: i64): // 2 preds: ^bb1, ^bb2
llvm.br ^bb4
^bb4: // pred: ^bb3
%1 = arith.remui %c1357835903_i64, %0 : i64
%2 = arith.ori %1, %c1357835903_i64 : i64
%3 = arith.xori %2, %c1506825994_i64 : i64
%4 = arith.subi %3, %c1111530998_i64 : i64
%5 = arith.minui %4, %c1506825994_i64 : i64
vector.print %5 : i64
return
}
}
```
I've analyzed this program manually, and according to my analysis, the number values of the two operands in the arith minimum operation seems to be -989983745 and 1506825994. This operation should get the result of -989983745 for ```arith.minsi```, and 1506825994 for ```arith.minui```. However, in my test, the ```--arith-unsigned-when-equivalent``` pass seems to optimize the ```arith.minsi``` operation to ```arith.minui```, and will cause an inconsistent result according to my analysis.
I'm not sure if there is any bug in my program or the wrong usage of the ```--arith-unsigned-when-equivalent``` that caused this error.
My git version is 5b6e58c565cf809e4133a10ff9d9b096754bea1e.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs