mirror of
https://github.com/intel/llvm.git
synced 2026-02-03 10:39:35 +08:00
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:
committed by
GitHub
parent
430b254503
commit
528a662d3a
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user