[llvm-branch-commits] [llvm] 6a03f8a - [SLP] reduce code for finding reduction costs; NFC
Sanjay Patel via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 5 14:40:48 PST 2021
Author: Sanjay Patel
Date: 2021-01-05T17:35:54-05:00
New Revision: 6a03f8ab629b34a2425764caaa46dbfcf3d8e1ef
URL: https://github.com/llvm/llvm-project/commit/6a03f8ab629b34a2425764caaa46dbfcf3d8e1ef
DIFF: https://github.com/llvm/llvm-project/commit/6a03f8ab629b34a2425764caaa46dbfcf3d8e1ef.diff
LOG: [SLP] reduce code for finding reduction costs; NFC
We can get both (vector/scalar) costs in a single switch
instead of sequentially.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 48f2a2d2886f..92e3ae7bea8b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -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:
@@ -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:
@@ -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;
}
More information about the llvm-branch-commits
mailing list