[llvm] [TLI] replace-with-veclib works with FRem Instruction. (PR #76166)

Alexandros Lamprineas via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 05:50:38 PST 2024


================
@@ -162,27 +170,35 @@ 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() &&
+        CI->getCalledFunction()->getIntrinsicID() != Intrinsic::not_intrinsic)
+      return true;
+  } else if (I->getOpcode() == Instruction::FRem && I->getType()->isVectorTy())
+    return true;
+
+  return false;
----------------
labrinea wrote:

Avoid else statements after return. I would rewrite it as follows:
```
if (auto *II = dyn_cast<IntrinsicInst>(I))
  return II->getIntrinsicID() != Intrinsic::not_intrinsic;
if (I->getOpcode() == Instruction::FRem)
  return I->getType()->isVectorTy();
return false;
```

https://github.com/llvm/llvm-project/pull/76166


More information about the llvm-commits mailing list