[llvm] r309739 - [Value Tracking] Default argument to true and rename accordingly. NFC.

Chad Rosier via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 13:18:54 PDT 2017


Author: mcrosier
Date: Tue Aug  1 13:18:54 2017
New Revision: 309739

URL: http://llvm.org/viewvc/llvm-project?rev=309739&view=rev
Log:
[Value Tracking] Default argument to true and rename accordingly. NFC.

IMHO this is a bit more readable.

Modified:
    llvm/trunk/include/llvm/Analysis/ValueTracking.h
    llvm/trunk/lib/Analysis/ValueTracking.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
    llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=309739&r1=309738&r2=309739&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Tue Aug  1 13:18:54 2017
@@ -528,8 +528,7 @@ template <typename T> class ArrayRef;
   ///  F | T | T
   /// (A)
   Optional<bool> isImpliedCondition(const Value *LHS, const Value *RHS,
-                                    const DataLayout &DL,
-                                    bool LHSIsFalse = false,
+                                    const DataLayout &DL, bool LHSIsTrue = true,
                                     unsigned Depth = 0);
 } // end namespace llvm
 

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=309739&r1=309738&r2=309739&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Tue Aug  1 13:18:54 2017
@@ -4452,14 +4452,14 @@ isImpliedCondMatchingImmOperands(CmpInst
 /// false.  Otherwise, return None if we can't infer anything.
 static Optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
                                          const ICmpInst *RHS,
-                                         const DataLayout &DL, bool LHSIsFalse,
+                                         const DataLayout &DL, bool LHSIsTrue,
                                          unsigned Depth) {
   Value *ALHS = LHS->getOperand(0);
   Value *ARHS = LHS->getOperand(1);
   // The rest of the logic assumes the LHS condition is true.  If that's not the
   // case, invert the predicate to make it so.
   ICmpInst::Predicate APred =
-      LHSIsFalse ? LHS->getInversePredicate() : LHS->getPredicate();
+      LHSIsTrue ? LHS->getPredicate() : LHS->getInversePredicate();
 
   Value *BLHS = RHS->getOperand(0);
   Value *BRHS = RHS->getOperand(1);
@@ -4498,7 +4498,7 @@ static Optional<bool> isImpliedCondICmps
 /// RHS to be an icmp and the LHS to be an 'and' or an 'or' instruction.
 static Optional<bool> isImpliedCondAndOr(const BinaryOperator *LHS,
                                          const ICmpInst *RHS,
-                                         const DataLayout &DL, bool LHSIsFalse,
+                                         const DataLayout &DL, bool LHSIsTrue,
                                          unsigned Depth) {
   // The LHS must be an 'or' or an 'and' instruction.
   assert((LHS->getOpcode() == Instruction::And ||
@@ -4513,14 +4513,14 @@ static Optional<bool> isImpliedCondAndOr
   // false.  Similarly, if the result of an 'and' is true, then we know both
   // legs of the 'and' are true.
   Value *ALHS, *ARHS;
-  if ((LHSIsFalse && match(LHS, m_Or(m_Value(ALHS), m_Value(ARHS)))) ||
-      (!LHSIsFalse && match(LHS, m_And(m_Value(ALHS), m_Value(ARHS))))) {
+  if ((!LHSIsTrue && match(LHS, m_Or(m_Value(ALHS), m_Value(ARHS)))) ||
+      (LHSIsTrue && match(LHS, m_And(m_Value(ALHS), m_Value(ARHS))))) {
     // FIXME: Make this non-recursion.
     if (Optional<bool> Implication =
-            isImpliedCondition(ALHS, RHS, DL, LHSIsFalse, Depth + 1))
+            isImpliedCondition(ALHS, RHS, DL, LHSIsTrue, Depth + 1))
       return Implication;
     if (Optional<bool> Implication =
-            isImpliedCondition(ARHS, RHS, DL, LHSIsFalse, Depth + 1))
+            isImpliedCondition(ARHS, RHS, DL, LHSIsTrue, Depth + 1))
       return Implication;
     return None;
   }
@@ -4528,7 +4528,7 @@ static Optional<bool> isImpliedCondAndOr
 }
 
 Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
-                                        const DataLayout &DL, bool LHSIsFalse,
+                                        const DataLayout &DL, bool LHSIsTrue,
                                         unsigned Depth) {
   // A mismatch occurs when we compare a scalar cmp to a vector cmp, for
   // example.
@@ -4540,7 +4540,7 @@ Optional<bool> llvm::isImpliedCondition(
 
   // LHS ==> RHS by definition
   if (LHS == RHS)
-    return !LHSIsFalse;
+    return LHSIsTrue;
 
   // FIXME: Extending the code below to handle vectors.
   if (OpTy->isVectorTy())
@@ -4552,7 +4552,7 @@ Optional<bool> llvm::isImpliedCondition(
   const ICmpInst *LHSCmp = dyn_cast<ICmpInst>(LHS);
   const ICmpInst *RHSCmp = dyn_cast<ICmpInst>(RHS);
   if (LHSCmp && RHSCmp)
-    return isImpliedCondICmps(LHSCmp, RHSCmp, DL, LHSIsFalse, Depth);
+    return isImpliedCondICmps(LHSCmp, RHSCmp, DL, LHSIsTrue, Depth);
 
   // The LHS should be an 'or' or an 'and' instruction.  We expect the RHS to be
   // an icmp. FIXME: Add support for and/or on the RHS.
@@ -4560,7 +4560,7 @@ Optional<bool> llvm::isImpliedCondition(
   if (LHSBO && RHSCmp) {
     if ((LHSBO->getOpcode() == Instruction::And ||
          LHSBO->getOpcode() == Instruction::Or))
-      return isImpliedCondAndOr(LHSBO, RHSCmp, DL, LHSIsFalse, Depth);
+      return isImpliedCondAndOr(LHSBO, RHSCmp, DL, LHSIsTrue, Depth);
   }
   return None;
 }

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=309739&r1=309738&r2=309739&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Tue Aug  1 13:18:54 2017
@@ -1531,9 +1531,9 @@ Instruction *InstCombiner::visitSelectIn
     if (PBI && PBI->isConditional() &&
         PBI->getSuccessor(0) != PBI->getSuccessor(1) &&
         (PBI->getSuccessor(0) == Parent || PBI->getSuccessor(1) == Parent)) {
-      bool CondIsFalse = PBI->getSuccessor(1) == Parent;
+      bool CondIsTrue = PBI->getSuccessor(0) == Parent;
       Optional<bool> Implication = isImpliedCondition(
-        PBI->getCondition(), SI.getCondition(), DL, CondIsFalse);
+          PBI->getCondition(), SI.getCondition(), DL, CondIsTrue);
       if (Implication) {
         Value *V = *Implication ? TrueVal : FalseVal;
         return replaceInstUsesWith(SI, V);

Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=309739&r1=309738&r2=309739&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Tue Aug  1 13:18:54 2017
@@ -1036,9 +1036,9 @@ bool JumpThreadingPass::ProcessImpliedCo
     if (PBI->getSuccessor(0) != CurrentBB && PBI->getSuccessor(1) != CurrentBB)
       return false;
 
-    bool FalseDest = PBI->getSuccessor(1) == CurrentBB;
+    bool CondIsTrue = PBI->getSuccessor(0) == CurrentBB;
     Optional<bool> Implication =
-      isImpliedCondition(PBI->getCondition(), Cond, DL, FalseDest);
+        isImpliedCondition(PBI->getCondition(), Cond, DL, CondIsTrue);
     if (Implication) {
       BI->getSuccessor(*Implication ? 1 : 0)->removePredecessor(BB);
       BranchInst::Create(BI->getSuccessor(*Implication ? 0 : 1), BI);
@@ -2331,8 +2331,7 @@ bool JumpThreadingPass::ThreadGuard(Basi
     TrueDestIsSafe = true;
   else {
     // False dest is safe if !BranchCond => GuardCond.
-    Impl =
-        isImpliedCondition(BranchCond, GuardCond, DL, /* InvertAPred */ true);
+    Impl = isImpliedCondition(BranchCond, GuardCond, DL, /* LHSIsTrue */ false);
     if (Impl && *Impl)
       FalseDestIsSafe = true;
   }

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=309739&r1=309738&r2=309739&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug  1 13:18:54 2017
@@ -5761,9 +5761,9 @@ bool SimplifyCFGOpt::SimplifyCondBranch(
     if (PBI && PBI->isConditional() &&
         PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
       assert(PBI->getSuccessor(0) == BB || PBI->getSuccessor(1) == BB);
-      bool CondIsFalse = PBI->getSuccessor(1) == BB;
+      bool CondIsTrue = PBI->getSuccessor(0) == BB;
       Optional<bool> Implication = isImpliedCondition(
-          PBI->getCondition(), BI->getCondition(), DL, CondIsFalse);
+          PBI->getCondition(), BI->getCondition(), DL, CondIsTrue);
       if (Implication) {
         // Turn this into a branch on constant.
         auto *OldCond = BI->getCondition();




More information about the llvm-commits mailing list