[llvm] r277479 - [LVI] NFC. Sink a condition type check from the caller down to getValueFromCondition

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 09:20:48 PDT 2016


Author: apilipenko
Date: Tue Aug  2 11:20:48 2016
New Revision: 277479

URL: http://llvm.org/viewvc/llvm-project?rev=277479&view=rev
Log:
[LVI] NFC. Sink a condition type check from the caller down to getValueFromCondition

This is a preparatory refactoring to support conditions other than ICmpInst.

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=277479&r1=277478&r2=277479&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Tue Aug  2 11:20:48 2016
@@ -859,7 +859,7 @@ bool LazyValueInfoCache::solveBlockValue
   return true;
 }
 
-static bool getValueFromCondition(Value *Val, ICmpInst *ICI,
+static bool getValueFromCondition(Value *Val, Value *Cond,
                                   LVILatticeVal &Result,
                                   bool isTrueDest = true);
 
@@ -879,12 +879,9 @@ void LazyValueInfoCache::intersectAssume
     if (!isValidAssumeForContext(I, BBI, DT))
       continue;
 
-    Value *C = I->getArgOperand(0);
-    if (ICmpInst *ICI = dyn_cast<ICmpInst>(C)) {
-      LVILatticeVal Result;
-      if (getValueFromCondition(Val, ICI, Result))
-        BBLV = intersect(BBLV, Result);
-    }
+    LVILatticeVal Result;
+    if (getValueFromCondition(Val, I->getArgOperand(0), Result))
+      BBLV = intersect(BBLV, Result);
   }
 }
 
@@ -954,25 +951,25 @@ bool LazyValueInfoCache::solveBlockValue
   // Can we constrain the facts about the true and false values by using the
   // 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.
-  if (auto *ICI = dyn_cast<ICmpInst>(SI->getCondition())) {
-    LVILatticeVal TrueValTaken, FalseValTaken;
-    if (!getValueFromCondition(SI->getTrueValue(), ICI, TrueValTaken, true))
-      TrueValTaken.markOverdefined();
-    if (!getValueFromCondition(SI->getFalseValue(), ICI, FalseValTaken, false))
-      FalseValTaken.markOverdefined();
-
-    TrueVal = intersect(TrueVal, TrueValTaken);
-    FalseVal = intersect(FalseVal, FalseValTaken);
-
-
-    // Handle clamp idioms such as:
-    //   %24 = constantrange<0, 17>
-    //   %39 = icmp eq i32 %24, 0
-    //   %40 = add i32 %24, -1
-    //   %siv.next = select i1 %39, i32 16, i32 %40
-    //   %siv.next = constantrange<0, 17> not <-1, 17>
-    // In general, this can handle any clamp idiom which tests the edge
-    // condition via an equality or inequality.
+  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);
+
+  // Handle clamp idioms such as:
+  //   %24 = constantrange<0, 17>
+  //   %39 = icmp eq i32 %24, 0
+  //   %40 = add i32 %24, -1
+  //   %siv.next = select i1 %39, i32 16, i32 %40
+  //   %siv.next = constantrange<0, 17> not <-1, 17>
+  // In general, this can handle any clamp idiom which tests the edge
+  // condition via an equality or inequality.
+  if (auto *ICI = dyn_cast<ICmpInst>(Cond)) {
     ICmpInst::Predicate Pred = ICI->getPredicate();
     Value *A = ICI->getOperand(0);
     if (ConstantInt *CIBase = dyn_cast<ConstantInt>(ICI->getOperand(1))) {
@@ -1177,9 +1174,15 @@ bool LazyValueInfoCache::solveBlockValue
   return true;
 }
 
-bool getValueFromCondition(Value *Val, ICmpInst *ICI, LVILatticeVal &Result,
+bool getValueFromCondition(Value *Val, Value *Cond, LVILatticeVal &Result,
                            bool isTrueDest) {
-  assert(ICI && "precondition");
+  assert(Cond && "precondition");
+
+  // For now we only support ICmpInst conditions
+  ICmpInst *ICI = dyn_cast<ICmpInst>(Cond);
+  if (!ICI)
+    return false;
+
   if (isa<Constant>(ICI->getOperand(1))) {
     if (ICI->isEquality() && ICI->getOperand(0) == Val) {
       // We know that V has the RHS constant if this is a true SETEQ or
@@ -1245,9 +1248,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 (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition()))
-        if (getValueFromCondition(Val, ICI, Result, isTrueDest))
-          return true;
+      if (getValueFromCondition(Val, BI->getCondition(), Result, isTrueDest))
+        return true;
     }
   }
 




More information about the llvm-commits mailing list