Skip to content

Commit fddc3b3

Browse files
committed
Add BasicTTIImplBase implementation for histogram ops
1 parent 7681d5b commit fddc3b3

File tree

5 files changed

+148
-46
lines changed

5 files changed

+148
-46
lines changed

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,9 +878,6 @@ class TargetTransformInfoImplBase {
878878
switch (ICA.getID()) {
879879
default:
880880
break;
881-
case Intrinsic::experimental_vector_histogram_add:
882-
// For now, we want explicit support from the target for histograms.
883-
return InstructionCost::getInvalid();
884881
case Intrinsic::allow_runtime_check:
885882
case Intrinsic::allow_ubsan_check:
886883
case Intrinsic::annotation:

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
21102110
}
21112111
case Intrinsic::get_active_lane_mask:
21122112
case Intrinsic::experimental_vector_match:
2113+
case Intrinsic::experimental_vector_histogram_add:
21132114
return thisT()->getTypeBasedIntrinsicInstrCost(ICA, CostKind);
21142115
case Intrinsic::modf:
21152116
case Intrinsic::sincos:
@@ -2458,6 +2459,51 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
24582459
thisT()->getArithmeticInstrCost(BinaryOperator::And, RetTy, CostKind);
24592460
return Cost;
24602461
}
2462+
case Intrinsic::experimental_vector_histogram_add:
2463+
case Intrinsic::experimental_vector_histogram_uadd_sat:
2464+
case Intrinsic::experimental_vector_histogram_umax:
2465+
case Intrinsic::experimental_vector_histogram_umin: {
2466+
FixedVectorType *PtrsTy = dyn_cast<FixedVectorType>(ICA.getArgTypes()[0]);
2467+
Type *EltTy = ICA.getArgTypes()[1];
2468+
2469+
// Targets with scalable vectors must handle this on their own.
2470+
if (!PtrsTy)
2471+
return InstructionCost::getInvalid();
2472+
2473+
Align Alignment = thisT()->DL.getABITypeAlign(EltTy);
2474+
InstructionCost Cost = 0;
2475+
Cost += thisT()->getVectorInstrCost(Instruction::ExtractElement, PtrsTy,
2476+
CostKind, 1, nullptr, nullptr);
2477+
Cost += thisT()->getMemoryOpCost(Instruction::Load, EltTy, Alignment, 0,
2478+
CostKind);
2479+
switch (IID) {
2480+
default:
2481+
llvm_unreachable("Unhandled histogram update operation.");
2482+
case Intrinsic::experimental_vector_histogram_add:
2483+
Cost +=
2484+
thisT()->getArithmeticInstrCost(Instruction::Add, EltTy, CostKind);
2485+
break;
2486+
case Intrinsic::experimental_vector_histogram_uadd_sat: {
2487+
IntrinsicCostAttributes UAddSat(Intrinsic::uadd_sat, EltTy, {EltTy});
2488+
Cost += thisT()->getIntrinsicInstrCost(UAddSat, CostKind);
2489+
break;
2490+
}
2491+
case Intrinsic::experimental_vector_histogram_umax: {
2492+
IntrinsicCostAttributes UMax(Intrinsic::umax, EltTy, {EltTy});
2493+
Cost += thisT()->getIntrinsicInstrCost(UMax, CostKind);
2494+
break;
2495+
}
2496+
case Intrinsic::experimental_vector_histogram_umin: {
2497+
IntrinsicCostAttributes UMin(Intrinsic::umin, EltTy, {EltTy});
2498+
Cost += thisT()->getIntrinsicInstrCost(UMin, CostKind);
2499+
break;
2500+
}
2501+
}
2502+
Cost += thisT()->getMemoryOpCost(Instruction::Store, EltTy, Alignment, 0,
2503+
CostKind);
2504+
Cost *= PtrsTy->getNumElements();
2505+
return Cost;
2506+
}
24612507
case Intrinsic::get_active_lane_mask: {
24622508
Type *ArgTy = ICA.getArgTypes()[0];
24632509
EVT ResVT = getTLI()->getValueType(DL, RetTy, true);

0 commit comments

Comments
 (0)