[PATCH] D105484: [TTI] Remove IsPairwiseForm from getArithmeticReductionCost

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 7 02:20:07 PDT 2021


sdesmalen added a comment.

Thanks for making this change, the PairWise flag always confused me, and from what I can see, the cost-model always over-calculated the costs of a reduction.
Like @david-arm says, `ReductionKind` can probably be removed now, same for `ReductionData`. Other than that, it looks good to me!



================
Comment at: llvm/test/Analysis/CostModel/X86/reduction.ll:18
 ; SSE2-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bin.rdx8 = fadd <4 x float> %bin.rdx, %rdx.shuf7
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %r = extractelement <4 x float> %bin.rdx8, i32 0
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %r = extractelement <4 x float> %bin.rdx8, i32 0
 ; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret float %r
----------------
I'm surprised this was how the cost was calculated for such an extract, seems very wrong, as this just calculated an additional cost to all the other individual costs, doubling the cost of a reduction.

The cost of the individual operations should be a close match to the cost of the llvm.vector.reduce intrinsic when going through BasicTTIImpl. I tried the following with AArch64, but it seems the costs are the same because it uses a table to calculate the cost.

```Printing analysis 'Cost Model Analysis' for function 'foo':
Cost Model: Found an estimated cost of 10 for instruction:   %red = call float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> %v)
Cost Model: Found an estimated cost of 0 for instruction:   ret float %red

Printing analysis 'Cost Model Analysis' for function 'bar':
Cost Model: Found an estimated cost of 3 for instruction:   %rdx.shuf = shufflevector <4 x float> %rdx, <4 x float> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
Cost Model: Found an estimated cost of 2 for instruction:   %bin.rdx = fadd <4 x float> %rdx, %rdx.shuf
Cost Model: Found an estimated cost of 3 for instruction:   %rdx.shuf7 = shufflevector <4 x float> %bin.rdx, <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
Cost Model: Found an estimated cost of 2 for instruction:   %bin.rdx8 = fadd <4 x float> %bin.rdx, %rdx.shuf7
Cost Model: Found an estimated cost of 0 for instruction:   %r = extractelement <4 x float> %bin.rdx8, i32 0
Cost Model: Found an estimated cost of 0 for instruction:   ret float %r
```
For targets which don't override this function the cost can be quite different, which is a bit of a surprise.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105484/new/

https://reviews.llvm.org/D105484



More information about the llvm-commits mailing list