Skip to content

Commit 9b6127d

Browse files
committed
[ConstraintSystem] Remove GCD handling (NFCI).
As @dtcxzyw pointed out in #76299 (review) 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
1 parent a49cf6c commit 9b6127d

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

llvm/include/llvm/Analysis/ConstraintSystem.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class ConstraintSystem {
5454
/// constraint system.
5555
DenseMap<Value *, unsigned> Value2Index;
5656

57-
/// Current greatest common divisor for all coefficients in the system.
58-
uint32_t GCD = 1;
59-
6057
// Eliminate constraints from the system using Fourier–Motzkin elimination.
6158
bool eliminateUsingFM();
6259

@@ -88,10 +85,6 @@ class ConstraintSystem {
8885
for (const auto &[Idx, C] : enumerate(R)) {
8986
if (C == 0)
9087
continue;
91-
auto A = std::abs(C);
92-
GCD = APIntOps::GreatestCommonDivisor({32, (uint32_t)A}, {32, GCD})
93-
.getZExtValue();
94-
9588
NewRow.emplace_back(C, Idx);
9689
}
9790
if (Constraints.empty())

llvm/lib/Analysis/ConstraintSystem.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ bool ConstraintSystem::eliminateUsingFM() {
2929
assert(!Constraints.empty() &&
3030
"should only be called for non-empty constraint systems");
3131

32-
uint32_t NewGCD = 1;
3332
unsigned LastIdx = NumVariables - 1;
3433

3534
// First, either remove the variable in place if it is 0 or add the row to
@@ -96,24 +95,20 @@ bool ConstraintSystem::eliminateUsingFM() {
9695
IdxUpper++;
9796
}
9897

99-
if (MulOverflow(UpperV, ((-1) * LowerLast / GCD), M1))
98+
if (MulOverflow(UpperV, ((-1) * LowerLast), M1))
10099
return false;
101100
if (IdxLower < LowerRow.size() && LowerRow[IdxLower].Id == CurrentId) {
102101
LowerV = LowerRow[IdxLower].Coefficient;
103102
IdxLower++;
104103
}
105104

106-
if (MulOverflow(LowerV, (UpperLast / GCD), M2))
105+
if (MulOverflow(LowerV, (UpperLast), M2))
107106
return false;
108107
if (AddOverflow(M1, M2, N))
109108
return false;
110109
if (N == 0)
111110
continue;
112111
NR.emplace_back(N, CurrentId);
113-
114-
NewGCD =
115-
APIntOps::GreatestCommonDivisor({32, (uint32_t)N}, {32, NewGCD})
116-
.getZExtValue();
117112
}
118113
if (NR.empty())
119114
continue;
@@ -124,7 +119,6 @@ bool ConstraintSystem::eliminateUsingFM() {
124119
}
125120
}
126121
NumVariables -= 1;
127-
GCD = NewGCD;
128122

129123
return true;
130124
}

0 commit comments

Comments
 (0)