[llvm] [BasicTTI] Use getTypeLegalizationCost to generalize vector cast cost. (PR #107303)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 13:15:42 PDT 2024
================
@@ -1171,9 +1171,50 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
CostKind, I));
}
+ // Check if the wider type of Src and Dst needs to be legalized. If it
+ // does, compute the cost of the cast based on vectors with the same
+ // number of elements as the legalized widest type. Don't directly return
+ // the cost, as scalarization may be more profitable, which has its cost
+ // computed below.
+ // TODO: Use the more general logic below to replace the specific logic
+ // above to also handle cost for legalization via splitting above.
+ InstructionCost LegalizedCost = InstructionCost::getInvalid();
+ if (SrcVTy->getElementCount().isVector() &&
+ DstVTy->getElementCount().isVector()) {
+ Type *WiderTy =
+ Src->getScalarSizeInBits() < Dst->getScalarSizeInBits() ? Dst : Src;
+ auto [WiderLegalCost, WiderLegalTy] = getTypeLegalizationCost(WiderTy);
+ if (WiderLegalTy.isVector() &&
+ TLI->getValueType(DL, WiderTy) != WiderLegalTy) {
+ Type *SplitDstTy = VectorType::get(
+ DstVTy->getElementType(), WiderLegalTy.getVectorElementCount());
+ Type *SplitSrcTy = VectorType::get(
+ SrcVTy->getElementType(), WiderLegalTy.getVectorElementCount());
+ if (SplitDstTy != Dst && SplitSrcTy != Src) {
+ bool SplitSrc = TLI->getTypeAction(Src->getContext(),
----------------
preames wrote:
Since you haven't change Src or Dst, this logic should be dead. The splitting part of this would be handled above.
I think what you're actual implementing here is a mixture of vector widening, and splitting *after* widening. I think you need to separate those two to avoid costing problems.
https://github.com/llvm/llvm-project/pull/107303
More information about the llvm-commits
mailing list