[all-commits] [llvm/llvm-project] b1da82: [mlir][arith] Fix overflow bug in arith::CeilDivSI...
Andrzej Warzyński via All-commits
all-commits at lists.llvm.org
Wed May 8 13:06:25 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b1da82ae3dba0982b3a9668ca895ddf4164fb3d1
https://github.com/llvm/llvm-project/commit/b1da82ae3dba0982b3a9668ca895ddf4164fb3d1
Author: Andrzej Warzyński <andrzej.warzynski at arm.com>
Date: 2024-05-08 (Wed, 08 May 2024)
Changed paths:
M mlir/lib/Dialect/Arith/IR/ArithOps.cpp
M mlir/test/Transforms/constant-fold.mlir
Log Message:
-----------
[mlir][arith] Fix overflow bug in arith::CeilDivSIOp::fold (#90947)
The folder for arith::CeilDivSIOp should only be applied when it can be
guaranteed that no overflow would happen. The current implementation
works fine when both dividends are positive and the only arithmetic
operation is the division itself.
However, in cases where either the dividend or divisor is negative (or
both),
the division is split into multiple arith operations, e.g.: `- ( -a /
b)`. That's
additional 2 operations on top of the actual division that can overflow
- the folder should check all 3 ops for overflow.
The current logic doesn't do that - it effectively only checks the last
operation
(i.e. the division). It breaks when using e.g. MININT values (e.g. -128
for
8-bit integers) - negating such values overflows.
This PR makes sure that no folding happens if any of the intermediate
arithmetic operations overflows.
Fixes https://github.com/llvm/llvm-project/issues/89382
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