[llvm] 28b31d9 - [ValueLattice] Move getCompare() out of line (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 2 02:43:14 PDT 2022


Author: Nikita Popov
Date: 2022-11-02T10:33:44+01:00
New Revision: 28b31d9ccc2420f4cb6fdaeb5630e63f502b810c

URL: https://github.com/llvm/llvm-project/commit/28b31d9ccc2420f4cb6fdaeb5630e63f502b810c
DIFF: https://github.com/llvm/llvm-project/commit/28b31d9ccc2420f4cb6fdaeb5630e63f502b810c.diff

LOG: [ValueLattice] Move getCompare() out of line (NFC)

This is a fairly large method that is unlikely to benefit from
inlining.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ValueLattice.h b/llvm/include/llvm/Analysis/ValueLattice.h
index 7fe45d9f4dc9..50419f32702b 100644
--- a/llvm/include/llvm/Analysis/ValueLattice.h
+++ b/llvm/include/llvm/Analysis/ValueLattice.h
@@ -452,43 +452,7 @@ class ValueLatticeElement {
   /// true, false or undef constants, or nullptr if the comparison cannot be
   /// evaluated.
   Constant *getCompare(CmpInst::Predicate Pred, Type *Ty,
-                       const ValueLatticeElement &Other) const {
-    // Not yet resolved.
-    if (isUnknown() || Other.isUnknown())
-      return nullptr;
-
-    // TODO: Can be made more precise, but always returning undef would be
-    // incorrect.
-    if (isUndef() || isUndef())
-      return nullptr;
-
-    if (isConstant() && Other.isConstant())
-      return ConstantExpr::getCompare(Pred, getConstant(), Other.getConstant());
-
-    if (ICmpInst::isEquality(Pred)) {
-      // not(C) != C => true, not(C) == C => false.
-      if ((isNotConstant() && Other.isConstant() &&
-           getNotConstant() == Other.getConstant()) ||
-          (isConstant() && Other.isNotConstant() &&
-           getConstant() == Other.getNotConstant()))
-        return Pred == ICmpInst::ICMP_NE
-            ? ConstantInt::getTrue(Ty) : ConstantInt::getFalse(Ty);
-    }
-
-    // Integer constants are represented as ConstantRanges with single
-    // elements.
-    if (!isConstantRange() || !Other.isConstantRange())
-      return nullptr;
-
-    const auto &CR = getConstantRange();
-    const auto &OtherCR = Other.getConstantRange();
-    if (CR.icmp(Pred, OtherCR))
-      return ConstantInt::getTrue(Ty);
-    if (CR.icmp(CmpInst::getInversePredicate(Pred), OtherCR))
-      return ConstantInt::getFalse(Ty);
-
-    return nullptr;
-  }
+                       const ValueLatticeElement &Other) const;
 
   unsigned getNumRangeExtensions() const { return NumRangeExtensions; }
   void setNumRangeExtensions(unsigned N) { NumRangeExtensions = N; }

diff  --git a/llvm/lib/Analysis/ValueLattice.cpp b/llvm/lib/Analysis/ValueLattice.cpp
index 627166e2409d..a1c0286495c5 100644
--- a/llvm/lib/Analysis/ValueLattice.cpp
+++ b/llvm/lib/Analysis/ValueLattice.cpp
@@ -9,6 +9,46 @@
 #include "llvm/Analysis/ValueLattice.h"
 
 namespace llvm {
+Constant *
+ValueLatticeElement::getCompare(CmpInst::Predicate Pred, Type *Ty,
+                                const ValueLatticeElement &Other) const {
+  // Not yet resolved.
+  if (isUnknown() || Other.isUnknown())
+    return nullptr;
+
+  // TODO: Can be made more precise, but always returning undef would be
+  // incorrect.
+  if (isUndef() || isUndef())
+    return nullptr;
+
+  if (isConstant() && Other.isConstant())
+    return ConstantExpr::getCompare(Pred, getConstant(), Other.getConstant());
+
+  if (ICmpInst::isEquality(Pred)) {
+    // not(C) != C => true, not(C) == C => false.
+    if ((isNotConstant() && Other.isConstant() &&
+         getNotConstant() == Other.getConstant()) ||
+        (isConstant() && Other.isNotConstant() &&
+         getConstant() == Other.getNotConstant()))
+      return Pred == ICmpInst::ICMP_NE ? ConstantInt::getTrue(Ty)
+                                       : ConstantInt::getFalse(Ty);
+  }
+
+  // Integer constants are represented as ConstantRanges with single
+  // elements.
+  if (!isConstantRange() || !Other.isConstantRange())
+    return nullptr;
+
+  const auto &CR = getConstantRange();
+  const auto &OtherCR = Other.getConstantRange();
+  if (CR.icmp(Pred, OtherCR))
+    return ConstantInt::getTrue(Ty);
+  if (CR.icmp(CmpInst::getInversePredicate(Pred), OtherCR))
+    return ConstantInt::getFalse(Ty);
+
+  return nullptr;
+}
+
 raw_ostream &operator<<(raw_ostream &OS, const ValueLatticeElement &Val) {
   if (Val.isUnknown())
     return OS << "unknown";


        


More information about the llvm-commits mailing list