Skip to content

Commit c87982b

Browse files
Revert "[Loop Peeling] Add possibility to enable peeling on loop nests."
This reverts commit 3f3017e because there's a failure on peel-loop-nests.ll with LLVM_ENABLE_EXPENSIVE_CHECKS on. Differential Revision: https://reviews.llvm.org/D70304
1 parent d51a15d commit c87982b

File tree

5 files changed

+93
-194
lines changed

5 files changed

+93
-194
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,6 @@ class TargetTransformInfo {
490490
bool UpperBound;
491491
/// Allow peeling off loop iterations.
492492
bool AllowPeeling;
493-
/// Allow peeling off loop iterations for loop nests.
494-
bool AllowLoopNestsPeeling;
495493
/// Allow unrolling of all the iterations of the runtime loop remainder.
496494
bool UnrollRemainder;
497495
/// Allow unroll and jam. Used to enable unroll and jam for the target.

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ static cl::opt<bool>
154154
cl::desc("Allows loops to be peeled when the dynamic "
155155
"trip count is known to be low."));
156156

157-
static cl::opt<bool> UnrollAllowLoopNestsPeeling(
158-
"unroll-allow-loop-nests-peeling", cl::init(false), cl::Hidden,
159-
cl::desc("Allows loop nests to be peeled."));
160-
161157
static cl::opt<bool> UnrollUnrollRemainder(
162158
"unroll-remainder", cl::Hidden,
163159
cl::desc("Allow the loop remainder to be unrolled."));
@@ -219,7 +215,6 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
219215
UP.Force = false;
220216
UP.UpperBound = false;
221217
UP.AllowPeeling = true;
222-
UP.AllowLoopNestsPeeling = false;
223218
UP.UnrollAndJam = false;
224219
UP.PeelProfiledIterations = true;
225220
UP.UnrollAndJamInnerLoopThreshold = 60;
@@ -260,8 +255,6 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
260255
UP.UpperBound = false;
261256
if (UnrollAllowPeeling.getNumOccurrences() > 0)
262257
UP.AllowPeeling = UnrollAllowPeeling;
263-
if (UnrollAllowLoopNestsPeeling.getNumOccurrences() > 0)
264-
UP.AllowLoopNestsPeeling = UnrollAllowLoopNestsPeeling;
265258
if (UnrollUnrollRemainder.getNumOccurrences() > 0)
266259
UP.UnrollRemainder = UnrollUnrollRemainder;
267260

llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,8 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
289289
if (!canPeel(L))
290290
return;
291291

292-
// Only try to peel innermost loops by default.
293-
// The constraint can be relaxed by the target in TTI.getUnrollingPreferences
294-
// or by the flag -unroll-allow-loop-nests-peeling.
295-
if (!UP.AllowLoopNestsPeeling && !L->empty())
292+
// Only try to peel innermost loops.
293+
if (!L->empty())
296294
return;
297295

298296
// If the user provided a peel count, use that.

llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,76 @@ for.end:
403403
ret void
404404
}
405405

