[SLP] fix formatting; NFC

Also move variable declarations closer to usage and add code comments.
This commit is contained in:
Sanjay Patel 2020-09-16 08:47:35 -04:00
parent 4dd9c709ef
commit 24238f09ed
1 changed files with 23 additions and 21 deletions

View File

@ -6805,10 +6805,6 @@ public:
if (NumReducedVals < 4) if (NumReducedVals < 4)
return false; return false;
unsigned ReduxWidth = PowerOf2Floor(NumReducedVals);
Value *VectorizedTree = nullptr;
// FIXME: Fast-math-flags should be set based on the instructions in the // FIXME: Fast-math-flags should be set based on the instructions in the
// reduction (not all of 'fast' are required). // reduction (not all of 'fast' are required).
IRBuilder<> Builder(cast<Instruction>(ReductionRoot)); IRBuilder<> Builder(cast<Instruction>(ReductionRoot));
@ -6842,7 +6838,9 @@ public:
for (ReductionOpsType &RdxOp : ReductionOps) for (ReductionOpsType &RdxOp : ReductionOps)
IgnoreList.append(RdxOp.begin(), RdxOp.end()); IgnoreList.append(RdxOp.begin(), RdxOp.end());
Value *VectorizedTree = nullptr;
unsigned i = 0; unsigned i = 0;
unsigned ReduxWidth = PowerOf2Floor(NumReducedVals);
while (i < NumReducedVals - ReduxWidth + 1 && ReduxWidth > 2) { while (i < NumReducedVals - ReduxWidth + 1 && ReduxWidth > 2) {
ArrayRef<Value *> VL = makeArrayRef(&ReducedVals[i], ReduxWidth); ArrayRef<Value *> VL = makeArrayRef(&ReducedVals[i], ReduxWidth);
V.buildTree(VL, ExternallyUsedValues, IgnoreList); V.buildTree(VL, ExternallyUsedValues, IgnoreList);
@ -6867,25 +6865,25 @@ public:
int ReductionCost = getReductionCost(TTI, ReducedVals[i], ReduxWidth); int ReductionCost = getReductionCost(TTI, ReducedVals[i], ReduxWidth);
int Cost = TreeCost + ReductionCost; int Cost = TreeCost + ReductionCost;
if (Cost >= -SLPCostThreshold) { if (Cost >= -SLPCostThreshold) {
V.getORE()->emit([&]() { V.getORE()->emit([&]() {
return OptimizationRemarkMissed( return OptimizationRemarkMissed(SV_NAME, "HorSLPNotBeneficial",
SV_NAME, "HorSLPNotBeneficial", cast<Instruction>(VL[0])) cast<Instruction>(VL[0]))
<< "Vectorizing horizontal reduction is possible" << "Vectorizing horizontal reduction is possible"
<< "but not beneficial with cost " << "but not beneficial with cost " << ore::NV("Cost", Cost)
<< ore::NV("Cost", Cost) << " and threshold " << " and threshold "
<< ore::NV("Threshold", -SLPCostThreshold); << ore::NV("Threshold", -SLPCostThreshold);
}); });
break; break;
} }
LLVM_DEBUG(dbgs() << "SLP: Vectorizing horizontal reduction at cost:" LLVM_DEBUG(dbgs() << "SLP: Vectorizing horizontal reduction at cost:"
<< Cost << ". (HorRdx)\n"); << Cost << ". (HorRdx)\n");
V.getORE()->emit([&]() { V.getORE()->emit([&]() {
return OptimizationRemark( return OptimizationRemark(SV_NAME, "VectorizedHorizontalReduction",
SV_NAME, "VectorizedHorizontalReduction", cast<Instruction>(VL[0])) cast<Instruction>(VL[0]))
<< "Vectorized horizontal reduction with cost " << "Vectorized horizontal reduction with cost "
<< ore::NV("Cost", Cost) << " and with tree size " << ore::NV("Cost", Cost) << " and with tree size "
<< ore::NV("TreeSize", V.getTreeSize()); << ore::NV("TreeSize", V.getTreeSize());
}); });
// Vectorize a tree. // Vectorize a tree.
@ -6902,15 +6900,19 @@ public:
Value *ReducedSubTree = Value *ReducedSubTree =
emitReduction(VectorizedRoot, Builder, ReduxWidth, TTI); emitReduction(VectorizedRoot, Builder, ReduxWidth, TTI);
if (VectorizedTree) {
if (!VectorizedTree) {
// Initialize the final value in the reduction.
VectorizedTree = ReducedSubTree;
} else {
// Update the final value in the reduction.
Builder.SetCurrentDebugLocation(Loc); Builder.SetCurrentDebugLocation(Loc);
OperationData VectReductionData(ReductionData.getOpcode(), OperationData VectReductionData(ReductionData.getOpcode(),
VectorizedTree, ReducedSubTree, VectorizedTree, ReducedSubTree,
ReductionData.getKind()); ReductionData.getKind());
VectorizedTree = VectorizedTree =
VectReductionData.createOp(Builder, "op.rdx", ReductionOps); VectReductionData.createOp(Builder, "op.rdx", ReductionOps);
} else }
VectorizedTree = ReducedSubTree;
i += ReduxWidth; i += ReduxWidth;
ReduxWidth = PowerOf2Floor(NumReducedVals - i); ReduxWidth = PowerOf2Floor(NumReducedVals - i);
} }