diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -787,15 +787,13 @@ // 2nd priority is unroll count set by pragma. if (PInfo.PragmaCount > 0) { - if ((UP.AllowRemainder || (TripMultiple % PInfo.PragmaCount == 0)) && - UCE.getUnrolledLoopSize(UP, PInfo.PragmaCount) < PragmaUnrollThreshold) + if ((UP.AllowRemainder || (TripMultiple % PInfo.PragmaCount == 0))) return PInfo.PragmaCount; } - if (PInfo.PragmaFullUnroll && TripCount != 0) { - if (UCE.getUnrolledLoopSize(UP, TripCount) < PragmaUnrollThreshold) - return TripCount; - } + if (PInfo.PragmaFullUnroll && TripCount != 0) + return TripCount; + // if didn't return until here, should continue to other priorties return None; } diff --git a/llvm/test/Transforms/LoopUnroll/unroll-pragmas.ll b/llvm/test/Transforms/LoopUnroll/unroll-pragmas.ll --- a/llvm/test/Transforms/LoopUnroll/unroll-pragmas.ll +++ b/llvm/test/Transforms/LoopUnroll/unroll-pragmas.ll @@ -235,33 +235,6 @@ !10 = !{!10, !11} !11 = !{!"llvm.loop.unroll.count", i32 1} -; #pragma clang loop unroll(full) -; Loop has very high loop count (1 million) and full unrolling was requested. -; Loop should unrolled up to the pragma threshold, but not completely. -; -; CHECK-LABEL: @unroll_1M( -; CHECK: store i32 -; CHECK: store i32 -; CHECK: br i1 -define void @unroll_1M(i32* nocapture %a, i32 %b) { -entry: - br label %for.body - -for.body: ; preds = %for.body, %entry - %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] - %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv - %0 = load i32, i32* %arrayidx, align 4 - %inc = add nsw i32 %0, 1 - store i32 %inc, i32* %arrayidx, align 4 - %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 - %exitcond = icmp eq i64 %indvars.iv.next, 1000000 - br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !12 - -for.end: ; preds = %for.body - ret void -} -!12 = !{!12, !4} - ; #pragma clang loop unroll(enable) ; Loop should be fully unrolled. ; @@ -279,13 +252,13 @@ store i32 %inc, i32* %arrayidx, align 4 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 %exitcond = icmp eq i64 %indvars.iv.next, 64 - br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !13 + br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !12 for.end: ; preds = %for.body ret void } -!13 = !{!13, !14} -!14 = !{!"llvm.loop.unroll.enable"} +!12 = !{!12, !13} +!13 = !{!"llvm.loop.unroll.enable"} ; #pragma clang loop unroll(enable) ; Loop has a runtime trip count and should be runtime unrolled and duplicated @@ -324,12 +297,12 @@ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 %lftr.wideiv = trunc i64 %indvars.iv.next to i32 %exitcond = icmp eq i32 %lftr.wideiv, %b - br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !15 + br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !14 for.end: ; preds = %for.body, %entry ret void } -!15 = !{!15, !14} +!14 = !{!14, !13} ; #pragma clang loop unroll_count(3) ; Loop has a runtime trip count. Runtime unrolling should occur and loop @@ -363,10 +336,10 @@ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 %lftr.wideiv = trunc i64 %indvars.iv.next to i32 %exitcond = icmp eq i32 %lftr.wideiv, %b - br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !16 + br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !15 for.end: ; preds = %for.body, %entry ret void } -!16 = !{!16, !17} -!17 = !{!"llvm.loop.unroll.count", i32 3} +!15 = !{!15, !16} +!16 = !{!"llvm.loop.unroll.count", i32 3}