Issue 117554
Summary [MLIR][Arith] Invalid SelectOp folding
Labels bug, mlir:arith
Assignees
Reporter 7FM
    In CIRCT, we have a dialect named `hwarith` to represent arithmetics that persist signedness information and prevent unintentional under- and overflows.
Using this dialect in combination with `arith.select` revealed an issue. Take the following example code:
```
func.func @test(%sel : i1) -> ui1 {
  %trueVal = hwarith.constant 1 : ui1
  %falseVal = hwarith.constant 0 : ui1
  %res = arith.select %sel, %trueVal, %falseVal : ui1
  func.return %res : ui1
}
```
The SelectOp's folder tries to replace the SelectOp directly with `%sel`. However, `%sel` is of type `i1` whereas the true- and falseVal values are of type `ui1`. Consequently, the following crash is caused: `error: 'arith.select' op folder produced a value of incorrect type: 'i1', expected: 'ui1'`.

The corresponding pattern matching code has a bit-width check for the return type but lacks a signedness check and thus implicitly assumes that the return type is signless (i1):
https://github.com/llvm/llvm-project/blob/612f8ec7ac5dcddd16fb027aad64e2e353faa528/mlir/lib/Dialect/Arith/IR/ArithOps.cpp#L2317-L2319
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to