[llvm] r278224 - [LVI] NFC. Make getValueFromCondition return LVILatticeValue instead of changing reference argument

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 10 06:38:08 PDT 2016


Author: apilipenko
Date: Wed Aug 10 08:38:07 2016
New Revision: 278224

URL: http://llvm.org/viewvc/llvm-project?rev=278224&view=rev
Log:
[LVI] NFC. Make getValueFromCondition return LVILatticeValue instead of changing reference argument

Instead of returning bool and setting LVILatticeValue reference argument return LVILattice value. Use overdefined value to denote the case when we didn't gather any information from the condition.

This change was separated from the review "[LVI] Handle conditions in the form of (cond1 && cond2)" (https://reviews.llvm.org/D23200#inline-199531). Once getValueFromCondition returns LVILatticeValue we can cache the result in Visited map.

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

Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=278224&r1=278223&r2=278224&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Wed Aug 10 08:38:07 2016
@@ -859,9 +859,8 @@ bool LazyValueInfoCache::solveBlockValue
   return true;
 }
 
-static bool getValueFromCondition(Value *Val, Value *Cond,
-                                  LVILatticeVal &Result,
-                                  bool isTrueDest = true);
+static LVILatticeVal getValueFromCondition(Value *Val, Value *Cond,
+                                           bool isTrueDest = true);
 
 // If we can determine a constraint on the value given conditions assumed by
 // the program, intersect those constraints with BBLV
@@ -879,9 +878,7 @@ void LazyValueInfoCache::intersectAssume
     if (!isValidAssumeForContext(I, BBI, DT))
       continue;
 
-    LVILatticeVal Result;
-    if (getValueFromCondition(Val, I->getArgOperand(0), Result))
-      BBLV = intersect(BBLV, Result);
+    BBLV = intersect(BBLV, getValueFromCondition(Val, I->getArgOperand(0)));
   }
 }
 
@@ -952,14 +949,10 @@ bool LazyValueInfoCache::solveBlockValue
   // condition itself?  This shows up with idioms like e.g. select(a > 5, a, 5).
   // TODO: We could potentially refine an overdefined true value above.
   Value *Cond = SI->getCondition();
-  LVILatticeVal TrueValTaken, FalseValTaken;
-  if (!getValueFromCondition(SI->getTrueValue(), Cond, TrueValTaken, true))
-    TrueValTaken.markOverdefined();
-  if (!getValueFromCondition(SI->getFalseValue(), Cond, FalseValTaken, false))
-    FalseValTaken.markOverdefined();
-
-  TrueVal = intersect(TrueVal, TrueValTaken);
-  FalseVal = intersect(FalseVal, FalseValTaken);
+  TrueVal = intersect(TrueVal,
+                      getValueFromCondition(SI->getTrueValue(), Cond, true));
+  FalseVal = intersect(FalseVal,
+                       getValueFromCondition(SI->getFalseValue(), Cond, false));
 
   // Handle clamp idioms such as:
   //   %24 = constantrange<0, 17>
@@ -1174,14 +1167,13 @@ bool LazyValueInfoCache::solveBlockValue
   return true;
 }
 
-bool getValueFromCondition(Value *Val, Value *Cond, LVILatticeVal &Result,
-                           bool isTrueDest) {
+LVILatticeVal getValueFromCondition(Value *Val, Value *Cond, bool isTrueDest) {
   assert(Cond && "precondition");
 
   // For now we only support ICmpInst conditions
   ICmpInst *ICI = dyn_cast<ICmpInst>(Cond);
   if (!ICI)
-    return false;
+    return LVILatticeVal::getOverdefined();
 
   Value *LHS = ICI->getOperand(0);
   Value *RHS = ICI->getOperand(1);
@@ -1192,15 +1184,14 @@ bool getValueFromCondition(Value *Val, V
       // We know that V has the RHS constant if this is a true SETEQ or
       // false SETNE.
       if (isTrueDest == (Predicate == ICmpInst::ICMP_EQ))
-        Result = LVILatticeVal::get(cast<Constant>(RHS));
+        return LVILatticeVal::get(cast<Constant>(RHS));
       else
-        Result = LVILatticeVal::getNot(cast<Constant>(RHS));
-      return true;
+        return LVILatticeVal::getNot(cast<Constant>(RHS));
     }
   }
 
   if (!Val->getType()->isIntegerTy())
-    return false;
+    return LVILatticeVal::getOverdefined();
 
   // Use ConstantRange::makeAllowedICmpRegion in order to determine the possible
   // range of Val guaranteed by the condition. Recognize comparisons in the from
@@ -1236,11 +1227,10 @@ bool getValueFromCondition(Value *Val, V
     if (Offset) // Apply the offset from above.
       TrueValues = TrueValues.subtract(Offset->getValue());
 
-    Result = LVILatticeVal::getRange(std::move(TrueValues));
-    return true;
+    return LVILatticeVal::getRange(std::move(TrueValues));
   }
 
-  return false;
+  return LVILatticeVal::getOverdefined();
 }
 
 /// \brief Compute the value of Val on the edge BBFrom -> BBTo. Returns false if
@@ -1269,7 +1259,8 @@ static bool getEdgeValueLocal(Value *Val
 
       // If the condition of the branch is an equality comparison, we may be
       // able to infer the value.
-      if (getValueFromCondition(Val, BI->getCondition(), Result, isTrueDest))
+      Result = getValueFromCondition(Val, BI->getCondition(), isTrueDest);
+      if (!Result.isOverdefined())
         return true;
     }
   }




More information about the llvm-commits mailing list