[Mlir-commits] [mlir] [mlir][affine] remove divide zero check when simplifer affineMap (#64622) (PR #68519)

Jakub Kuderski llvmlistbot at llvm.org
Mon Oct 30 10:29:51 PDT 2023


================
@@ -57,13 +60,34 @@ class AffineExprConstantFolder {
           expr, [](int64_t lhs, int64_t rhs) { return lhs * rhs; });
     case AffineExprKind::Mod:
       return constantFoldBinExpr(
-          expr, [](int64_t lhs, int64_t rhs) { return mod(lhs, rhs); });
+          expr,
+          [expr, this](int64_t lhs, int64_t rhs) -> std::optional<int64_t> {
+            if (rhs < 1) {
+              hasPoison_ = true;
+              return std::nullopt;
+            }
+            return mod(lhs, rhs);
+          });
     case AffineExprKind::FloorDiv:
       return constantFoldBinExpr(
-          expr, [](int64_t lhs, int64_t rhs) { return floorDiv(lhs, rhs); });
+          expr,
+          [expr, this](int64_t lhs, int64_t rhs) -> std::optional<int64_t> {
+            if (0 == rhs) {
----------------
kuhar wrote:

It looks unusual. Why would you do that? If that's to guard against accidental assignment, the warnings enabled by default in llvm already enforce that assignments are wrapped with an extra layer of parens.

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


More information about the Mlir-commits mailing list