[PATCH] D30757: [LoopUnroll] Don't peel loops where the latch isn't the exiting block

Michael Kuperstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 16 13:42:23 PDT 2017


mkuper updated this revision to Diff 92045.
mkuper retitled this revision from "[LoopUnroll] Handle loops where the exiting block is different from the latch" to "[LoopUnroll] Don't peel loops where the latch isn't the exiting block".
mkuper edited the summary of this revision.

https://reviews.llvm.org/D30757

Files:
  lib/Transforms/Utils/LoopUnrollPeel.cpp
  test/Transforms/LoopUnroll/peel-loop-irreducible.ll


Index: test/Transforms/LoopUnroll/peel-loop-irreducible.ll
===================================================================
--- test/Transforms/LoopUnroll/peel-loop-irreducible.ll
+++ test/Transforms/LoopUnroll/peel-loop-irreducible.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -S -loop-unroll | FileCheck %s
+
+; Check we don't try to peel loops where the latch is not the exiting block.
+; CHECK-LABEL: @invariant_backedge_irreducible
+; CHECK: entry:
+; CHECK: br label %header
+; CHECK-NOT: peel
+; CHECK: header:
+; CHECK: br i1 {{.*}} label %latch, label %exiting
+; CHECK: latch:
+; CHECK: br i1 {{.*}} label %header, label %exiting
+; CHECK: exiting:
+; CHECK: br i1 {{.*}} label %latch, label %exit
+
+define i32 @invariant_backedge_irreducible(i32 %a, i32 %b) {
+entry:
+  br label %header
+
+header:
+  %i = phi i32 [ 0, %entry ], [ %inc, %latch ]
+  %sum = phi i32 [ 0, %entry ], [ %incsum, %latch ]
+  %plus = phi i32 [ %a, %entry ], [ %b, %latch ]
+  %cmp.phi = phi i1 [ false, %entry ], [ %cmp, %latch ]
+  br i1 %cmp.phi, label %latch, label %exiting
+
+latch:
+  %incsum = add i32 %sum, %plus
+  %inc = add i32 %i, 1
+  %cmp = icmp slt i32 %i, 1000    
+  br i1 %cmp, label %header, label %exiting
+
+exiting:
+  %cmp.exiting = phi i1 [ %cmp.phi, %header ], [ %cmp, %latch]
+  br i1 %cmp.exiting, label %latch, label %exit
+
+exit:
+  ret i32 %sum
+}
Index: lib/Transforms/Utils/LoopUnrollPeel.cpp
===================================================================
--- lib/Transforms/Utils/LoopUnrollPeel.cpp
+++ lib/Transforms/Utils/LoopUnrollPeel.cpp
@@ -56,6 +56,13 @@
   if (!L->getExitingBlock() || !L->getUniqueExitBlock())
     return false;
 
+  // Don't try to peel loops where the latch is not the exiting block.
+  // This can be an indication of two different things:
+  // 1) The loop is not rotated.
+  // 2) The loop contains irreducible control flow that involves the latch.
+  if (L->getLoopLatch() != L->getExitingBlock())
+    return false;
+
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30757.92045.patch
Type: text/x-patch
Size: 1996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170316/0042a6c9/attachment.bin>


More information about the llvm-commits mailing list