[llvm] [CostModel][X86] Update logic vector reduction costs to match llvm-mca estimates (PR #214191)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 01:38:17 PDT 2026


================
@@ -5729,13 +5743,75 @@ X86TTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *ValTy,
     { ISD::ADD,   MVT::v8i32,   {5, 5, 5, 5} },
     { ISD::ADD,   MVT::v16i16,  {5, 5, 5, 5} },
     { ISD::ADD,   MVT::v32i8,   {4, 4, 4, 4} },
+
+    { ISD::AND,   MVT::v4i64,   {3, 7, 5, 5} },
+    { ISD::AND,   MVT::v8i32,   {4, 9, 7, 7} },
+    { ISD::AND,   MVT::v16i16,  {5,11, 9, 9} },
+    { ISD::AND,   MVT::v8i16,   {4, 7, 7, 7} },
+    { ISD::AND,   MVT::v32i8,   {6,13,11,11} },
+    { ISD::AND,   MVT::v16i8,   {5,10, 9, 9} },
----------------
ParkHanbum wrote:

SSE case
```
% cat x86-reduce-mca-results/SSE2_AND_v16i8/silvermont/reduce_and_v16i8.mca.s 
# LLVM-MCA-BEGIN reduce_and_v16i8
  pshufd	$238, %xmm0, %xmm1
  pand	%xmm0, %xmm1
  pshufd	$85, %xmm1, %xmm0
  pand	%xmm1, %xmm0
  movdqa	%xmm0, %xmm1
  psrld	$16, %xmm1
  pand	%xmm0, %xmm1
  movdqa	%xmm1, %xmm0
  psrlw	$8, %xmm0
  pand	%xmm1, %xmm0
  movd	%xmm0, %eax
# LLVM-MCA-END reduce_and_v16i8

% /Users/b2sy/work/build/bin/llvm-mca /Users/b2sy/work/llvm-x86-reduce-mca-verify/x86-reduce-mca-results/SSE2_AND_v16i8/silvermont/reduce_and_v16i8.mca.s -mtriple=x86_64-unknown-linux-gnu -mcpu=silvermont -iterations=100 -instruction-info -resource-pressure

[0] Code Region - reduce_and_v16i8

Iterations:        100
Instructions:      1100
Total Cycles:      1004
Total uOps:        1100

Dispatch Width:    2
uOps Per Cycle:    1.10
IPC:               1.10
Block RThroughput: 5.5
```

AVX512f case

```
b2sy at mac llvm-x86-reduce-mca-verify % cat /Users/b2sy/work/llvm-x86-reduce-mca-verify/x86-reduce-mca-results/AVX512F_AND_v16i8/skylake-avx512/reduce_and_v16i8.mca.s
# LLVM-MCA-BEGIN reduce_and_v16i8
  vpshufd	$238, %xmm0, %xmm1
  vpand	%xmm1, %xmm0, %xmm0
  vpsrlq	$32, %xmm0, %xmm1
  vpand	%xmm1, %xmm0, %xmm0
  vpsrld	$16, %xmm0, %xmm1
  vpand	%xmm1, %xmm0, %xmm0
  vpsrlw	$8, %xmm0, %xmm1
  vpand	%xmm1, %xmm0, %xmm0
  vmovd	%xmm0, %eax
# LLVM-MCA-END reduce_and_v16i8
b2sy at mac llvm-x86-reduce-mca-verify % /Users/b2sy/work/build/bin/llvm-mca /Users/b2sy/work/llvm-x86-reduce-mca-verify/x86-reduce-mca-results/AVX512F_AND_v16i8/skylake-avx512/reduce_and_v16i8.mca.s -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake-avx512 -iterations=100 -instruction-info -resource-pressure

[0] Code Region - reduce_and_v16i8

Iterations:        100
Instructions:      900
Total Cycles:      805
Total uOps:        900

Dispatch Width:    6
uOps Per Cycle:    1.12
IPC:               1.12
Block RThroughput: 1.5
```

what do I wrong? 

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


More information about the llvm-commits mailing list