[PATCH] D44766: Extend peeling to help invariant motion

Evgeny Stupachenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 21 17:52:19 PDT 2018


evstupac created this revision.
evstupac added reviewers: mkazantsev, mkuper, efriedma, fhahn.

Apply peeling for loops like:
for (i = 0; i < n; i++) {

  if (i >= *a_bound) assert(0); 
  s += a[i]; 
  if (i >= *b_bound) assert(0); 
  s += b[i]; 

}

Here load *a_bound is safe to speculate and it should be hoisted out of the loop,
However, *b_bound is not safe to speculate, because this will potentially change program behavior:
If we load "b_bound" before the loop and "b_bound" is null we throw an exception, which is wrong if we exit at "i >= *a_bound".
After peeling *b_bound is safe to speculate and hoist it out of the loop (because if it is null - we throw an exception before the loop):

if (0 >= *a_bound) assert(0); 
s += a[0]; 
if (0 >= *b_bound) assert(0); 
s += b[0];

for (i = 1; i < n; i++) {

  if (i >= *a_bound) assert(0); 
  s += a[i]; 
  if (i >= *b_bound) assert(0); 
  s += b[i]; 

}


Repository:
  rL LLVM

https://reviews.llvm.org/D44766

Files:
  include/llvm/Analysis/LoopInfo.h
  include/llvm/Transforms/Utils/UnrollLoop.h
  lib/Analysis/LoopInfo.cpp
  lib/Transforms/Scalar/LoopUnrollPass.cpp
  lib/Transforms/Utils/LoopUnrollPeel.cpp
  test/Transforms/LoopUnroll/peel-loop-spec-load.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44766.139396.patch
Type: text/x-patch
Size: 17665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180322/cbc95d2c/attachment.bin>


More information about the llvm-commits mailing list