[llvm] [TLI] Fix replace-with-veclib crash with invalid arguments (PR #77112)
Maciej Gabka via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 9 04:26:57 PST 2024
================
@@ -170,30 +170,31 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
if (!OptInfo)
return false;
- FunctionType *VectorFTy = VFABI::createFunctionType(*OptInfo, ScalarFTy);
- if (!VectorFTy)
- return false;
-
- Function *TLIFunc = getTLIFunction(I.getModule(), VectorFTy,
- VD->getVectorFnName(), FuncToReplace);
-
- // For calls, bail out when their arguments do not match with the TLI mapping.
+ // There is no guarantee that the vectorized instructions followed the VFABI
+ // specification when being created, this is why we need to add extra check to
+ // make sure that the operands of the vector function obtained via VFABI match
+ // the operands of the original vector instruction.
if (CI) {
- int IdxNonPred = 0;
- for (auto [OrigTy, VFParam] :
- zip(OrigArgTypes, OptInfo->Shape.Parameters)) {
+ for (auto VFParam : OptInfo->Shape.Parameters) {
if (VFParam.ParamKind == VFParamKind::GlobalPredicate)
continue;
- ++IdxNonPred;
+ Type *OrigTy = OrigArgTypes[VFParam.ParamPos];
----------------
mgabka wrote:
nit: to avoid confusion, I think it is worth to add an assert to check if the VFParam.ParamPos < OrigArgTypes.size() with a comment that this is guaranteed by the tryDemangleForVFABI, is if it failed most likely there is a bug in the VFABI parser.
https://github.com/llvm/llvm-project/pull/77112
More information about the llvm-commits
mailing list