[all-commits] [llvm/llvm-project] 8b67f3: [mlir] [arith] Fix ceildivsi lowering in arith-exp...
Fehr Mathieu via All-commits
all-commits at lists.llvm.org
Wed Apr 2 09:27:20 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 8b67f362583db5f9ace7238bcc174ec6cd11527f
https://github.com/llvm/llvm-project/commit/8b67f362583db5f9ace7238bcc174ec6cd11527f
Author: Fehr Mathieu <mathieu.fehr at gmail.com>
Date: 2025-04-02 (Wed, 02 Apr 2025)
Changed paths:
M mlir/lib/Dialect/Arith/Transforms/ExpandOps.cpp
M mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
M mlir/test/Dialect/Arith/expand-ops.mlir
A mlir/test/Integration/Dialect/Arith/CPU/test-arith-expand-ceildivsi.mlir
Log Message:
-----------
[mlir] [arith] Fix ceildivsi lowering in arith-expand (#133774)
This fixes the current lowering of `arith.ceildivsi` in the arith-expand
pass, which was previously incorrect. The new version is based on the
lowering of `arith.floordivsi`, and will not introduce new undefined
behavior or poison during the lowering. It also replaces one division
with a multiplication.
The previous lowering of `ceildivsi(n, m)` was the following:
```
x = (m > 0) ? -1 : 1
(n*m>0) ? ((n+x) / m) + 1 : - (-n / m)
```
This caused two problems:
* In the case where `n` is INT_MIN and `m` is positive, the result would
be poison instead of an actual value
* In the case where `n` is INT_MAX and `m` is `-1`, this would trigger
undefined behavior, while the original code wouldn't. This is because
`n+x` would be equal to `INT_MIN` (`INT_MAX + 1`), so the `(n+x) / m`
division would overflow and trigger UB.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list