mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[ValueTracking] Use Inst::comesBefore in isValidAssumeForCtx (NFC).
D51664 added Instruction::comesBefore which should provide better performance than the manual check. Reviewers: rnk, nikic, spatel Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D76228
This commit is contained in:
parent
e1695a56c4
commit
1e0d9ddb20
@ -617,30 +617,11 @@ bool llvm::isValidAssumeForContext(const Instruction *Inv,
|
||||
// feeding the assume is trivially true, thus causing the removal of
|
||||
// the assume).
|
||||
|
||||
if (DT) {
|
||||
if (DT->dominates(Inv, CxtI))
|
||||
if (Inv->getParent() == CxtI->getParent()) {
|
||||
// If Inv and CtxI are in the same block, check if the assume (Inv) is first
|
||||
// in the BB.
|
||||
if (Inv->comesBefore(CxtI))
|
||||
return true;
|
||||
} else if (Inv->getParent() == CxtI->getParent()->getSinglePredecessor()) {
|
||||
// We don't have a DT, but this trivially dominates.
|
||||
return true;
|
||||
}
|
||||
|
||||
// With or without a DT, the only remaining case we will check is if the
|
||||
// instructions are in the same BB. Give up if that is not the case.
|
||||
if (Inv->getParent() != CxtI->getParent())
|
||||
return false;
|
||||
|
||||
// If we have a dom tree, then we now know that the assume doesn't dominate
|
||||
// the other instruction. If we don't have a dom tree then we can check if
|
||||
// the assume is first in the BB.
|
||||
if (!DT) {
|
||||
// Search forward from the assume until we reach the context (or the end
|
||||
// of the block); the common case is that the assume will come first.
|
||||
for (auto I = std::next(BasicBlock::const_iterator(Inv)),
|
||||
IE = Inv->getParent()->end(); I != IE; ++I)
|
||||
if (&*I == CxtI)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Don't let an assume affect itself - this would cause the problems
|
||||
// `isEphemeralValueOf` is trying to prevent, and it would also make
|
||||
@ -658,6 +639,18 @@ bool llvm::isValidAssumeForContext(const Instruction *Inv,
|
||||
return !isEphemeralValueOf(Inv, CxtI);
|
||||
}
|
||||
|
||||
// Inv and CxtI are in different blocks.
|
||||
if (DT) {
|
||||
if (DT->dominates(Inv, CxtI))
|
||||
return true;
|
||||
} else if (Inv->getParent() == CxtI->getParent()->getSinglePredecessor()) {
|
||||
// We don't have a DT, but this trivially dominates.
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isKnownNonZeroFromAssume(const Value *V, const Query &Q) {
|
||||
// Use of assumptions is context-sensitive. If we don't have a context, we
|
||||
// cannot use them!
|
||||
|
Loading…
x
Reference in New Issue
Block a user