[llvm] [LV][AArch64] LoopVectorizer allows scalable frem instructions (PR #76247)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 4 03:56:42 PST 2024


================
@@ -7142,6 +7142,19 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
         Legal->isInvariant(Op2))
       Op2Info.Kind = TargetTransformInfo::OK_UniformValue;
 
+    // Some targets replace frem with vector library calls.
+    if (I->getOpcode() == Instruction::FRem && VectorTy->isScalableTy()) {
+      LibFunc Func;
+      if (TLI->getLibFunc(I->getOpcode(), I->getType(), Func)) {
+        if (TLI->isFunctionVectorizable(TLI->getName(Func))) {
+          SmallVector<Type *, 4> OpTypes;
+          for (auto &Op : I->operands())
+            OpTypes.push_back(Op->getType());
+          return TTI.getCallInstrCost(nullptr, VectorTy, OpTypes, CostKind);
----------------
fhahn wrote:

IIUC this doesn't account for the cost of the `frem` implementation itself. What about the case where a library provides `frem`, but it is more expensive?

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


More information about the llvm-commits mailing list