Skip to content

Commit 7f90b45

Browse files
committedJan 27, 2014
[vectorizer] Add some flags which are useful for conducting experiments
with the unrolling behavior in the loop vectorizer. No functionality changed at this point. These are a bit hack-y, but talking with Hal, there doesn't seem to be a cleaner way to easily experiment with different thresholds here and he was also interested in them so I wanted to commit them. Suggestions for improvement are very welcome here. llvm-svn: 200212
1 parent 328998b commit 7f90b45

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed
 

‎llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

+38-2
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,30 @@ static const unsigned RuntimeMemoryCheckThreshold = 8;
139139
/// Maximum simd width.
140140
static const unsigned MaxVectorWidth = 64;
141141

142+
static cl::opt<unsigned> ForceTargetNumScalarRegs(
143+
"force-target-num-scalar-regs", cl::init(0), cl::Hidden,
144+
cl::desc("A flag that overrides the target's number of scalar registers."));
145+
146+
static cl::opt<unsigned> ForceTargetNumVectorRegs(
147+
"force-target-num-vector-regs", cl::init(0), cl::Hidden,
148+
cl::desc("A flag that overrides the target's number of vector registers."));
149+
142150
/// Maximum vectorization unroll count.
143151
static const unsigned MaxUnrollFactor = 16;
144152

145-
/// The cost of a loop that is considered 'small' by the unroller.
146-
static const unsigned SmallLoopCost = 20;
153+
static cl::opt<unsigned> ForceTargetMaxScalarUnrollFactor(
154+
"force-target-max-scalar-unroll", cl::init(0), cl::Hidden,
155+
cl::desc("A flag that overrides the target's max unroll factor for scalar "
156+
"loops."));
157+
158+
static cl::opt<unsigned> ForceTargetMaxVectorUnrollFactor(
159+
"force-target-max-vector-unroll", cl::init(0), cl::Hidden,
160+
cl::desc("A flag that overrides the target's max unroll factor for "
161+
"vectorized loops."));
162+
163+
static cl::opt<unsigned> SmallLoopCost(
164+
"small-loop-cost", cl::init(20), cl::Hidden,
165+
cl::desc("The cost of a loop that is considered 'small' by the unroller."));
147166

148167
namespace {
149168

@@ -4966,6 +4985,14 @@ LoopVectorizationCostModel::selectUnrollFactor(bool OptForSize,
49664985
DEBUG(dbgs() << "LV: The target has " << TargetNumRegisters <<
49674986
" registers\n");
49684987

4988+
if (VF == 1) {
4989+
if (ForceTargetNumScalarRegs.getNumOccurrences() > 0)
4990+
TargetNumRegisters = ForceTargetNumScalarRegs;
4991+
} else {
4992+
if (ForceTargetNumVectorRegs.getNumOccurrences() > 0)
4993+
TargetNumRegisters = ForceTargetNumVectorRegs;
4994+
}
4995+
49694996
LoopVectorizationCostModel::RegisterUsage R = calculateRegisterUsage();
49704997
// We divide by these constants so assume that we have at least one
49714998
// instruction that uses at least one register.
@@ -4983,6 +5010,15 @@ LoopVectorizationCostModel::selectUnrollFactor(bool OptForSize,
49835010
// Clamp the unroll factor ranges to reasonable factors.
49845011
unsigned MaxUnrollSize = TTI.getMaximumUnrollFactor();
49855012

5013+
// Check if the user has overridden the unroll max.
5014+
if (VF == 1) {
5015+
if (ForceTargetMaxScalarUnrollFactor.getNumOccurrences() > 0)
5016+
MaxUnrollSize = ForceTargetMaxScalarUnrollFactor;
5017+
} else {
5018+
if (ForceTargetMaxVectorUnrollFactor.getNumOccurrences() > 0)
5019+
MaxUnrollSize = ForceTargetMaxVectorUnrollFactor;
5020+
}
5021+
49865022
// If we did not calculate the cost for VF (because the user selected the VF)
49875023
// then we calculate the cost of VF here.
49885024
if (LoopCost == 0)

0 commit comments

Comments
 (0)
Please sign in to comment.