[PATCH] D30161: [LoopPeeling] Peel loops with invariant backedge Phi input

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 21:07:50 PST 2017


mkazantsev added inline comments.


================
Comment at: lib/Transforms/Utils/LoopUnrollPeel.cpp:118
+    PHINode *Phi;
+    for (auto BI = Header->begin(); (Phi = dyn_cast<PHINode>(&*BI)); ++BI) {
+      Value *Input = Phi->getIncomingValueForBlock(BackEdge);
----------------
reames wrote:
> Out of curiosity, why the complexity about finding the backedge?  Wouldn't *all* of the inputs to the phi be loop invariant in the case you're interested in?
Off course, all inputs from preheaders will be invariant. Finding the backedge for header with n predecessors takes O(n) (it needs traversal over all predecessors with "contains" check in set that takes O(1). Acquiring its input also takes O(n) for every Phi, so total complexity being O(n*m) for m Phis.

If we just check all inputs for being invariants, it will also take O(n*m), but we will have positive results for loops with multiple back edges. The current implementation of peeling expects the loop to have 1 back edge, otherwise it will bail and we do unneded work with such loops.


https://reviews.llvm.org/D30161





More information about the llvm-commits mailing list