Skip to content

Commit f0557de

Browse files
committed
Simplify logic a bit, handle scalar return overload type.
1 parent 8227c91 commit f0557de

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

llvm/lib/CodeGen/ReplaceWithVeclib.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,37 +104,31 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
104104
// a void type.
105105
auto *VTy = dyn_cast<VectorType>(II->getType());
106106
ElementCount EC(VTy ? VTy->getElementCount() : ElementCount::getFixed(0));
107+
Type *ScalarRetTy = II->getType()->getScalarType();
107108
// Compute the argument types of the corresponding scalar call and check that
108109
// all vector operands match the previously found EC.
109110
SmallVector<Type *, 8> ScalarArgTypes;
110111
Intrinsic::ID IID = II->getIntrinsicID();
111112

112113
// OloadTys collects types used in scalar intrinsic overload name.
113114
SmallVector<Type *, 3> OloadTys;
114-
if (VTy && isVectorIntrinsicWithOverloadTypeAtArg(IID, -1))
115-
OloadTys.push_back(VTy->getElementType());
115+
if (isVectorIntrinsicWithOverloadTypeAtArg(IID, -1))
116+
OloadTys.push_back(ScalarRetTy);
116117

117118
for (auto Arg : enumerate(II->args())) {
118119
auto *ArgTy = Arg.value()->getType();
119-
// Gather type if it is used in the overload name.
120-
if (isVectorIntrinsicWithOverloadTypeAtArg(IID, Arg.index())) {
121-
if (!isVectorIntrinsicWithScalarOpAtArg(IID, Arg.index()) && isa<VectorType>(ArgTy))
122-
OloadTys.push_back(cast<VectorType>(ArgTy)->getElementType());
123-
else
124-
OloadTys.push_back(ArgTy);
125-
}
126-
127-
if (isVectorIntrinsicWithScalarOpAtArg(IID, Arg.index())) {
128-
ScalarArgTypes.push_back(ArgTy);
129-
} else if (auto *VectorArgTy = dyn_cast<VectorType>(ArgTy)) {
130-
ScalarArgTypes.push_back(VectorArgTy->getElementType());
120+
auto *ScalarArgTy = ArgTy->getScalarType();
121+
ScalarArgTypes.push_back(ScalarArgTy);
122+
if (isVectorIntrinsicWithOverloadTypeAtArg(IID, Arg.index()))
123+
OloadTys.push_back(ScalarArgTy);
124+
if (auto *VectorArgTy = dyn_cast<VectorType>(ArgTy)) {
131125
// When return type is void, set EC to the first vector argument, and
132126
// disallow vector arguments with different ECs.
133127
if (EC.isZero())
134128
EC = VectorArgTy->getElementCount();
135129
else if (EC != VectorArgTy->getElementCount())
136130
return false;
137-
} else
131+
} else if (!isVectorIntrinsicWithScalarOpAtArg(IID, Arg.index()))
138132
// Exit when it is supposed to be a vector argument but it isn't.
139133
return false;
140134
}
@@ -160,7 +154,6 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
160154

161155
// Replace the call to the intrinsic with a call to the vector library
162156
// function.
163-
Type *ScalarRetTy = II->getType()->getScalarType();
164157
FunctionType *ScalarFTy =
165158
FunctionType::get(ScalarRetTy, ScalarArgTypes, /*isVarArg*/ false);
166159
const std::string MangledName = VD->getVectorFunctionABIVariantString();

0 commit comments

Comments
 (0)