[Mlir-commits] [mlir] 528a662 - Fix sign of largest known divisor of div. (#100081)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jul 23 01:55:36 PDT 2024
Author: Johannes Reifferscheid
Date: 2024-07-23T10:55:32+02:00
New Revision: 528a662d3a1e28c3bd4fe2d54bc73506b68ddc4e
URL: https://github.com/llvm/llvm-project/commit/528a662d3a1e28c3bd4fe2d54bc73506b68ddc4e
DIFF: https://github.com/llvm/llvm-project/commit/528a662d3a1e28c3bd4fe2d54bc73506b68ddc4e.diff
LOG: Fix sign of largest known divisor of div. (#100081)
There's a missing abs, so it returns a negative value if the divisor is
negative. Later this is then cast to uint.
Added:
Modified:
mlir/lib/IR/AffineExpr.cpp
mlir/unittests/IR/AffineExprTest.cpp
Removed:
################################################################################
diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp
index 75cc01ee9a146..7978b35e7147d 100644
--- a/mlir/lib/IR/AffineExpr.cpp
+++ b/mlir/lib/IR/AffineExpr.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include <cmath>
#include <cstdint>
#include <limits>
#include <utility>
@@ -257,7 +258,7 @@ int64_t AffineExpr::getLargestKnownDivisor() const {
if (rhs && rhs.getValue() != 0) {
int64_t lhsDiv = binExpr.getLHS().getLargestKnownDivisor();
if (lhsDiv % rhs.getValue() == 0)
- return lhsDiv / rhs.getValue();
+ return std::abs(lhsDiv / rhs.getValue());
}
return 1;
}
diff --git a/mlir/unittests/IR/AffineExprTest.cpp b/mlir/unittests/IR/AffineExprTest.cpp
index 75c893334943d..dc78bbac85f3c 100644
--- a/mlir/unittests/IR/AffineExprTest.cpp
+++ b/mlir/unittests/IR/AffineExprTest.cpp
@@ -106,3 +106,9 @@ TEST(AffineExprTest, modSimplificationRegression) {
auto sum = d0 + d0.floorDiv(3).floorDiv(-3);
ASSERT_EQ(sum.getKind(), AffineExprKind::Add);
}
+
+TEST(AffineExprTest, divisorOfNegativeFloorDiv) {
+ MLIRContext ctx;
+ OpBuilder b(&ctx);
+ ASSERT_EQ(b.getAffineDimExpr(0).floorDiv(-1).getLargestKnownDivisor(), 1);
+}
More information about the Mlir-commits
mailing list