[llvm] [TLI] replace-with-veclib works with FRem Instruction. (PR #76166)
Maciej Gabka via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 22 08:16:20 PST 2023
================
@@ -162,27 +171,36 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
if (!VectorFTy)
return false;
- Function *FuncToReplace = CallToReplace.getCalledFunction();
- Function *TLIFunc = getTLIFunction(CallToReplace.getModule(), VectorFTy,
+ Function *FuncToReplace = CI ? CI->getCalledFunction() : nullptr;
+ Function *TLIFunc = getTLIFunction(I.getModule(), VectorFTy,
VD->getVectorFnName(), FuncToReplace);
- replaceWithTLIFunction(CallToReplace, *OptInfo, TLIFunc);
-
- LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": Replaced call to `"
- << FuncToReplace->getName() << "` with call to `"
- << TLIFunc->getName() << "`.\n");
+ replaceWithTLIFunction(I, *OptInfo, TLIFunc);
+ LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": Replaced call to `" << ScalarName
+ << "` with call to `" << TLIFunc->getName() << "`.\n");
++NumCallsReplaced;
return true;
}
+/// Supported Instructions \p I are either FRem or CallInsts to Intrinsics.
+static bool isSupportedInstruction(Instruction *I) {
+ if (auto *CI = dyn_cast<CallInst>(I)) {
+ if (!CI->getCalledFunction())
+ return false;
+ if (CI->getCalledFunction()->getIntrinsicID() == Intrinsic::not_intrinsic)
+ return false;
+ } else if (I->getOpcode() != Instruction::FRem)
+ return false;
+
+ return true;
+}
+
static bool runImpl(const TargetLibraryInfo &TLI, Function &F) {
bool Changed = false;
- SmallVector<CallInst *> ReplacedCalls;
+ SmallVector<Instruction *> ReplacedCalls;
for (auto &I : instructions(F)) {
- if (auto *CI = dyn_cast<CallInst>(&I)) {
- if (replaceWithCallToVeclib(TLI, *CI)) {
- ReplacedCalls.push_back(CI);
- Changed = true;
- }
+ if (isSupportedInstruction(&I) && replaceWithCallToVeclib(TLI, I)) {
----------------
mgabka wrote:
this change requires some changed in the documentation for this pass, see lines 9-11 in this file
https://github.com/llvm/llvm-project/pull/76166
More information about the llvm-commits
mailing list