From d82811df4de866d2eb74bc7227a4b1bd9e1d185b Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 5 Feb 2023 22:05:53 +0000 Subject: [PATCH] [ConstraintElim] Move some array accesses to variables (NFC). Move some accesses that are use multiple times to variables. This also will make updating them easier in the future. --- llvm/lib/Analysis/ConstraintSystem.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Analysis/ConstraintSystem.cpp b/llvm/lib/Analysis/ConstraintSystem.cpp index 883d1c4..633427e 100644 --- a/llvm/lib/Analysis/ConstraintSystem.cpp +++ b/llvm/lib/Analysis/ConstraintSystem.cpp @@ -36,7 +36,8 @@ bool ConstraintSystem::eliminateUsingFM() { for (unsigned R1 = 0; R1 < NumConstraints; R1++) { SmallVector &Row1 = Constraints[R1]; - if (Row1[LastIdx] == 0) { + int64_t LowerLast = Row1[LastIdx]; + if (LowerLast == 0) { Row1.pop_back(); NewSystem.push_back(std::move(Row1)); continue; @@ -47,35 +48,38 @@ bool ConstraintSystem::eliminateUsingFM() { if (R1 == R2) continue; + int64_t UpperLast = Constraints[R2][LastIdx]; // FIXME: can we do better than just dropping things here? - if (Constraints[R2][LastIdx] == 0) + if (UpperLast == 0) continue; - if ((Constraints[R1][LastIdx] < 0 && Constraints[R2][LastIdx] < 0) || - (Constraints[R1][LastIdx] > 0 && Constraints[R2][LastIdx] > 0)) + int64_t LowerLast = Constraints[R1][LastIdx]; + if ((LowerLast < 0 && UpperLast < 0) || (LowerLast > 0 && UpperLast > 0)) continue; unsigned LowerR = R1; unsigned UpperR = R2; - if (Constraints[UpperR][LastIdx] < 0) + if (UpperLast < 0) { std::swap(LowerR, UpperR); + std::swap(LowerLast, UpperLast); + } SmallVector NR; for (unsigned I = 0; I < LastIdx; I++) { int64_t M1, M2, N; - if (MulOverflow(Constraints[UpperR][I], - ((-1) * Constraints[LowerR][LastIdx] / GCD), M1)) + int64_t UpperV = Constraints[UpperR][I]; + if (MulOverflow(UpperV, ((-1) * LowerLast / GCD), M1)) return false; - if (MulOverflow(Constraints[LowerR][I], - (Constraints[UpperR][LastIdx] / GCD), M2)) + int64_t LowerV = Constraints[LowerR][I]; + if (MulOverflow(LowerV, (UpperLast / GCD), M2)) return false; if (AddOverflow(M1, M2, N)) return false; NR.push_back(N); - NewGCD = APIntOps::GreatestCommonDivisor({32, (uint32_t)NR.back()}, - {32, NewGCD}) - .getZExtValue(); + NewGCD = + APIntOps::GreatestCommonDivisor({32, (uint32_t)N}, {32, NewGCD}) + .getZExtValue(); } NewSystem.push_back(std::move(NR)); // Give up if the new system gets too big. -- 2.7.4