[llvm] [TTI] Improve histogram intrinsic costing (PR #216337)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 1 05:30:10 PDT 2026


================
@@ -594,13 +600,14 @@ static InstructionCost getHistogramCost(const AArch64Subtarget *ST,
     // HistCnt only supports 32b and 64b element types
     unsigned LegalEltSize = EltSize <= 32 ? 32 : 64;
 
-    if (EC == 2 || (LegalEltSize == 32 && EC == 4))
-      return InstructionCost(BaseHistCntCost);
-
+    // HistCnt is the same cost as a vector integer add on 128b implementations,
+    // but will likely increase on wider vector types. Multiply by vscale as
+    // a quick estimate.
+    unsigned VScale = ST->getVScaleForTuning();
     unsigned NaturalVectorWidth = AArch64::SVEBitsPerBlock / LegalEltSize;
-    TotalHistCnts = EC / NaturalVectorWidth;
+    unsigned TotalHistCnts = EC / NaturalVectorWidth;
----------------
david-arm wrote:

Not required for this patch, but it would be nice to rename `EC` to `MinEC` here because it's confusing at the moment. If it was really the element count then it should be `ElementCount` type.

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


More information about the llvm-commits mailing list