[PATCH] D17526: [LoopUnroll] Respect the convergent attribute.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 15:33:47 PST 2016


jlebar created this revision.
jlebar added a reviewer: resistor.
jlebar added a subscriber: llvm-commits.
Herald added a subscriber: mzolotukhin.

Specifically, when we perform runtime loop unrolling of a loop that
contains a convergent op, we can only unroll k times, where k divides
the loop trip multiple.

Without this change, we'll happily unroll e.g. the following loop

  for (int i = 0; i < N; ++i) {
    if (i == 0) convergent_op();
    foo();
  }

into

  int i = 0;
  if (N % 2 == 1) {
    convergent_op();
    foo();
    ++i;
  }
  for (; i < N - 1; i += 2) {
    if (i == 0) convergent_op();
    foo();
    foo();
  }.

This is unsafe, because we've just added a control-flow dependency to
the convergent op in the prelude.

In general, runtime unrolling loops that contain convergent ops is safe
only if we don't have emit a prelude, which occurs when the unroll count
divides the trip multiple.

http://reviews.llvm.org/D17526

Files:
  lib/Transforms/Scalar/LoopUnrollPass.cpp
  lib/Transforms/Utils/LoopUnroll.cpp
  test/Transforms/LoopUnroll/convergent.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17526.48741.patch
Type: text/x-patch
Size: 7477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160222/c4b277c3/attachment.bin>


More information about the llvm-commits mailing list