[PATCH] D76797: [LVI] Don't use dominator tree in isValidAssumeForContext()

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 13:00:46 PDT 2020


nikic created this revision.
nikic added reviewers: reames, lebedev.ri.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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, I don't think this is 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. If it lands, I will remove the whole disableDT/enableDT machinery in a followup, because it becomes unused.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76797

Files:
  lib/Analysis/LazyValueInfo.cpp


Index: lib/Analysis/LazyValueInfo.cpp
===================================================================
--- lib/Analysis/LazyValueInfo.cpp
+++ lib/Analysis/LazyValueInfo.cpp
@@ -820,11 +820,16 @@
   if (!BBI)
     return;
 
+  BasicBlock *BB = BBI->getParent();
   for (auto &AssumeVH : AC->assumptionsFor(Val)) {
     if (!AssumeVH)
       continue;
+
+    // Only check assumes in the block of the context instruction. Other
+    // assumes will have already been taken into account when the value was
+    // propagated from predecessor blocks.
     auto *I = cast<CallInst>(AssumeVH);
-    if (!isValidAssumeForContext(I, BBI, DT))
+    if (I->getParent() != BB || !isValidAssumeForContext(I, BBI))
       continue;
 
     BBLV = intersect(BBLV, getValueFromCondition(Val, I->getArgOperand(0)));
@@ -836,10 +841,10 @@
   if (!GuardDecl || GuardDecl->use_empty())
     return;
 
-  if (BBI->getIterator() == BBI->getParent()->begin())
+  if (BBI->getIterator() == BB->begin())
     return;
   for (Instruction &I : make_range(std::next(BBI->getIterator().getReverse()),
-                                   BBI->getParent()->rend())) {
+                                   BB->rend())) {
     Value *Cond = nullptr;
     if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>(m_Value(Cond))))
       BBLV = intersect(BBLV, getValueFromCondition(Val, Cond));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76797.252650.patch
Type: text/x-patch
Size: 1363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200325/09a7c404/attachment.bin>


More information about the llvm-commits mailing list