| Issue |
107508
|
| Summary |
[mlir] Semantic inconsistency in `ceildiv` optimization
|
| Labels |
mlir
|
| Assignees |
|
| Reporter |
Emilyaxe
|
Git version: [c28b1a19aa](https://github.com/llvm/llvm-project/commit/c28b1a19aa)
System: Ubuntu 18.04.6 LTS
# Issue Description:
In the following MLIR:
a.mlir
```
func.func @semiaffine_composite_floor(%arg0: index, %arg1: index) -> index {
%a = affine.apply affine_map<(d0)[s0] ->(((((s0 * 2) ceildiv 4) * 5) + s0 * 42) ceildiv s0)> (%arg0)[%arg1]
return %a : index
}
```
After running `mlir-opt -canonicalize a.mlir`, the resulting optimized MLIR is:
```
module {
func.func private @semiaffine_composite_floor(%arg0: index, %arg1: index) -> index {
%c47 = arith.constant 47 : index
return %c47 : index
}
}
```
This leads to the result always being 47.
However, without applying the canonicalize optimization, the result of a.mlir varies depending on the input `%arg1` as follows:
- 44 if `%arg1` is less than 0
- Floating-point exception if `%arg1` is 0
- 47 if `%arg1` is 1
- 45 if `%arg1 `is greater than 1
This seems like a misoptimization in the handling of ceildiv. The canonicalize pass simplifies the _expression_ to always return 47, but the expected behavior is input-dependent as shown above. Is this an unintended side effect of the ceildiv optimization?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs