Skip to content

Commit c482629

Browse files
committed
Prevent LoopUnrollPass from doing partial unroll if TripCount and MaxTripCount are unknown
1 parent bdec5bf commit c482629

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,8 @@ tryToUnrollLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
13271327
}
13281328

13291329
// Do not attempt partial/runtime unrolling in FullLoopUnrolling
1330-
if (OnlyFullUnroll && (UP.Count < TripCount || UP.Count < MaxTripCount)) {
1330+
if (OnlyFullUnroll && ((!TripCount && !MaxTripCount) ||
1331+
UP.Count < TripCount || UP.Count < MaxTripCount)) {
13311332
LLVM_DEBUG(
13321333
dbgs() << "Not attempting partial/runtime unroll in FullLoopUnroll.\n");
13331334
return LoopUnrollResult::Unmodified;

llvm/test/Transforms/LoopUnroll/full-unroll-avoid-partial.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,34 @@ for.body: ; preds = %for.body.preheader,
8585
br i1 %exitcond, label %for.body, label %for.cond.cleanup.loopexit, !llvm.loop !3
8686
}
8787

88+
; LOOP-UNROLL-LABEL: Loop Unroll: F[pragma_unroll_count2] Loop %
89+
; LOOP-UNROLL-NEXT: Loop Size = 4
90+
; LOOP-UNROLL-NEXT: Exiting block %: TripCount=0, TripMultiple=1, BreakoutTrip=1
91+
; LOOP-UNROLL-NEXT: Trying runtime unrolling on Loop:
92+
; LOOP-UNROLL-NEXT: Loop at depth 1 containing: %2<header><exiting>,%5<latch>
93+
; LOOP-UNROLL-NEXT: Using epilog remainder.
94+
; LOOP-UNROLL-NEXT: Loop latch not terminated by a conditional branch.
95+
; LOOP-UNROLL-NEXT: UNROLLING loop % by 5!
96+
97+
; LOOP-UNROLL-FULL-LABEL: Loop Unroll: F[pragma_unroll_count2] Loop %
98+
; LOOP-UNROLL-FULL-NEXT: Loop Size = 4
99+
; LOOP-UNROLL-FULL-NEXT: Not attempting partial/runtime unroll in FullLoopUnroll
100+
define void @pragma_unroll_count2(i64 %0) {
101+
br label %2
102+
103+
2: ; preds = %5, %1
104+
%3 = phi i64 [ 0, %1 ], [ %6, %5 ]
105+
%4 = icmp ult i64 %3, %0
106+
br i1 %4, label %5, label %7
107+
108+
5: ; preds = %2
109+
%6 = add i64 %3, 8
110+
br label %2, !llvm.loop !3
111+
112+
7: ; preds = %2
113+
ret void
114+
}
115+
88116
; LOOP-UNROLL: llvm.loop.unroll.disable
89117
; LOOP-UNROLL-FULL: llvm.loop.unroll.enable
90118
!0 = !{!"llvm.loop.unroll.enable"}

0 commit comments

Comments
 (0)