[Mlir-commits] [mlir] [arith][mlir] Fixed a bug in CeilDiv with neg values (PR #90855)
Balaji V. Iyer.
llvmlistbot at llvm.org
Thu May 2 13:23:01 PDT 2024
================
@@ -652,16 +652,15 @@ OpFoldResult arith::CeilDivSIOp::fold(FoldAdaptor adaptor) {
APInt posB = zero.ssub_ov(b, overflowOrDiv0);
return signedCeilNonnegInputs(posA, posB, overflowOrDiv0);
}
- if (!aGtZero && bGtZero) {
- // A is negative, b is positive, return - ( -a / b).
- APInt posA = zero.ssub_ov(a, overflowOrDiv0);
- APInt div = posA.sdiv_ov(b, overflowOrDiv0);
- return zero.ssub_ov(div, overflowOrDiv0);
- }
- // A is positive, b is negative, return - (a / -b).
- APInt posB = zero.ssub_ov(b, overflowOrDiv0);
- APInt div = a.sdiv_ov(posB, overflowOrDiv0);
- return zero.ssub_ov(div, overflowOrDiv0);
+ // If either divisor or dividend is negative, then take their absolute
+ // value and then do a normal signedCeil Division, but add 1 to bring
+ // the quotient down. In essense, Ceil Division with one of the values
+ // negative works like a floorDivision with negated quotient.
----------------
bviyer wrote:
Actually its just `(abs(a)/abs(b))` T
https://github.com/llvm/llvm-project/pull/90855
More information about the Mlir-commits
mailing list