[llvm-dev] LoopSimplify pass prevents loop unrolling

Balaram Makam via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 30 07:48:54 PDT 2017


Edit. Predecessor -> successor.

 

From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Balaram
Makam via llvm-dev
Sent: Friday, June 30, 2017 10:47 AM
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] LoopSimplify pass prevents loop unrolling

 

Hi All,

 

In the attached test case there, is an unnested loop with 2 iterations. The
loop latch block is terminated by an unconditional branch, so simplifycfg
folds the almost empty latch block into its successor which is the loop
header. This results in an additional backedge in the CFG, so when
LoopRotate pass is called it canonicalizes the loop into a nested loop.
However, now the loop trip count is unpredictable as the BackedgeTakenCount
for the outer loop is not loop invariant. As a result the loop cannot be
unrolled. Is this the intended canonicalization for this loop or is the
loopsimplify canonicalizing incorrectly? Should simplifycfg skip folding the
latch block into the loop header if this results in additional backedges and
let the empty blocks be folded during CGP? More details in
https://bugs.llvm.org/show_bug.cgi?id=33605.

 

FWIW, this prevents unrolling of a hot loop in spec2017/gcc and also
prevents loop-interleave of a loop in spec2017/perlbench. Appreciate any
suggestions on how to fix this.

 

Attached testcase:

$cat test.c

void foo();

bool test(int a, int b, int *c) {

  bool changed = false;

  for (unsigned int i = 2; i--;) {

    int r = a | b;

    if ( r != c[i]) {

      c[i] = r;

      foo();

      changed = true;

    }

  }

  return changed;

}

 

Thanks,

Balaram

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170630/0275d044/attachment.html>


More information about the llvm-dev mailing list