Skip to content

[mlir] Don't assert when simplifying certain AffineExprs #78855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mlir/lib/IR/AffineExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions mlir/unittests/IR/AffineExprTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===- AffineExprTest.cpp - unit tests for affine expression API ----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/Builders.h"
#include "gtest/gtest.h"

using namespace mlir;

// Test creating AffineExprs using the overloaded binary operators.
TEST(AffineExprTest, constructFromBinaryOperators) {
MLIRContext ctx;
OpBuilder b(&ctx);

auto d0 = b.getAffineDimExpr(0);
auto d1 = b.getAffineDimExpr(1);

auto sum = d0 + d1;
auto difference = d0 - d1;
auto product = d0 * d1;
auto remainder = d0 % d1;

ASSERT_EQ(sum.getKind(), AffineExprKind::Add);
ASSERT_EQ(difference.getKind(), AffineExprKind::Add);
ASSERT_EQ(product.getKind(), AffineExprKind::Mul);
ASSERT_EQ(remainder.getKind(), AffineExprKind::Mod);
}
1 change: 1 addition & 0 deletions mlir/unittests/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_mlir_unittest(MLIRIRTests
AdaptorTest.cpp
AffineExprTest.cpp
AffineMapTest.cpp
AttributeTest.cpp
DialectTest.cpp
Expand Down