[llvm] [AArch64] SLP can vectorize frem (PR #82488)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 06:25:55 PST 2024


================
@@ -8362,9 +8362,20 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
       unsigned OpIdx = isa<UnaryOperator>(VL0) ? 0 : 1;
       TTI::OperandValueInfo Op1Info = getOperandInfo(E->getOperand(0));
       TTI::OperandValueInfo Op2Info = getOperandInfo(E->getOperand(OpIdx));
-      return TTI->getArithmeticInstrCost(ShuffleOrOp, VecTy, CostKind, Op1Info,
-                                         Op2Info) +
-             CommonCost;
+      auto VecCost = TTI->getArithmeticInstrCost(ShuffleOrOp, VecTy, CostKind,
+                                                 Op1Info, Op2Info);
+      // Some targets can replace frem with vector library calls.
+      if (ShuffleOrOp == Instruction::FRem) {
+        LibFunc Func;
+        if (TLI->getLibFunc(ShuffleOrOp, ScalarTy, Func) &&
+            TLI->isFunctionVectorizable(TLI->getName(Func),
+                                        VecTy->getElementCount())) {
+          auto VecCallCost = TTI->getCallInstrCost(
+              nullptr, VecTy, {ScalarTy, ScalarTy}, CostKind);
+          VecCost = std::min(VecCost, VecCallCost);
+        }
+      }
+      return VecCost + CommonCost;
----------------
paschalis-mpeis wrote:

Thanks for your review @alexey-bataev.

BTW, this is a separate patch. It's just is 'stacked' on top of PR #80423 (see PR description above).

Github doesn't properly support Stacked PRs, so you have to manually check individual commits, eg:
- commit that showcases what was missing: [982d28b](https://github.com/llvm/llvm-project/pull/82488/commits/982d28b651908bf3f865a2165e11fb654a063ee8) (everything before this belongs to the previous PR patch)
- commit that does the change: [3b12ec6](https://github.com/llvm/llvm-project/pull/82488/commits/3b12ec69371e11e2a8aa2aaca4a1702b3eaedfa2)

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


More information about the llvm-commits mailing list