[Mlir-commits] [mlir] [mlir] Don't assert when simplifying certain `AffineExpr`s (PR #78855)

Felix Schneider llvmlistbot at llvm.org
Sat Jan 20 10:09:44 PST 2024


https://github.com/ubfx created https://github.com/llvm/llvm-project/pull/78855

Currently, `simplifyMul()` asserts that either `lhs` or `rhs` is symbolic or constant. This method is called by the overloaded `*` operator for `AffineExpr`s which leads to a crash when building a multiplication expression where neither operand is symbolic or constant.
This patch returns a `nullptr` from `simplifyMul()` to signal that the expression could not be simplified instead.

Fix https://github.com/llvm/llvm-project/issues/75770

>From ba7b34bd51ac96b83660bb927f276b6dc39ec290 Mon Sep 17 00:00:00 2001
From: Felix Schneider <fx.schn at gmail.com>
Date: Sat, 20 Jan 2024 19:05:23 +0100
Subject: [PATCH] [mlir] Don't assert when simplifying certain `AffineExpr`s

Currently, `simplifyMul()` asserts that either `lhs` or `rhs`
is symbolic or constant. This method is called by the
overloaded `*` operator for `AffineExpr`s which leads to a crash
when building a multiplication expression where neither operand
is symbolic or constant.
This patch returns a `nullptr` from `simplifyMul()` to signal that
the expression could not be simplified instead.

Fix https://github.com/llvm/llvm-project/issues/75770
---
 mlir/lib/IR/AffineExpr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp
index a90b264a8edd26..77c8fcc96d0ea0 100644
--- a/mlir/lib/IR/AffineExpr.cpp
+++ b/mlir/lib/IR/AffineExpr.cpp
@@ -774,7 +774,8 @@ static AffineExpr simplifyMul(AffineExpr lhs, AffineExpr rhs) {
     return getAffineConstantExpr(lhsConst.getValue() * rhsConst.getValue(),
                                  lhs.getContext());
 
-  assert(lhs.isSymbolicOrConstant() || rhs.isSymbolicOrConstant());
+  if (!lhs.isSymbolicOrConstant() && !rhs.isSymbolicOrConstant())
+    return nullptr;
 
   // Canonicalize the mul expression so that the constant/symbolic term is the
   // RHS. If both the lhs and rhs are symbolic, swap them if the lhs is a



More information about the Mlir-commits mailing list