[llvm] 902db4e - [ConstraintElimination] Move some definitions closer to uses (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 9 09:30:07 PST 2022


Author: Florian Hahn
Date: 2022-02-09T17:29:49Z
New Revision: 902db4ec1cb9cab8743ef985ba214ee917bc2a09

URL: https://github.com/llvm/llvm-project/commit/902db4ec1cb9cab8743ef985ba214ee917bc2a09
DIFF: https://github.com/llvm/llvm-project/commit/902db4ec1cb9cab8743ef985ba214ee917bc2a09.diff

LOG: [ConstraintElimination] Move some definitions closer to uses (NFC).

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 2a71830ced5a..27a275ed59dc 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -247,23 +247,6 @@ static ConstraintListTy
 getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
               const DenseMap<Value *, unsigned> &Value2Index,
               DenseMap<Value *, unsigned> &NewIndices) {
-  int64_t Offset1 = 0;
-  int64_t Offset2 = 0;
-
-  SmallVector<PreconditionTy, 4> Preconditions;
-  // First try to look up \p V in Value2Index and NewIndices. Otherwise add a
-  // new entry to NewIndices.
-  auto GetOrAddIndex = [&Value2Index, &NewIndices](Value *V) -> unsigned {
-    auto V2I = Value2Index.find(V);
-    if (V2I != Value2Index.end())
-      return V2I->second;
-    auto NewI = NewIndices.find(V);
-    if (NewI != NewIndices.end())
-      return NewI->second;
-    auto Insert =
-        NewIndices.insert({V, Value2Index.size() + NewIndices.size() + 1});
-    return Insert.first->second;
-  };
 
   if (Pred == CmpInst::ICMP_UGT || Pred == CmpInst::ICMP_UGE ||
       Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_SGE)
@@ -292,6 +275,7 @@ getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
       Pred != CmpInst::ICMP_SLE && Pred != CmpInst::ICMP_SLT)
     return {};
 
+  SmallVector<PreconditionTy, 4> Preconditions;
   bool IsSigned = CmpInst::isSigned(Pred);
   auto ADec = decompose(Op0->stripPointerCastsSameRepresentation(),
                         Preconditions, IsSigned);
@@ -305,14 +289,28 @@ getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
   if (ADec.size() == 1 && BDec.size() == 1)
     return {};
 
-  Offset1 = ADec[0].first;
-  Offset2 = BDec[0].first;
+  int64_t Offset1 = ADec[0].first;
+  int64_t Offset2 = BDec[0].first;
   Offset1 *= -1;
 
   // Create iterator ranges that skip the constant-factor.
   auto VariablesA = llvm::drop_begin(ADec);
   auto VariablesB = llvm::drop_begin(BDec);
 
+  // First try to look up \p V in Value2Index and NewIndices. Otherwise add a
+  // new entry to NewIndices.
+  auto GetOrAddIndex = [&Value2Index, &NewIndices](Value *V) -> unsigned {
+    auto V2I = Value2Index.find(V);
+    if (V2I != Value2Index.end())
+      return V2I->second;
+    auto NewI = NewIndices.find(V);
+    if (NewI != NewIndices.end())
+      return NewI->second;
+    auto Insert =
+        NewIndices.insert({V, Value2Index.size() + NewIndices.size() + 1});
+    return Insert.first->second;
+  };
+
   // Make sure all variables have entries in Value2Index or NewIndices.
   for (const auto &KV :
        concat<std::pair<int64_t, Value *>>(VariablesA, VariablesB))


        


More information about the llvm-commits mailing list