[ConstraintSystem] Remove GCD handling (NFCI).

As @dtcxzyw pointed out in
https://github.com/llvm/llvm-project/pull/76299#pullrequestreview-1795471115
the current GCD handling is effectively a no-op, as NewGCD will always
by 1, as it is initially initialized as 1.

This patch removes the uses of GCD and its computation. This slightly
reduces compile-time [1], while not causing any binary changes (due to always
dividing by 1) in the large test-set I checked.

Division by GCD could be added in the future again and it in theory
should help reduce overflows by normalizing the coefficients (sketched
in cadbfdf8605e743e092217c54e2b837245a0a330), but this also doesn't seem
to have much (any) impact in practice.

[1] https://llvm-compile-time-tracker.com/compare.php?from=0de030e4dcb798228731ab25d4dd31df4dcaba2b&to=cadbfdf8605e743e092217c54e2b837245a0a330&stat=instructions:u
This commit is contained in:
Florian Hahn
2023-12-28 15:22:23 +00:00
parent a49cf6c14a
commit 9b6127d76d
2 changed files with 2 additions and 15 deletions

View File

@@ -54,9 +54,6 @@ class ConstraintSystem {
/// constraint system.
DenseMap<Value *, unsigned> Value2Index;
/// Current greatest common divisor for all coefficients in the system.
uint32_t GCD = 1;
// Eliminate constraints from the system using FourierMotzkin elimination.
bool eliminateUsingFM();
@@ -88,10 +85,6 @@ public:
for (const auto &[Idx, C] : enumerate(R)) {
if (C == 0)
continue;
auto A = std::abs(C);
GCD = APIntOps::GreatestCommonDivisor({32, (uint32_t)A}, {32, GCD})
.getZExtValue();
NewRow.emplace_back(C, Idx);
}
if (Constraints.empty())

View File

@@ -29,7 +29,6 @@ bool ConstraintSystem::eliminateUsingFM() {
assert(!Constraints.empty() &&
"should only be called for non-empty constraint systems");
uint32_t NewGCD = 1;
unsigned LastIdx = NumVariables - 1;
// First, either remove the variable in place if it is 0 or add the row to
@@ -96,24 +95,20 @@ bool ConstraintSystem::eliminateUsingFM() {
IdxUpper++;
}
if (MulOverflow(UpperV, ((-1) * LowerLast / GCD), M1))
if (MulOverflow(UpperV, ((-1) * LowerLast), M1))
return false;
if (IdxLower < LowerRow.size() && LowerRow[IdxLower].Id == CurrentId) {
LowerV = LowerRow[IdxLower].Coefficient;
IdxLower++;
}
if (MulOverflow(LowerV, (UpperLast / GCD), M2))
if (MulOverflow(LowerV, (UpperLast), M2))
return false;
if (AddOverflow(M1, M2, N))
return false;
if (N == 0)
continue;
NR.emplace_back(N, CurrentId);
NewGCD =
APIntOps::GreatestCommonDivisor({32, (uint32_t)N}, {32, NewGCD})
.getZExtValue();
}
if (NR.empty())
continue;
@@ -124,7 +119,6 @@ bool ConstraintSystem::eliminateUsingFM() {
}
}
NumVariables -= 1;
GCD = NewGCD;
return true;
}