[llvm] r311922 - [LoopUnroll] Properly update loop structure in case of successful peeling.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 13:29:33 PDT 2017


Author: davide
Date: Mon Aug 28 13:29:33 2017
New Revision: 311922

URL: http://llvm.org/viewvc/llvm-project?rev=311922&view=rev
Log:
[LoopUnroll] Properly update loop structure in case of successful peeling.

When peeling kicks in, it updates the loop preheader.
Later, a successful full unroll of the loop needs to update a PHI
which i-th argument comes from the loop preheader, so it'd better look
at the correct block. Fixes PR33437.

Differential Revision:  https://reviews.llvm.org/D37153

Added:
    llvm/trunk/test/Transforms/LoopUnroll/pr33437.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp

Modified: llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp?rev=311922&r1=311921&r2=311922&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp Mon Aug 28 13:29:33 2017
@@ -396,8 +396,19 @@ bool llvm::UnrollLoop(Loop *L, unsigned
          "Did not expect runtime trip-count unrolling "
          "and peeling for the same loop");
 
-  if (PeelCount)
-    peelLoop(L, PeelCount, LI, SE, DT, AC, PreserveLCSSA);
+  if (PeelCount) {
+    bool Peeled = peelLoop(L, PeelCount, LI, SE, DT, AC, PreserveLCSSA);
+
+    // Successful peeling may result in a change in the loop preheader/trip
+    // counts. If we later unroll the loop, we want these to be updated.
+    if (Peeled) {
+      BasicBlock *ExitingBlock = L->getExitingBlock();
+      assert(ExitingBlock && "Loop without exiting block?");
+      Preheader = L->getLoopPreheader();
+      TripCount = SE->getSmallConstantTripCount(L, ExitingBlock);
+      TripMultiple = SE->getSmallConstantTripMultiple(L, ExitingBlock);
+    }
+  }
 
   // Loops containing convergent instructions must have a count that divides
   // their TripMultiple.

Added: llvm/trunk/test/Transforms/LoopUnroll/pr33437.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/pr33437.ll?rev=311922&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/pr33437.ll (added)
+++ llvm/trunk/test/Transforms/LoopUnroll/pr33437.ll Mon Aug 28 13:29:33 2017
@@ -0,0 +1,30 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -loop-unroll %s -S | FileCheck %s
+
+declare zeroext i8 @patatino()
+
+define fastcc void @tinky() {
+; CHECK-LABEL: @tinky(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[FOR_COND93:%.*]]
+; CHECK:       for.cond93:
+; CHECK-NEXT:    br label [[FOR_BODY198:%.*]]
+; CHECK:       for.body198:
+; CHECK-NEXT:    [[CALL593:%.*]] = tail call zeroext i8 @patatino()
+; CHECK-NEXT:    ret void
+;
+entry:
+  br label %for.cond93
+
+for.cond93.loopexit:
+  ret void
+
+for.cond93:
+  br label %for.body198
+
+for.body198:
+  %l_249.12 = phi i8 [ undef, %for.cond93 ], [ %call593, %for.body198 ]
+  %l_522.01 = phi i32 [ 0, %for.cond93 ], [ 1, %for.body198 ]
+  %call593 = tail call zeroext i8 @patatino()
+  br i1 false, label %for.body198, label %for.cond93.loopexit
+}




More information about the llvm-commits mailing list