[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:26:51 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(
----------------
preames wrote:
I don't think this type is correct. Consider: %v2 = bitcast <24 x i8> %v to <192 x i1>
The legalized wider type will be <32 x i8>, but having the src type be <32 x i1> seems quite wrong.
https://github.com/llvm/llvm-project/pull/107303
More information about the llvm-commits
mailing list