diff options
| author | Artur Pilipenko <apilipenko@azulsystems.com> | 2016-08-02 16:20:48 +0000 | 
|---|---|---|
| committer | Artur Pilipenko <apilipenko@azulsystems.com> | 2016-08-02 16:20:48 +0000 | 
| commit | 2e19f593040cfa77aec58b0816bff0e3235799e3 (patch) | |
| tree | ee4fdafea1487ea460234f03020e59c4830b1434 /llvm/lib | |
| parent | b0e4a86e0537c6b6e084ad854f7335d38c15920d (diff) | |
| download | bcm5719-llvm-2e19f593040cfa77aec58b0816bff0e3235799e3.tar.gz bcm5719-llvm-2e19f593040cfa77aec58b0816bff0e3235799e3.zip | |
[LVI] NFC. Sink a condition type check from the caller down to getValueFromCondition
This is a preparatory refactoring to support conditions other than ICmpInst.
llvm-svn: 277479
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 64 | 
1 files changed, 33 insertions, 31 deletions
| diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 8013e2367ce..2f5fbec66d2 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -859,7 +859,7 @@ bool LazyValueInfoCache::solveBlockValuePHINode(LVILatticeVal &BBLV,    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::intersectAssumeBlockValueConstantRange(Value *Val,      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::solveBlockValueSelect(LVILatticeVal &BBLV,    // 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::solveBlockValueBinaryOp(LVILatticeVal &BBLV,    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, BasicBlock *BBFrom,        // 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;      }    } | 

