Skip to content

Commit 39beeef

Browse files
committed
[LVI] Don't use dominator tree in isValidAssumeForContext()
LVI and its consumers currently have quite a bit of complexity related to dominator tree management. However, it doesn't look like it is actually needed... The only use of the dominator tree is inside isValidAssumeForContext(). However, due to the way LVI queries work, it is not needed: If we query a value for some block, we will first get the edge values from all predecessor blocks, which also includes an intersection with assumptions that apply to the terminator of the predecessor. As such, we will already have processed all assumptions from predecessor blocks (this is actually stronger than what isValidAssumeForContext() does with a DT, because this is capable of combining non-dominating assumptions). The only additional assumptions we need to take into account are those in the block being queried. And we don't need a dominator tree for that. This patch only removes the use of DT, I will drop the machinery around it in a followup. Differential Revision: https://reviews.llvm.org/D76797
1 parent a39faac commit 39beeef

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,16 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
802802
if (!BBI)
803803
return;
804804

805+
BasicBlock *BB = BBI->getParent();
805806
for (auto &AssumeVH : AC->assumptionsFor(Val)) {
806807
if (!AssumeVH)
807808
continue;
809+
810+
// Only check assumes in the block of the context instruction. Other
811+
// assumes will have already been taken into account when the value was
812+
// propagated from predecessor blocks.
808813
auto *I = cast<CallInst>(AssumeVH);
809-
if (!isValidAssumeForContext(I, BBI, DT))
814+
if (I->getParent() != BB || !isValidAssumeForContext(I, BBI))
810815
continue;
811816

812817
BBLV = intersect(BBLV, getValueFromCondition(Val, I->getArgOperand(0)));
@@ -818,10 +823,10 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
818823
if (!GuardDecl || GuardDecl->use_empty())
819824
return;
820825

821-
if (BBI->getIterator() == BBI->getParent()->begin())
826+
if (BBI->getIterator() == BB->begin())
822827
return;
823828
for (Instruction &I : make_range(std::next(BBI->getIterator().getReverse()),
824-
BBI->getParent()->rend())) {
829+
BB->rend())) {
825830
Value *Cond = nullptr;
826831
if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>(m_Value(Cond))))
827832
BBLV = intersect(BBLV, getValueFromCondition(Val, Cond));

0 commit comments

Comments
 (0)