[llvm] r307291 - [LoopUnrollRuntime] Bailout when multiple exiting blocks to the unique latch exit block

Anna Thomas via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 6 11:39:26 PDT 2017


Author: annat
Date: Thu Jul  6 11:39:26 2017
New Revision: 307291

URL: http://llvm.org/viewvc/llvm-project?rev=307291&view=rev
Log:
[LoopUnrollRuntime] Bailout when multiple exiting blocks to the unique latch exit block

Currently, we do not support multiple exiting blocks to the
latch exit block. However, this bailout wasn't triggered when we had a
unique exit block (which is the latch exit), with multiple exiting
blocks to that unique exit.

Moved the bailout so that it's triggered in both cases and added
testcase.

Modified:
    llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp
    llvm/trunk/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll

Modified: llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp?rev=307291&r1=307290&r2=307291&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp Thu Jul  6 11:39:26 2017
@@ -504,10 +504,6 @@ bool llvm::UnrollRuntimeLoopRemainder(Lo
     // transformed.
     if (!PreserveLCSSA)
       return false;
-    // TODO: Support multiple exiting blocks jumping to the `LatchExit`. This
-    // will need updating the logic in connectEpilog.
-    if (!LatchExit->getSinglePredecessor())
-        return false;
     SmallVector<BasicBlock *, 4> Exits;
     L->getUniqueExitBlocks(Exits);
     for (auto *BB : Exits)
@@ -517,6 +513,11 @@ bool llvm::UnrollRuntimeLoopRemainder(Lo
 
   assert(LatchExit && "Latch Exit should exist!");
 
+  // TODO: Support multiple exiting blocks jumping to the `LatchExit` when
+  // UnrollRuntimeMultiExit is true. This will need updating the logic in
+  // connectEpilog.
+  if (!LatchExit->getSinglePredecessor())
+    return false;
   // Use Scalar Evolution to compute the trip count. This allows more loops to
   // be unrolled than relying on induction var simplification.
   if (!SE)

Modified: llvm/trunk/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll?rev=307291&r1=307290&r2=307291&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll (original)
+++ llvm/trunk/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll Thu Jul  6 11:39:26 2017
@@ -184,6 +184,36 @@ for.exit2:
   ret i32 42
 }
 
+; FIXME: Support multiple exiting blocks to the unique exit block.
+define void @unique_exit(i32 %arg) {
+; CHECK-LABEL: unique_exit
+; CHECK-NOT: .unr
+; CHECK-NOT: .epil
+entry:
+  %tmp = icmp sgt i32 undef, %arg
+  br i1 %tmp, label %preheader, label %returnblock
+
+preheader:                                 ; preds = %entry
+  br label %header
+
+LoopExit:                                ; preds = %header, %latch
+  %tmp2.ph = phi i32 [ %tmp4, %header ], [ -1, %latch ]
+  br label %returnblock
+
+returnblock:                                         ; preds = %LoopExit, %entry
+  %tmp2 = phi i32 [ -1, %entry ], [ %tmp2.ph, %LoopExit ]
+  ret void
+
+header:                                           ; preds = %preheader, %latch
+  %tmp4 = phi i32 [ %inc, %latch ], [ %arg, %preheader ]
+  %inc = add nsw i32 %tmp4, 1
+  br i1 true, label %LoopExit, label %latch
+
+latch:                                            ; preds = %header
+  %cmp = icmp slt i32 %inc, undef
+  br i1 %cmp, label %header, label %LoopExit
+}
+
 ; two exiting and two exit blocks.
 ; the non-latch exiting block has duplicate edges to the non-latch exit block.
 define i64 @test5(i64 %trip, i64 %add, i1 %cond) {




More information about the llvm-commits mailing list