[PATCH] D95806: [LoopUnrollAndJam] Do not allows loops which have no exit(ing) blocks or multiple exit(ing) blocks

Sidharth Baveja via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 14:49:38 PST 2021


sidbav updated this revision to Diff 320913.
sidbav retitled this revision from "[LoopUnrollAndJam] Check if the loops have an Exit Block" to "[LoopUnrollAndJam] Do not allows loops which have no exit(ing) blocks or multiple exit(ing) blocks".
sidbav edited the summary of this revision.
sidbav added a comment.

Update the test case such that it is not specific to a target.

Also, I dug a little deeper into the definition of getExitBlock. This function will return a nullptr if the loop has 2 or more exit blocks, or the loop does not have an exit block. This is why the isLoopExiting(Latch) does not return a nullptr in the function isRotatedForm. 
The function getExitingBlock has the same behaviour as getExitBlock

Updated the test case to not allow loops which have multiple exit or exiting blocks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95806/new/

https://reviews.llvm.org/D95806

Files:
  llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
  llvm/test/Transforms/LoopUnrollAndJam/multiple_exit_blocks.ll


Index: llvm/test/Transforms/LoopUnrollAndJam/multiple_exit_blocks.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopUnrollAndJam/multiple_exit_blocks.ll
@@ -0,0 +1,58 @@
+; REQUIRES: asserts
+; RUN: opt -debug-only=loop-unroll-and-jam -passes="loop-unroll-and-jam" -enable-unroll-and-jam -allow-unroll-and-jam -unroll-and-jam-count=8 -disable-output %s 2>&1 | FileCheck %s
+
+; CHECK: Loop Unroll and Jam: F[h] Loop %bb8
+; CHECK: Won't unroll-and-jam; Loop has multiple exit blocks OR does not have an exit block
+
+ at a = external global i16, align 2
+ at e = external global i32, align 4
+ at f = external global i16, align 2
+ at b = external global i16, align 2
+ at c = external global i64, align 8
+
+define i16 @g() {
+bb:
+  %i = load i16, i16* @a, align 2
+  ret i16 %i
+}
+
+define void @h() {
+bb:
+  store i32 4, i32* @e, align 4
+  %i15 = load i16, i16* @b, align 2
+  %i17 = icmp slt i16 %i15, 1
+  br label %bb8
+
+bb8:                                              ; preds = %bb, %bb47
+  %storemerge15 = phi i32 [ 4, %bb ], [ %i49, %bb47 ]
+  br label %bb24
+
+bb24:                                             ; preds = %bb43, %bb8
+  %storemerge312 = phi i16 [ 0, %bb8 ], [ %i45, %bb43 ]
+  br i1 %i17, label %bb46.preheader, label %bb43
+
+bb46.preheader:                                   ; preds = %bb24
+  store i16 %storemerge312, i16* @f, align 2
+  br label %bb46
+
+bb43:                                             ; preds = %bb24
+  %i45 = add nuw nsw i16 %storemerge312, 1
+  %i13 = icmp ult i16 %storemerge312, 7
+  br i1 %i13, label %bb24, label %bb47
+
+bb46:                                             ; preds = %bb46.preheader, %bb46
+  br label %bb46
+
+bb47:                                             ; preds = %bb43
+  %i49 = add nsw i32 %storemerge15, -1
+  store i32 %i49, i32* @e, align 4
+  %i7.not = icmp eq i32 %i49, 0
+  br i1 %i7.not, label %bb50, label %bb8
+
+bb50:                                             ; preds = %bb47
+  store i16 %i45, i16* @f, align 2
+  ret void
+}
+
+; Function Attrs: argmemonly nofree nosync nounwind willreturn
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
Index: llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
+++ llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
@@ -831,6 +831,22 @@
     if (SubLoopsSize != 1)
       return false;
 
+    // If the Loop has multiple exit blocks OR does not have an exit block,
+    // cannot perform unroll and jam
+    if (!L->getExitBlock()) {
+      LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; Loop has multiple exit "
+                           "blocks OR does not have an exit block\n");
+      return false;
+    }
+
+    // If the Loop has multiple exiting blocks OR does not have an exiting
+    // blocks, cannot perform unroll and jam
+    if (!L->getExitingBlock()) {
+      LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; Loop has multiple exiting "
+                           "blocks OR does not have an exiting block\n");
+      return false;
+    }
+
     L = L->getSubLoops()[0];
   } while (L);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95806.320913.patch
Type: text/x-patch
Size: 3219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210202/6205f3e5/attachment.bin>


More information about the llvm-commits mailing list