diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp | 113 |
1 files changed, 56 insertions, 57 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp b/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp index 1dababafb8a6..50fa169c2081 100644 --- a/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp @@ -126,7 +126,7 @@ static ValueLatticeElement intersect(const ValueLatticeElement &A, // Note: An empty range is implicitly converted to unknown or undef depending // on MayIncludeUndef internally. return ValueLatticeElement::getRange( - std::move(Range), /*MayIncludeUndef=*/A.isConstantRangeIncludingUndef() | + std::move(Range), /*MayIncludeUndef=*/A.isConstantRangeIncludingUndef() || B.isConstantRangeIncludingUndef()); } @@ -832,7 +832,7 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect( }; }(); return ValueLatticeElement::getRange( - ResultCR, TrueVal.isConstantRangeIncludingUndef() | + ResultCR, TrueVal.isConstantRangeIncludingUndef() || FalseVal.isConstantRangeIncludingUndef()); } @@ -846,7 +846,7 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect( } if (SPR.Flavor == SPF_NABS) { - ConstantRange Zero(APInt::getNullValue(TrueCR.getBitWidth())); + ConstantRange Zero(APInt::getZero(TrueCR.getBitWidth())); if (LHS == SI->getTrueValue()) return ValueLatticeElement::getRange( Zero.sub(TrueCR.abs()), FalseVal.isConstantRangeIncludingUndef()); @@ -1117,12 +1117,11 @@ static ValueLatticeElement getValueFromICmpCondition(Value *Val, ICmpInst *ICI, } // If (Val & Mask) != 0 then the value must be larger than the lowest set // bit of Mask. - if (EdgePred == ICmpInst::ICMP_NE && !Mask->isNullValue() && - C->isNullValue()) { + if (EdgePred == ICmpInst::ICMP_NE && !Mask->isZero() && C->isZero()) { unsigned BitWidth = Ty->getIntegerBitWidth(); return ValueLatticeElement::getRange(ConstantRange::getNonEmpty( APInt::getOneBitSet(BitWidth, Mask->countTrailingZeros()), - APInt::getNullValue(BitWidth))); + APInt::getZero(BitWidth))); } } @@ -1780,62 +1779,62 @@ LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C, // We could consider extending this to search further backwards through the // CFG and/or value graph, but there are non-obvious compile time vs quality // tradeoffs. - if (CxtI) { - BasicBlock *BB = CxtI->getParent(); - - // Function entry or an unreachable block. Bail to avoid confusing - // analysis below. - pred_iterator PI = pred_begin(BB), PE = pred_end(BB); - if (PI == PE) - return Unknown; - - // If V is a PHI node in the same block as the context, we need to ask - // questions about the predicate as applied to the incoming value along - // each edge. This is useful for eliminating cases where the predicate is - // known along all incoming edges. - if (auto *PHI = dyn_cast<PHINode>(V)) - if (PHI->getParent() == BB) { - Tristate Baseline = Unknown; - for (unsigned i = 0, e = PHI->getNumIncomingValues(); i < e; i++) { - Value *Incoming = PHI->getIncomingValue(i); - BasicBlock *PredBB = PHI->getIncomingBlock(i); - // Note that PredBB may be BB itself. - Tristate Result = getPredicateOnEdge(Pred, Incoming, C, PredBB, BB, - CxtI); - - // Keep going as long as we've seen a consistent known result for - // all inputs. - Baseline = (i == 0) ? Result /* First iteration */ - : (Baseline == Result ? Baseline : Unknown); /* All others */ - if (Baseline == Unknown) - break; - } - if (Baseline != Unknown) - return Baseline; + BasicBlock *BB = CxtI->getParent(); + + // Function entry or an unreachable block. Bail to avoid confusing + // analysis below. + pred_iterator PI = pred_begin(BB), PE = pred_end(BB); + if (PI == PE) + return Unknown; + + // If V is a PHI node in the same block as the context, we need to ask + // questions about the predicate as applied to the incoming value along + // each edge. This is useful for eliminating cases where the predicate is + // known along all incoming edges. + if (auto *PHI = dyn_cast<PHINode>(V)) + if (PHI->getParent() == BB) { + Tristate Baseline = Unknown; + for (unsigned i = 0, e = PHI->getNumIncomingValues(); i < e; i++) { + Value *Incoming = PHI->getIncomingValue(i); + BasicBlock *PredBB = PHI->getIncomingBlock(i); + // Note that PredBB may be BB itself. + Tristate Result = + getPredicateOnEdge(Pred, Incoming, C, PredBB, BB, CxtI); + + // Keep going as long as we've seen a consistent known result for + // all inputs. + Baseline = (i == 0) ? Result /* First iteration */ + : (Baseline == Result ? Baseline + : Unknown); /* All others */ + if (Baseline == Unknown) + break; } + if (Baseline != Unknown) + return Baseline; + } - // For a comparison where the V is outside this block, it's possible - // that we've branched on it before. Look to see if the value is known - // on all incoming edges. - if (!isa<Instruction>(V) || - cast<Instruction>(V)->getParent() != BB) { - // For predecessor edge, determine if the comparison is true or false - // on that edge. If they're all true or all false, we can conclude - // the value of the comparison in this block. - Tristate Baseline = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI); - if (Baseline != Unknown) { - // Check that all remaining incoming values match the first one. - while (++PI != PE) { - Tristate Ret = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI); - if (Ret != Baseline) break; - } - // If we terminated early, then one of the values didn't match. - if (PI == PE) { - return Baseline; - } + // For a comparison where the V is outside this block, it's possible + // that we've branched on it before. Look to see if the value is known + // on all incoming edges. + if (!isa<Instruction>(V) || cast<Instruction>(V)->getParent() != BB) { + // For predecessor edge, determine if the comparison is true or false + // on that edge. If they're all true or all false, we can conclude + // the value of the comparison in this block. + Tristate Baseline = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI); + if (Baseline != Unknown) { + // Check that all remaining incoming values match the first one. + while (++PI != PE) { + Tristate Ret = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI); + if (Ret != Baseline) + break; + } + // If we terminated early, then one of the values didn't match. + if (PI == PE) { + return Baseline; } } } + return Unknown; } |