[llvm] [AArch64] Fix SVE cost model for various math intrinsics (PR #184358)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 04:21:09 PST 2026


================
@@ -696,6 +696,13 @@ AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
     break;
   }
   case Intrinsic::abs: {
+    if (isa<ScalableVectorType>(RetTy) && ST->isSVEorStreamingSVEAvailable()) {
+      auto LT = getTypeLegalizationCost(RetTy);
----------------
david-arm wrote:

So I was using getTypeBasedIntrinsicInstrCost from BasicTTIImpl.h as inspiration for this change, but now I see in that function we have:

```
    if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
      if (IID == Intrinsic::fabs && LT.second.isFloatingPoint() &&
          TLI->isFAbsFree(LT.second)) {
        return 0;
      }

      // The operation is legal. Assume it costs 1.
      // If the type is split to multiple registers, assume that there is some
      // overhead to this.
      // TODO: Once we have extract/insert subvector cost we need to use them.
      if (LT.first > 1)
        return (LT.first * 2);
      else
        return (LT.first * 1);
    } else if (TLI->isOperationCustom(ISD, LT.second)) {
      // If the operation is custom lowered then assume
      // that the code is twice as expensive.
      return (LT.first * 2);
    }
```

I was just trying to fix the intrinsic cost model because even though for SVE these intrinsics are custom lowered, they are just as cheap as NEON for the normal cases, e.g. <vscale x 4 x float>. But yes there is some logic that seems to double the cost if the type isn't legal, such as for promotion. Potentially this is also being too pessimistic for NEON too?

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


More information about the llvm-commits mailing list