[llvm] Fix scalar overload name constructed by ReplaceWithVeclib.cpp (PR #111095)
Tex Riddell via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 09:42:09 PDT 2024
================
@@ -100,27 +100,38 @@ static void replaceWithTLIFunction(IntrinsicInst *II, VFInfo &Info,
static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
IntrinsicInst *II) {
assert(II != nullptr && "Intrinsic cannot be null");
+ Intrinsic::ID IID = II->getIntrinsicID();
+ if (IID == Intrinsic::not_intrinsic)
+ return false;
// At the moment VFABI assumes the return type is always widened unless it is
// a void type.
auto *VTy = dyn_cast<VectorType>(II->getType());
ElementCount EC(VTy ? VTy->getElementCount() : ElementCount::getFixed(0));
+ Type *ScalarRetTy = II->getType()->getScalarType();
// Compute the argument types of the corresponding scalar call and check that
// all vector operands match the previously found EC.
SmallVector<Type *, 8> ScalarArgTypes;
- Intrinsic::ID IID = II->getIntrinsicID();
+
+ // OloadTys collects types used in scalar intrinsic overload name.
+ SmallVector<Type *, 3> OloadTys;
+ if (!ScalarRetTy->isVoidTy() &&
+ isVectorIntrinsicWithOverloadTypeAtArg(IID, -1))
+ OloadTys.push_back(ScalarRetTy);
+
for (auto Arg : enumerate(II->args())) {
auto *ArgTy = Arg.value()->getType();
- if (isVectorIntrinsicWithScalarOpAtArg(IID, Arg.index())) {
- ScalarArgTypes.push_back(ArgTy);
- } else if (auto *VectorArgTy = dyn_cast<VectorType>(ArgTy)) {
- ScalarArgTypes.push_back(VectorArgTy->getElementType());
+ auto *ScalarArgTy = ArgTy->getScalarType();
+ ScalarArgTypes.push_back(ScalarArgTy);
+ if (isVectorIntrinsicWithOverloadTypeAtArg(IID, Arg.index()))
+ OloadTys.push_back(ScalarArgTy);
+ if (auto *VectorArgTy = dyn_cast<VectorType>(ArgTy)) {
----------------
tex3d wrote:
In any case, we definitely should not do this up front:
```
if (!isVectorIntrinsicWithScalarOpAtArg(IID, Arg.index()))
return false;
```
Otherwise, any intrinsic with a vector operand will be skipped. That's not what this code does. It expects a vector or scalar operand. If vector, the scalar type is used and it checks that the size matches, otherwise, it's a scalar operand, this scalar type is used, and `isVectorIntrinsicWithScalarOpAtArg` should return true (it would return false for vector operands).
https://github.com/llvm/llvm-project/pull/111095
More information about the llvm-commits
mailing list