[llvm] 9b6127d - [ConstraintSystem] Remove GCD handling (NFCI).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 28 07:22:57 PST 2023


Author: Florian Hahn
Date: 2023-12-28T15:22:23Z
New Revision: 9b6127d76db7b77f8a2c16191860cb30fb8da4b1

URL: https://github.com/llvm/llvm-project/commit/9b6127d76db7b77f8a2c16191860cb30fb8da4b1
DIFF: https://github.com/llvm/llvm-project/commit/9b6127d76db7b77f8a2c16191860cb30fb8da4b1.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/ConstraintSystem.h
    llvm/lib/Analysis/ConstraintSystem.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ConstraintSystem.h b/llvm/include/llvm/Analysis/ConstraintSystem.h
index 5d3bc64bf8b4b2..7b02b618f7cb44 100644
--- a/llvm/include/llvm/Analysis/ConstraintSystem.h
+++ b/llvm/include/llvm/Analysis/ConstraintSystem.h
@@ -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 Fourier–Motzkin elimination.
   bool eliminateUsingFM();
 
@@ -88,10 +85,6 @@ class ConstraintSystem {
     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())

diff  --git a/llvm/lib/Analysis/ConstraintSystem.cpp b/llvm/lib/Analysis/ConstraintSystem.cpp
index 8a802515b6f4fb..35bdd869a88d1a 100644
--- a/llvm/lib/Analysis/ConstraintSystem.cpp
+++ b/llvm/lib/Analysis/ConstraintSystem.cpp
@@ -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;
 }


        


More information about the llvm-commits mailing list