[llvm] [AArch64] Improve cost model for legal subvec insert/extract (PR #81135)
Graham Hunter via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 19 06:17:26 PST 2024
================
@@ -568,6 +568,48 @@ AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
}
return Cost;
}
+ case Intrinsic::vector_extract: {
+ // If both the vector argument and the return type are legal types and the
+ // index is 0, then this should be a no-op or simple operation; return a
+ // relatively low cost.
+
+ // If arguments aren't actually supplied, then we cannot determine the
+ // value of the index.
+ if (ICA.getArgs().size() < 2)
+ break;
+ LLVMContext &C = RetTy->getContext();
+ EVT MRTy = getTLI()->getValueType(DL, RetTy);
+ EVT MPTy = getTLI()->getValueType(DL, ICA.getArgTypes()[0]);
+ TargetLoweringBase::LegalizeKind RLK = getTLI()->getTypeConversion(C, MRTy);
+ TargetLoweringBase::LegalizeKind PLK = getTLI()->getTypeConversion(C, MPTy);
+ const ConstantInt *Idx = dyn_cast<ConstantInt>(ICA.getArgs()[1]);
+ if (RLK.first == TargetLoweringBase::TypeLegal &&
+ PLK.first == TargetLoweringBase::TypeLegal && Idx &&
+ Idx->getZExtValue() == 0)
+ return InstructionCost(1);
----------------
huntergr-arm wrote:
If the subvector is legal but smaller than the vector its being inserted into, we would need an extra operation. e.g. <2 x float> (packed 64b NEON) into <vscale x 2 x float> (unpacked 128b+ SVE) would need an unzip, I think?
My original idea with this was to only do it in cases where the size of the vectors was the same, but I was encouraged to extend that to legal types. I can walk it back to my initial idea if we're not sure about the extent of the change.
https://github.com/llvm/llvm-project/pull/81135
More information about the llvm-commits
mailing list