406+
; In this case we cannot peel the inner loop, because the condition involves
407+
; the outer induction variable.
408+
define void @test5(i32 %k) {
409+
; CHECK-LABEL: @test5(
410+
; CHECK-NEXT: for.body.lr.ph:
411+
; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
412+
; CHECK: outer.header:
413+
; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[J_INC:%.*]], [[OUTER_INC:%.*]] ]
414+
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
415+
; CHECK: for.body:
416+
; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[OUTER_HEADER]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
417+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[J]], 2
418+
; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
419+
; CHECK: if.then:
420+
; CHECK-NEXT: call void @f1()
421+
; CHECK-NEXT: br label [[FOR_INC]]
422+
; CHECK: if.else:
423+
; CHECK-NEXT: call void @f2()
424+
; CHECK-NEXT: br label [[FOR_INC]]
425+
; CHECK: for.inc:
426+
; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1
427+
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
428+
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[OUTER_INC]]
429+
; CHECK: outer.inc:
430+
; CHECK-NEXT: [[J_INC]] = add nsw i32 [[J]], 1
431+
; CHECK-NEXT: [[OUTER_CMP:%.*]] = icmp slt i32 [[J_INC]], [[K]]
432+
; CHECK-NEXT: br i1 [[OUTER_CMP]], label [[OUTER_HEADER]], label [[FOR_END:%.*]]
433+
; CHECK: for.end:
434+
; CHECK-NEXT: ret void
435+
;
436+
for.body.lr.ph:
437+
br label %outer.header
438+
439+
outer.header:
440+
%j = phi i32 [ 0, %for.body.lr.ph ], [ %j.inc, %outer.inc ]
441+
br label %for.body
442+
443+
for.body:
444+
%i.05 = phi i32 [ 0, %outer.header ], [ %inc, %for.inc ]
445+
%cmp1 = icmp ult i32 %j, 2
446+
br i1 %cmp1, label %if.then, label %if.else
447+
448+
if.then:
449+
call void @f1()
450+
br label %for.inc
451+
452+
if.else:
453+
call void @f2()
454+
br label %for.inc
455+
456+
for.inc:
457+
%inc = add nsw i32 %i.05, 1
458+
%cmp = icmp slt i32 %inc, %k
459+
br i1 %cmp, label %for.body, label %outer.inc
460+
461+
outer.inc:
462+
%j.inc = add nsw i32 %j, 1
463+
%outer.cmp = icmp slt i32 %j.inc, %k
464+
br i1 %outer.cmp, label %outer.header, label %for.end
465+
466+
467+
for.end:
468+
ret void
469+
}
470+
406471
; In this test, the condition involves 2 AddRecs. Without evaluating both
407472
; AddRecs, we cannot prove that the condition becomes known in the loop body
408473
; after peeling.
409-
define void @test5(i32 %k) {
410-
; CHECK-LABEL: @test5(
474+
define void @test6(i32 %k) {
475+
; CHECK-LABEL: @test6(
411476
; CHECK-NEXT: entry:
412477
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
413478
; CHECK: for.body:
@@ -456,8 +521,8 @@ for.end:
456521
ret void
457522
}
458523

459-
define void @test6(i32 %k) {
460-
; CHECK-LABEL: @test6(
524+
define void @test7(i32 %k) {
525+
; CHECK-LABEL: @test7(
461526
; CHECK-NEXT: for.body.lr.ph:
462527
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
463528
; CHECK: for.body.peel.begin:
@@ -550,8 +615,8 @@ for.end:
550615
ret void
551616
}
552617

553-
define void @test7(i32 %k) {
554-
; CHECK-LABEL: @test7(
618+
define void @test8(i32 %k) {
619+
; CHECK-LABEL: @test8(
555620
; CHECK-NEXT: for.body.lr.ph:
556621
; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
557622
; CHECK: for.body.peel.begin:
@@ -646,8 +711,8 @@ for.end:
646711

647712
; Comparison with non-monotonic predicate due to possible wrapping, loop
648713
; body cannot be simplified.
649-
define void @test8(i32 %k) {
650-
; CHECK-LABEL: @test8(
714+
define void @test9(i32 %k) {
715+
; CHECK-LABEL: @test9(
651716
; CHECK-NEXT: for.body.lr.ph:
652717
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
653718
; CHECK: for.body:
@@ -686,8 +751,8 @@ for.end:
686751
}
687752
; CHECK-NOT: llvm.loop.unroll.disable
688753

689-
define void @test_9__peel_first_iter_via_slt_pred(i32 %len) {
690-
; CHECK-LABEL: @test_9__peel_first_iter_via_slt_pred(
754+
define void @test_10__peel_first_iter_via_slt_pred(i32 %len) {
755+
; CHECK-LABEL: @test_10__peel_first_iter_via_slt_pred(
691756
; CHECK-NEXT: entry:
692757
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
693758
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
@@ -753,8 +818,8 @@ if.end: ; preds = %if.then, %for.body
753818
br i1 %exitcond, label %for.cond.cleanup, label %for.body
754819
}
755820

756-
define void @test_10__peel_first_iter_via_sgt_pred(i32 %len) {
757-
; CHECK-LABEL: @test_10__peel_first_iter_via_sgt_pred(
821+
define void @test_11__peel_first_iter_via_sgt_pred(i32 %len) {
822+
; CHECK-LABEL: @test_11__peel_first_iter_via_sgt_pred(
758823
; CHECK-NEXT: entry:
759824
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
760825
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
@@ -822,8 +887,8 @@ if.end: ; preds = %if.then, %for.body
822887

823888
; NOTE: here we should only peel the first iteration,
824889
; i.e. all calls to sink() must stay in loop.
825-
define void @test11__peel_first_iter_via_eq_pred(i32 %len) {
826-
; CHECK-LABEL: @test11__peel_first_iter_via_eq_pred(
890+
define void @test12__peel_first_iter_via_eq_pred(i32 %len) {
891+
; CHECK-LABEL: @test12__peel_first_iter_via_eq_pred(
827892
; CHECK-NEXT: entry:
828893
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
829894
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
@@ -891,8 +956,8 @@ if.end: ; preds = %if.then, %for.body
891956

892957
; NOTE: here we should only peel the first iteration,
893958
; i.e. all calls to sink() must stay in loop.
894-
define void @test12__peel_first_iter_via_ne_pred(i32 %len) {
895-
; CHECK-LABEL: @test12__peel_first_iter_via_ne_pred(
959+
define void @test13__peel_first_iter_via_ne_pred(i32 %len) {
960+
; CHECK-LABEL: @test13__peel_first_iter_via_ne_pred(
896961
; CHECK-NEXT: entry:
897962
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
898963
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
@@ -959,8 +1024,8 @@ if.end: ; preds = %if.then, %for.body
9591024
}
9601025

9611026
; No peeling is profitable here.
962-
define void @test13__ivar_mod2_is_1(i32 %len) {
963-
; CHECK-LABEL: @test13__ivar_mod2_is_1(
1027+
define void @test14__ivar_mod2_is_1(i32 %len) {
1028+
; CHECK-LABEL: @test14__ivar_mod2_is_1(
9641029
; CHECK-NEXT: entry:
9651030
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
9661031
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
@@ -1009,8 +1074,8 @@ if.end: ; preds = %if.then, %for.body
10091074
}
10101075

10111076
; No peeling is profitable here.
1012-
define void @test14__ivar_mod2_is_0(i32 %len) {
1013-
; CHECK-LABEL: @test14__ivar_mod2_is_0(
1077+
define void @test15__ivar_mod2_is_0(i32 %len) {
1078+
; CHECK-LABEL: @test15__ivar_mod2_is_0(
10141079
; CHECK-NEXT: entry:
10151080
; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[LEN:%.*]], 0
10161081
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
@@ -1058,10 +1123,10 @@ if.end: ; preds = %if.then, %for.body
10581123
br i1 %exitcond, label %for.cond.cleanup, label %for.body
10591124
}
10601125

1061-
; Similar to @test6, we need to peel one extra iteration, and we can't do that
1126+
; Similar to @test7, we need to peel one extra iteration, and we can't do that
10621127
; as per the -unroll-peel-max-count=4, so this shouldn't be peeled at all.
1063-
define void @test15(i32 %k) {
1064-
; CHECK-LABEL: @test15(
1128+
define void @test16(i32 %k) {
1129+
; CHECK-LABEL: @test16(
10651130
; CHECK-NEXT: for.body.lr.ph:
10661131
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
10671132
; CHECK: for.body:
@@ -1099,10 +1164,10 @@ for.end:
10991164
ret void
11001165
}
11011166

1102-
; Similar to @test7, we need to peel one extra iteration, and we can't do that
1167+
; Similar to @test8, we need to peel one extra iteration, and we can't do that
11031168
; as per the -unroll-peel-max-count=4, so this shouldn't be peeled at all.
1104-
define void @test16(i32 %k) {
1105-
; CHECK-LABEL: @test16(
1169+
define void @test17(i32 %k) {
1170+
; CHECK-LABEL: @test17(
11061171
; CHECK-NEXT: for.body.lr.ph:
11071172
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
11081173
; CHECK: for.body:

0 commit comments

Comments
 (0)