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.
This commit is contained in:
Johannes Reifferscheid
2024-07-23 10:55:32 +02:00
committed by GitHub
parent 430b254503
commit 528a662d3a
2 changed files with 8 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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);
}