[PATCH] D31281: [LoopUnroll] Remap references in peeled iteration

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 05:21:13 PDT 2017


sepavloff updated this revision to Diff 92927.
sepavloff added a comment.

Updated patch


https://reviews.llvm.org/D31281

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


Index: test/Transforms/LoopUnroll/peel-loop.ll
===================================================================
--- test/Transforms/LoopUnroll/peel-loop.ll
+++ test/Transforms/LoopUnroll/peel-loop.ll
@@ -94,3 +94,34 @@
   %ret = phi i32 [ 0, %entry], [ %inc, %for.cond.for.end_crit_edge ]
   ret i32 %ret
 }
+
+; Check if loop composed of several BB is peeled correctly.
+declare void @funcb()
+define void @funca(i8* readnone %b, i8* readnone %e) local_unnamed_addr {
+entry:
+  %cmp2 = icmp eq i8* %b, %e
+  br i1 %cmp2, label %for.end, label %for.body.preheader
+
+for.body.preheader:
+  br label %for.body
+
+for.body:
+  %Comma.04 = phi i1 [ true, %if.end ], [ false, %for.body.preheader ]
+  %b.addr.03 = phi i8* [ %incdec.ptr, %if.end ], [ %b, %for.body.preheader ]
+  br i1 %Comma.04, label %if.then, label %if.end
+
+if.then:
+  tail call void @funcb()
+  br label %if.end
+
+if.end:
+  %incdec.ptr = getelementptr inbounds i8, i8* %b.addr.03, i64 1
+  %cmp = icmp eq i8* %incdec.ptr, %e
+  br i1 %cmp, label %for.end.loopexit, label %for.body
+
+for.end.loopexit:
+  br label %for.end
+
+for.end:
+  ret void
+}
Index: lib/Transforms/Utils/LoopUnrollPeel.cpp
===================================================================
--- lib/Transforms/Utils/LoopUnrollPeel.cpp
+++ lib/Transforms/Utils/LoopUnrollPeel.cpp
@@ -415,6 +415,11 @@
 
     cloneLoopBlocks(L, Iter, InsertTop, InsertBot, Exit,
                     NewBlocks, LoopBlocks, VMap, LVMap, DT, LI);
+
+    // Remap to use values from the current iteration instead of the
+    // previous one.
+    remapInstructionsInBlocks(NewBlocks, VMap);
+
     if (DT) {
       // Latches of the cloned loops dominate over the loop exit, so idom of the
       // latter is the first cloned loop body, as original PreHeader dominates
@@ -437,10 +442,6 @@
     F->getBasicBlockList().splice(InsertTop->getIterator(),
                                   F->getBasicBlockList(),
                                   NewBlocks[0]->getIterator(), F->end());
-
-    // Remap to use values from the current iteration instead of the
-    // previous one.
-    remapInstructionsInBlocks(NewBlocks, VMap);
   }
 
   // Now adjust the phi nodes in the loop header to get their initial values


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31281.92927.patch
Type: text/x-patch
Size: 2241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170324/158a0ca3/attachment.bin>


More information about the llvm-commits mailing list