Skip to content

Commit 285279b

Browse files
Addressing reviewers (2)
1 parent 9523a0a commit 285279b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

llvm/lib/CodeGen/ReplaceWithVeclib.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void replaceWithTLIFunction(Instruction &I, VFInfo &Info,
8888
if (CI)
8989
CI->getOperandBundlesAsDefs(OpBundles);
9090

91-
CallInst *Replacement = IRBuilder.CreateCall(TLIVecFunc, Args, OpBundles);
91+
auto *Replacement = IRBuilder.CreateCall(TLIVecFunc, Args, OpBundles);
9292
I.replaceAllUsesWith(Replacement);
9393
// Preserve fast math flags for FP math.
9494
if (isa<FPMathOperator>(Replacement))
@@ -102,14 +102,15 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
102102
Instruction &I) {
103103
std::string ScalarName;
104104
ElementCount EC = ElementCount::getFixed(0);
105-
CallInst *CI = dyn_cast<CallInst>(&I);
105+
Function *FuncToReplace = nullptr;
106106
SmallVector<Type *, 8> ScalarArgTypes;
107107
// Compute the argument types of the corresponding scalar call, the scalar
108-
// function name, and EC. For CI, it additionally checks if in the vector
108+
// function name, and EC. For calls, it additionally checks if in the vector
109109
// call, all vector operands have the same EC.
110-
if (CI) {
111-
Intrinsic::ID IID = Intrinsic::not_intrinsic;
112-
IID = CI->getCalledFunction()->getIntrinsicID();
110+
if (auto *CI = dyn_cast<CallInst>(&I)) {
111+
Intrinsic::ID IID = CI->getCalledFunction()->getIntrinsicID();
112+
assert(IID != Intrinsic::not_intrinsic && "Not an intrinsic");
113+
FuncToReplace = CI->getCalledFunction();
113114
for (auto Arg : enumerate(CI->args())) {
114115
auto *ArgTy = Arg.value()->getType();
115116
if (isVectorIntrinsicWithScalarOpAtArg(IID, Arg.index())) {
@@ -170,7 +171,6 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
170171
if (!VectorFTy)
171172
return false;
172173

173-
Function *FuncToReplace = CI ? CI->getCalledFunction() : nullptr;
174174
Function *TLIFunc = getTLIFunction(I.getModule(), VectorFTy,
175175
VD->getVectorFnName(), FuncToReplace);
176176
replaceWithTLIFunction(I, *OptInfo, TLIFunc);
@@ -182,21 +182,22 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
182182

183183
/// Supported instructions \p I are either frem or CallInsts to intrinsics.
184184
static bool isSupportedInstruction(Instruction *I) {
185-
if (auto *CI = dyn_cast<CallInst>(I)) {
186-
if (CI->getCalledFunction() &&
187-
CI->getCalledFunction()->getIntrinsicID() != Intrinsic::not_intrinsic)
188-
return true;
189-
} else if (I->getOpcode() == Instruction::FRem && I->getType()->isVectorTy())
185+
if (auto *CI = dyn_cast<CallInst>(I))
186+
return CI->getCalledFunction() &&
187+
CI->getCalledFunction()->getIntrinsicID() !=
188+
Intrinsic::not_intrinsic;
189+
if (I->getOpcode() == Instruction::FRem && I->getType()->isVectorTy())
190190
return true;
191-
192191
return false;
193192
}
194193

195194
static bool runImpl(const TargetLibraryInfo &TLI, Function &F) {
196195
bool Changed = false;
197196
SmallVector<Instruction *> ReplacedCalls;
198197
for (auto &I : instructions(F)) {
199-
if (isSupportedInstruction(&I) && replaceWithCallToVeclib(TLI, I)) {
198+
if (!isSupportedInstruction(&I))
199+
continue;
200+
if (replaceWithCallToVeclib(TLI, I)) {
200201
ReplacedCalls.push_back(&I);
201202
Changed = true;
202203
}

0 commit comments

Comments
 (0)