[llvm] 2a9313e - [ConstraintElimination] Move logic to check condition to helper (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 02:50:51 PDT 2022


Author: Florian Hahn
Date: 2022-06-21T11:50:33+02:00
New Revision: 2a9313ee0b11d47c0972b47f86cfe225e96b84e2

URL: https://github.com/llvm/llvm-project/commit/2a9313ee0b11d47c0972b47f86cfe225e96b84e2
DIFF: https://github.com/llvm/llvm-project/commit/2a9313ee0b11d47c0972b47f86cfe225e96b84e2.diff

LOG: [ConstraintElimination] Move logic to check condition to helper (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 1fc2ed4fc70e0..9a574fa1eb24b 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -141,6 +141,8 @@ class ConstraintInfo {
     getCS(Signed).popLastNVariables(N);
   }
 
+  bool doesHold(CmpInst::Predicate Pred, Value *A, Value *B) const;
+
   void addFact(CmpInst *Condition, bool IsNegated, unsigned NumIn,
                unsigned NumOut, SmallVectorImpl<StackEntry> &DFSInStack);
 
@@ -364,16 +366,24 @@ ConstraintInfo::getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
 bool ConstraintTy::isValid(const ConstraintInfo &Info) const {
   return Coefficients.size() > 0 &&
          all_of(Preconditions, [&Info](const PreconditionTy &C) {
-           DenseMap<Value *, unsigned> NewIndices;
-           auto R = Info.getConstraint(C.Pred, C.Op0, C.Op1, NewIndices);
-           // TODO: properly check NewIndices.
-           return NewIndices.empty() && R.Preconditions.empty() && !R.IsEq &&
-                  R.size() >= 1 &&
-                  Info.getCS(CmpInst::isSigned(C.Pred))
-                      .isConditionImplied(R.Coefficients);
+           return Info.doesHold(C.Pred, C.Op0, C.Op1);
          });
 }
 
+bool ConstraintInfo::doesHold(CmpInst::Predicate Pred, Value *A,
+                              Value *B) const {
+  DenseMap<Value *, unsigned> NewIndices;
+  auto R = getConstraint(Pred, A, B, NewIndices);
+
+  if (!NewIndices.empty())
+    return false;
+
+  // TODO: properly check NewIndices.
+  return NewIndices.empty() && R.Preconditions.empty() && !R.IsEq &&
+         !R.empty() &&
+         getCS(CmpInst::isSigned(Pred)).isConditionImplied(R.Coefficients);
+}
+
 namespace {
 /// Represents either a condition that holds on entry to a block or a basic
 /// block, with their respective Dominator DFS in and out numbers.


        


More information about the llvm-commits mailing list