@@ -88,7 +88,7 @@ static void replaceWithTLIFunction(Instruction &I, VFInfo &Info,
88
88
if (CI)
89
89
CI->getOperandBundlesAsDefs (OpBundles);
90
90
91
- CallInst *Replacement = IRBuilder.CreateCall (TLIVecFunc, Args, OpBundles);
91
+ auto *Replacement = IRBuilder.CreateCall (TLIVecFunc, Args, OpBundles);
92
92
I.replaceAllUsesWith (Replacement);
93
93
// Preserve fast math flags for FP math.
94
94
if (isa<FPMathOperator>(Replacement))
@@ -102,14 +102,15 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
102
102
Instruction &I) {
103
103
std::string ScalarName;
104
104
ElementCount EC = ElementCount::getFixed (0 );
105
- CallInst *CI = dyn_cast<CallInst>(&I) ;
105
+ Function *FuncToReplace = nullptr ;
106
106
SmallVector<Type *, 8 > ScalarArgTypes;
107
107
// 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
109
109
// 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 ();
113
114
for (auto Arg : enumerate(CI->args ())) {
114
115
auto *ArgTy = Arg.value ()->getType ();
115
116
if (isVectorIntrinsicWithScalarOpAtArg (IID, Arg.index ())) {
@@ -170,7 +171,6 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
170
171
if (!VectorFTy)
171
172
return false ;
172
173
173
- Function *FuncToReplace = CI ? CI->getCalledFunction () : nullptr ;
174
174
Function *TLIFunc = getTLIFunction (I.getModule (), VectorFTy,
175
175
VD->getVectorFnName (), FuncToReplace);
176
176
replaceWithTLIFunction (I, *OptInfo, TLIFunc);
@@ -182,21 +182,22 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
182
182
183
183
// / Supported instructions \p I are either frem or CallInsts to intrinsics.
184
184
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 ())
190
190
return true ;
191
-
192
191
return false ;
193
192
}
194
193
195
194
static bool runImpl (const TargetLibraryInfo &TLI, Function &F) {
196
195
bool Changed = false ;
197
196
SmallVector<Instruction *> ReplacedCalls;
198
197
for (auto &I : instructions (F)) {
199
- if (isSupportedInstruction (&I) && replaceWithCallToVeclib (TLI, I)) {
198
+ if (!isSupportedInstruction (&I))
199
+ continue ;
200
+ if (replaceWithCallToVeclib (TLI, I)) {
200
201
ReplacedCalls.push_back (&I);
201
202
Changed = true ;
202
203
}
0 commit comments