Skip to content

Commit

Permalink
[SLP] reduce code for finding reduction costs; NFC
Browse files Browse the repository at this point in the history
We can get both (vector/scalar) costs in a single switch
instead of sequentially.
  • Loading branch information
rotateright committed Jan 5, 2021
1 parent 1ebe86a commit 6a03f8a
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7140,6 +7140,7 @@ class HorizontalReduction {
RecurKind Kind = RdxTreeInst.getKind();
unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(Kind);
int SplittingRdxCost;
int ScalarReduxCost;
switch (Kind) {
case RecurKind::Add:
case RecurKind::Mul:
Expand All @@ -7150,6 +7151,7 @@ class HorizontalReduction {
case RecurKind::FMul:
SplittingRdxCost = TTI->getArithmeticReductionCost(
RdxOpcode, VecTy, /*IsPairwiseForm=*/false);
ScalarReduxCost = TTI->getArithmeticInstrCost(RdxOpcode, ScalarTy);
break;
case RecurKind::SMax:
case RecurKind::SMin:
Expand All @@ -7160,42 +7162,21 @@ class HorizontalReduction {
SplittingRdxCost =
TTI->getMinMaxReductionCost(VecTy, VecCondTy,
/*IsPairwiseForm=*/false, IsUnsigned);
break;
}
default:
llvm_unreachable("Expected arithmetic or min/max reduction operation");
}

int ScalarReduxCost = 0;
switch (Kind) {
case RecurKind::Add:
case RecurKind::Mul:
case RecurKind::Or:
case RecurKind::And:
case RecurKind::Xor:
case RecurKind::FAdd:
case RecurKind::FMul:
ScalarReduxCost = TTI->getArithmeticInstrCost(RdxOpcode, ScalarTy);
break;
case RecurKind::SMax:
case RecurKind::SMin:
case RecurKind::UMax:
case RecurKind::UMin:
ScalarReduxCost =
TTI->getCmpSelInstrCost(RdxOpcode, ScalarTy) +
TTI->getCmpSelInstrCost(Instruction::Select, ScalarTy,
CmpInst::makeCmpResultType(ScalarTy));
break;
}
default:
llvm_unreachable("Expected arithmetic or min/max reduction operation");
}
ScalarReduxCost *= (ReduxWidth - 1);

ScalarReduxCost *= (ReduxWidth - 1);
LLVM_DEBUG(dbgs() << "SLP: Adding cost "
<< SplittingRdxCost - ScalarReduxCost
<< " for reduction that starts with " << *FirstReducedVal
<< " (It is a splitting reduction)\n");

return SplittingRdxCost - ScalarReduxCost;
}

Expand Down

0 comments on commit 6a03f8a

Please sign in to comment.