[llvm] r268651 - [ValueTracking] Early exit when further analysis won't be fruitful.

Chad Rosier via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 10:41:19 PDT 2016


Author: mcrosier
Date: Thu May  5 12:41:19 2016
New Revision: 268651

URL: http://llvm.org/viewvc/llvm-project?rev=268651&view=rev
Log:
[ValueTracking] Early exit when further analysis won't be fruitful.

This should have NFC in the context of codegen, but may have positive
implications on compile-time.

Modified:
    llvm/trunk/lib/Analysis/ValueTracking.cpp

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=268651&r1=268650&r2=268651&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Thu May  5 12:41:19 2016
@@ -3922,19 +3922,24 @@ isImpliedCondOperands(CmpInst::Predicate
   }
 }
 
+/// Return true if the operands of the two compares match.  IsSwappedOps is true
+/// when the operands match, but are swapped.
+static bool isMatchingOps(Value *ALHS, Value *ARHS, Value *BLHS, Value *BRHS,
+                          bool &IsSwappedOps) {
+
+  bool IsMatchingOps = (ALHS == BLHS && ARHS == BRHS);
+  IsSwappedOps = (ALHS == BRHS && ARHS == BLHS);
+  return IsMatchingOps || IsSwappedOps;
+}
+
 /// Return true if "icmp1 APred ALHS ARHS" implies "icmp2 BPred BLHS BRHS" is
 /// true.  Return false if "icmp1 APred ALHS ARHS" implies "icmp2 BPred BLHS
 /// BRHS" is false.  Otherwise, return None if we can't infer anything.
 static Optional<bool> isImpliedCondMatchingOperands(CmpInst::Predicate APred,
                                                     Value *ALHS, Value *ARHS,
                                                     CmpInst::Predicate BPred,
-                                                    Value *BLHS, Value *BRHS) {
-  // The operands of the two compares must match.
-  bool IsMatchingOps = (ALHS == BLHS && ARHS == BRHS);
-  bool IsSwappedOps = (ALHS == BRHS && ARHS == BLHS);
-  if (!IsMatchingOps && !IsSwappedOps)
-    return None;
-
+                                                    Value *BLHS, Value *BRHS,
+                                                    bool IsSwappedOps) {
   // Canonicalize the operands so they're matching.
   if (IsSwappedOps) {
     std::swap(BLHS, BRHS);
@@ -4001,17 +4006,27 @@ Optional<bool> llvm::isImpliedCondition(
   if (InvertAPred)
     APred = CmpInst::getInversePredicate(APred);
 
-  Optional<bool> Implication =
-      isImpliedCondMatchingOperands(APred, ALHS, ARHS, BPred, BLHS, BRHS);
-  if (Implication)
-    return Implication;
+  // Can we infer anything when the two compares have matching operands?
+  bool IsSwappedOps;
+  if (isMatchingOps(ALHS, ARHS, BLHS, BRHS, IsSwappedOps)) {
+    if (Optional<bool> Implication = isImpliedCondMatchingOperands(
+            APred, ALHS, ARHS, BPred, BLHS, BRHS, IsSwappedOps))
+      return Implication;
+    // No amount of additional analysis will infer the second condition, so
+    // early exit.
+    return None;
+  }
 
+  // Can we infer anything when the LHS operands match and the RHS operands are
+  // constants (not necessarily matching)?
   if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
-    Implication =
-        isImpliedCondMatchingImmOperands(APred, ALHS, cast<ConstantInt>(ARHS),
-                                         BPred, BLHS, cast<ConstantInt>(BRHS));
-    if (Implication)
+    if (Optional<bool> Implication = isImpliedCondMatchingImmOperands(
+            APred, ALHS, cast<ConstantInt>(ARHS), BPred, BLHS,
+            cast<ConstantInt>(BRHS)))
       return Implication;
+    // No amount of additional analysis will infer the second condition, so
+    // early exit.
+    return None;
   }
 
   if (APred == BPred)




More information about the llvm-commits mailing list