[PATCH] D34135: [JumpThreading] Use DT to avoid processing dead blocks

Brian Rzycki via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 12 11:00:12 PDT 2018


brzycki added a comment.

In https://reviews.llvm.org/D34135#1034823, @dberlin wrote:

> I'm a little worried about the duplicated code here. I feel like you are having to patch way too many  points in the same function, and it will be easy to miss one in the future if someone changes the logicc slightly.
>
> Is there really no better place to put this/way to refactor it?
>
> If not, i'll approve, but just wanted to check.


Hi @dberlin, thank you for the comment. I'm a bit confused by your remarks however.  I suspect you may be confusing my older suggested patch with my newer one. The older patch won't work as it requires far too many flushes of DDT. And I agree, it's also too brittle. Here is my most recent patch I believe to properly address the LVI infinite recursion:

  $ git diff lib/Analysis/LazyValueInfo.cpp
  diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
  index 65fd007dc0b..36e66f7f6ef 100644
  --- a/llvm/lib/Analysis/LazyValueInfo.cpp
  +++ b/llvm/lib/Analysis/LazyValueInfo.cpp
  @@ -1145,9 +1145,17 @@ getValueFromConditionImpl(Value *Val, Value *Cond, bool isTrueDest,
                (!isTrueDest && BO->getOpcode() != BinaryOperator::Or))
       return ValueLatticeElement::getOverdefined();
  
  -  auto RHS = getValueFromCondition(Val, BO->getOperand(0), isTrueDest, Visited);
  -  auto LHS = getValueFromCondition(Val, BO->getOperand(1), isTrueDest, Visited);
  -  return intersect(RHS, LHS);
  +  // Prevent infinite recursion if Cond references itself as in this example:
  +  //  Cond: "%tmp4 = and i1 %tmp4, undef"
  +  //    BL: "%tmp4 = and i1 %tmp4, undef"
  +  //    BR: "i1 undef"
  +  Value *BL = BO->getOperand(0);
  +  Value *BR = BO->getOperand(1);
  +  if (BL == Cond || BR == Cond)
  +    return ValueLatticeElement::getOverdefined();
  +
  +  return intersect(getValueFromCondition(Val, BL, isTrueDest, Visited),
  +                   getValueFromCondition(Val, BR, isTrueDest, Visited));
   }


https://reviews.llvm.org/D34135





More information about the llvm-commits mailing list