[llvm] r242047 - Enable runtime unrolling with unroll pragma metadata
Mark Heffernan
meheff at google.com
Mon Jul 13 11:26:28 PDT 2015
Author: meheff
Date: Mon Jul 13 13:26:27 2015
New Revision: 242047
URL: http://llvm.org/viewvc/llvm-project?rev=242047&view=rev
Log:
Enable runtime unrolling with unroll pragma metadata
Enable runtime unrolling for loops with unroll count metadata ("#pragma unroll N")
and a runtime trip count. Also, do not unroll loops with unroll full metadata if the
loop has a runtime loop count. Previously, such loops would be unrolled with a
very large threshold (pragma-unroll-threshold) if runtime unrolled happened to be
enabled resulting in a very large (and likely unwise) unroll factor.
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
llvm/trunk/test/Transforms/LoopUnroll/unroll-pragmas.ll
Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=242047&r1=242046&r2=242047&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp Mon Jul 13 13:26:27 2015
@@ -840,8 +840,10 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPa
// Reduce count based on the type of unrolling and the threshold values.
unsigned OriginalCount = Count;
- bool AllowRuntime = UserRuntime ? CurrentRuntime : UP.Runtime;
- if (HasRuntimeUnrollDisablePragma(L)) {
+ bool AllowRuntime =
+ (PragmaCount > 0) || (UserRuntime ? CurrentRuntime : UP.Runtime);
+ // Don't unroll a runtime trip count loop with unroll full pragma.
+ if (HasRuntimeUnrollDisablePragma(L) || PragmaFullUnroll) {
AllowRuntime = false;
}
if (Unrolling == Partial) {
Modified: llvm/trunk/test/Transforms/LoopUnroll/unroll-pragmas.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/unroll-pragmas.ll?rev=242047&r1=242046&r2=242047&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/unroll-pragmas.ll (original)
+++ llvm/trunk/test/Transforms/LoopUnroll/unroll-pragmas.ll Mon Jul 13 13:26:27 2015
@@ -86,9 +86,9 @@ for.end:
; #pragma clang loop unroll(full)
; Loop should be fully unrolled.
;
-; CHECK-LABEL: @loop64_with_enable(
+; CHECK-LABEL: @loop64_with_full(
; CHECK-NOT: br i1
-define void @loop64_with_enable(i32* nocapture %a) {
+define void @loop64_with_full(i32* nocapture %a) {
entry:
br label %for.body
@@ -139,14 +139,13 @@ for.end:
!6 = !{!"llvm.loop.unroll.count", i32 4}
; #pragma clang loop unroll(full)
-; Full unrolling is requested, but loop has a dynamic trip count so
+; Full unrolling is requested, but loop has a runtime trip count so
; no unrolling should occur.
;
-; CHECK-LABEL: @dynamic_loop_with_enable(
+; CHECK-LABEL: @runtime_loop_with_full(
; CHECK: store i32
; CHECK-NOT: store i32
-; CHECK: br i1
-define void @dynamic_loop_with_enable(i32* nocapture %a, i32 %b) {
+define void @runtime_loop_with_full(i32* nocapture %a, i32 %b) {
entry:
%cmp3 = icmp sgt i32 %b, 0
br i1 %cmp3, label %for.body, label %for.end, !llvm.loop !8
@@ -168,22 +167,22 @@ for.end:
!8 = !{!8, !4}
; #pragma clang loop unroll_count(4)
-; Loop has a dynamic trip count. Unrolling should occur, but no
-; conditional branches can be removed.
+; Loop has a runtime trip count. Runtime unrolling should occur and loop
+; should be duplicated (original and 4x unrolled).
;
-; CHECK-LABEL: @dynamic_loop_with_count4(
+; CHECK-LABEL: @runtime_loop_with_count4(
+; CHECK: for.body.prol:
+; CHECK: store
; CHECK-NOT: store
; CHECK: br i1
+; CHECK: for.body
; CHECK: store
-; CHECK: br i1
; CHECK: store
-; CHECK: br i1
; CHECK: store
-; CHECK: br i1
; CHECK: store
+; CHECK-NOT: store
; CHECK: br i1
-; CHECK-NOT: br i1
-define void @dynamic_loop_with_count4(i32* nocapture %a, i32 %b) {
+define void @runtime_loop_with_count4(i32* nocapture %a, i32 %b) {
entry:
%cmp3 = icmp sgt i32 %b, 0
br i1 %cmp3, label %for.body, label %for.end, !llvm.loop !9
More information about the llvm-commits
mailing list