[PATCH] D32720: [LICM] Introduce a finer granularity option to compute early exits.

Xin Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 13:42:16 PDT 2017


trentxintong added inline comments.


================
Comment at: lib/Transforms/Utils/LoopUtils.cpp:1053
+    for (Instruction *ExitInst : SafetyInfo->EarlyExits)
+      if (!SafetyInfo->OI.dominates(&Inst, ExitInst))
+        return false;
----------------
efriedma wrote:
> Actually, one more issue we probably need to address.
> 
> This is potentially linear in the number of calls in the loop, since we don't try to prune EarlyExits at all.  This makes LICM potentially O(n^2) overall.  Can we store this information in some more efficient way?
We could certainly prune the early exits by discovering them walking the dominator tree. If an instruction dominates an early exit (Inst A), it certainly dominates all the other early exits dominated by Inst A.  So we do not need to include those early exits in the list.

The drawback with this is that if an early exit is deleted, which is possible but unlikely. We need to invalidate the early exit list (we could try to recompute everything, but probably not worth it).

By doing this, we potentially save a lot of OI.dominates checks.  Worst case is still O(n^2) in case of a loop with many basic blocks that do not dominate each other and each one of them have early exits ... but this happens infrequently in practice IMO.



https://reviews.llvm.org/D32720





More information about the llvm-commits mailing list