[PATCH] D67408: [IndVars] An implementation of loop predication without a need for speculation

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 10:44:11 PDT 2019


reames created this revision.
reames added reviewers: apilipenko, nikic, skatkov, ebrevnov.
Herald added subscribers: javed.absar, bollu, mcrosier.
Herald added a project: LLVM.

This patch implements a variation of a well known techniques for JIT compilers - we have an implementation in tree as LoopPredication - but with an interesting twist.  This version does not assume the ability to execute a path which wasn't taken in the original program  (such as a guard or widenable.condition intrinsic).  The benefit is that this works for arbitrary IR from any frontend (including C/C++/Fortran).  The tradeoff is that it's restricted to read only loops without implicit exits.

This builds on SCEV, and can thus eliminate the loop varying portion of the any early exit where all exits are understandable by SCEV.  A key advantage is that fixing deficiency exposed in SCEV - already found one while writing test cases - will also benefit all of full redundancy elimination (and most other loop transforms).

I haven't seen anything in the literature which quite matches this.  Given that, I'm not entirely sure that keeping the name "loop predication" is helpful.  Anyone have suggestions for a better name?  This is analogous to partial redundancy elimination - since we remove the condition flowing around the backedge - and has some parallels to our existing transforms which try to make conditions invariant in loops.

Factoring wise, I chose to put this in IndVarSimplify since it's a generally applicable to all workloads.  I could split this off into it's own pass, but we'd then probably want to add that new pass every place we use IndVars.

One solid argument for splitting it off into it's own pass is that this transform is "too good".  It breaks a huge number of existing IndVars test cases as they tend to be simple read only loops.  At the moment, I've opted it off by default, but if we add this to IndVars and enable, we'll have to update around 20 test files to add side effects or disable this transform.


Repository:
  rL LLVM

https://reviews.llvm.org/D67408

Files:
  lib/Transforms/Scalar/IndVarSimplify.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67408.219567.patch
Type: text/x-patch
Size: 5486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190910/b9c26557/attachment.bin>


More information about the llvm-commits mailing list