Skip to content

Commit

Permalink
[AArch64] Expand the SVE min/max reduction costs to NEON
Browse files Browse the repository at this point in the history
This takes the existing SVE costing for the various min/max reduction
intrinsics and expands it to NEON, where I believe it applies equally
well.

In the process it changes the lowering to use min/max cost, as opposed
to summing up the cost of ICmp+Select.

Differential Revision: https://reviews.llvm.org/D106239
  • Loading branch information
davemgreen committed Aug 5, 2021
1 parent a919165 commit 649cf45
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 124 deletions.
25 changes: 13 additions & 12 deletions llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/CodeGen/BasicTTIImpl.h"
#include "llvm/CodeGen/CostTable.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/IntrinsicsAArch64.h"
#include "llvm/IR/PatternMatch.h"
Expand Down Expand Up @@ -1899,23 +1900,23 @@ InstructionCost
AArch64TTIImpl::getMinMaxReductionCost(VectorType *Ty, VectorType *CondTy,
bool IsUnsigned,
TTI::TargetCostKind CostKind) {
if (!isa<ScalableVectorType>(Ty))
std::pair<InstructionCost, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty);

if (LT.second.getScalarType() == MVT::f16 && !ST->hasFullFP16())
return BaseT::getMinMaxReductionCost(Ty, CondTy, IsUnsigned, CostKind);
assert((isa<ScalableVectorType>(Ty) && isa<ScalableVectorType>(CondTy)) &&
"Both vector needs to be scalable");

std::pair<InstructionCost, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty);
assert((isa<ScalableVectorType>(Ty) == isa<ScalableVectorType>(CondTy)) &&
"Both vector needs to be equally scalable");

InstructionCost LegalizationCost = 0;
if (LT.first > 1) {
Type *LegalVTy = EVT(LT.second).getTypeForEVT(Ty->getContext());
unsigned CmpOpcode =
Ty->isFPOrFPVectorTy() ? Instruction::FCmp : Instruction::ICmp;
LegalizationCost =
getCmpSelInstrCost(CmpOpcode, LegalVTy, LegalVTy,
CmpInst::BAD_ICMP_PREDICATE, CostKind) +
getCmpSelInstrCost(Instruction::Select, LegalVTy, LegalVTy,
CmpInst::BAD_ICMP_PREDICATE, CostKind);
LegalizationCost *= LT.first - 1;
unsigned MinMaxOpcode =
Ty->isFPOrFPVectorTy()
? Intrinsic::maxnum
: (IsUnsigned ? Intrinsic::umin : Intrinsic::smin);
IntrinsicCostAttributes Attrs(MinMaxOpcode, LegalVTy, {LegalVTy, LegalVTy});
LegalizationCost = getIntrinsicInstrCost(Attrs, CostKind) * (LT.first - 1);
}

return LegalizationCost + /*Cost of horizontal reduction*/ 2;
Expand Down
Loading

0 comments on commit 649cf45

Please sign in to comment.