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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Jan 20 10:10:12 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-core

Author: Felix Schneider (ubfx)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/78855.diff


1 Files Affected:

- (modified) mlir/lib/IR/AffineExpr.cpp (+2-1) 


``````````diff
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

``````````

</details>


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


More information about the Mlir-commits mailing list