[llvm] [mlir] [mlir][arith] fix wrong floordivsi fold (#83079) (PR #83248)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 13:33:46 PDT 2024


================
@@ -2022,6 +2022,14 @@ APInt APInt::ushl_ov(unsigned ShAmt, bool &Overflow) const {
   return *this << ShAmt;
 }
 
+APInt APInt::sfloordiv_ov(const APInt &RHS, bool &Overflow) const {
+  auto quotient = sdiv_ov(RHS, Overflow);
+  if ((quotient * RHS != *this) && (isNegative() != RHS.isNegative()))
+    return quotient - 1;
+  else
+    return quotient;
----------------
dwblaikie wrote:

LLVM style encourages skipping else-after-return, so would be written as:
```
  return quotient - 1;
return quotient;
```

https://github.com/llvm/llvm-project/pull/83248


More information about the llvm-commits mailing list