Skip to content

Commit 77fdbc1

Browse files
committed
Use ScaledThreshold to calculate Unroll count
Earlier we were using partial threshold to calculate unroll count for loop but for small loops it is giving more unroll count which is degrading the performance.Using Scaled Threshold improves the performance.
1 parent 5e07093 commit 77fdbc1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ class TargetTransformInfo {
574574
/// The cost threshold for the unrolled loop, like Threshold, but used
575575
/// for partial/runtime unrolling (set to UINT_MAX to disable).
576576
unsigned PartialThreshold;
577+
/// The cost threshold for the unrolled loop, like Threshold, but used
578+
/// for calculating unroll count for loop.
579+
unsigned ScaledThreshold;
577580
/// The cost threshold for the unrolled loop when optimizing for size, like
578581
/// OptSizeThreshold, but used for partial/runtime unrolling (set to
579582
/// UINT_MAX to disable).

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
201201
UP.MaxPercentThresholdBoost = 400;
202202
UP.OptSizeThreshold = UnrollOptSizeThreshold;
203203
UP.PartialThreshold = 150;
204+
UP.ScaledThreshold = 100;
204205
UP.PartialOptSizeThreshold = UnrollOptSizeThreshold;
205206
UP.Count = 0;
206207
UP.DefaultUnrollRuntimeCount = 8;
@@ -884,8 +885,8 @@ shouldPartialUnroll(const unsigned LoopSize, const unsigned TripCount,
884885
if (UP.PartialThreshold != NoThreshold) {
885886
// Reduce unroll count to be modulo of TripCount for partial unrolling.
886887
if (UCE.getUnrolledLoopSize(UP, count) > UP.PartialThreshold)
887-
count = (std::max(UP.PartialThreshold, UP.BEInsns + 1) - UP.BEInsns) /
888-
(LoopSize - UP.BEInsns);
888+
count = (std::max(UP.ScaledThreshold, UP.BEInsns + 1) - UP.BEInsns) /
889+
(LoopSize - UP.BEInsns);
889890
if (count > UP.MaxCount)
890891
count = UP.MaxCount;
891892
while (count != 0 && TripCount % count != 0)

0 commit comments

Comments
 (0)