[PATCH] D47407: [LoopInstSimplify] Re-implement the core logic of loop-instsimplify to be both simpler and substantially more efficient.

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 26 02:55:24 PDT 2018


chandlerc created this revision.
chandlerc added reviewers: sanjoy, asbirlea.
Herald added subscribers: hiraditya, mcrosier.

Rather than use a hand-rolled iteration technique that isn't quite the
same as RPO, use the pre-built RPO loop body traversal utility.

Once visiting the loop body in RPO, we can assert that we visit defs
before uses reliably. When this is the case, the only need to iterate is
when simplifying a def that is used by a PHI node along a back-edge.
With this patch, the first pass over the loop body is just a complete
simplification of every instruction across the loop body. When we
encounter a use of a simplified instruction that stems from a PHI node
in the loop body that has already been visited (due to some cyclic CFG,
potentially the loop itself, or a nested loop, or unstructured control
flow), we recall that specific PHI node for the second iteration.
Nothing else needs to be preserved from iteration to iteration.

On the second and later iterations, only instructions known to have
simplified inputs are considered, each time starting from a set of PHIs
that had simplified inputs along the backedges.

Dead instructions are collected along the way, but deleted in a batch at
the end of each iteration making the iterations themselves substantially
simpler. This uses a new batch API for recursively deleting dead
instructions.

This alsa changes the routine to visit subloops. Because simplification
is fundamentally transitive, we may need to visit the entire loop body,
including subloops, to handle knock-on simplification.

I've added a basic test file that helps demonstrate that all of these
changes work. It includes both straight-forward loops with
simplifications as well as interesting PHI-structures, CFG-structures,
and a nested loop case.


Repository:
  rL LLVM

https://reviews.llvm.org/D47407

Files:
  llvm/include/llvm/Analysis/Utils/Local.h
  llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/test/Transforms/LoopInstSimplify/basic.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47407.148710.patch
Type: text/x-patch
Size: 19272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180526/670a4768/attachment.bin>


More information about the llvm-commits mailing list