<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61047>61047</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [SLP][AArch64] Over-eager SLP vectorisation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sjoerdmeijer
      </td>
    </tr>
</table>

<pre>
    I am opening this issue to discuss possible approaches as the problem seem to have been identified already. I.e., my motivating case is very similar to the pre-committed test case in 3c5e24a51ce072fd0083396dcf0ea107b1858d11

Taking the very first test case, SLP vectorisation is indeed not profitable, which you could probably guess by just eyeballing the codegen: 

https://godbolt.org/z/E64TMKsx9

But there are actually quite a few things going on here, I don't think it is only related to generating fmas or not. To illustrate this, here are the timeline view from MCA:

 ```Timeline view:
                      0123456789          01
  Index 0123456789          0123456789
  [0,0]     DeeER.    .    .    .    . ..   mov        x8, x1
  [0,1]     DeeeeeeER .    .    .    .    ..   ldr s0, [x0]
  [0,2]     D==eeeeeeeeER  .    .    .    ..   ld1r { v1.2s }, [x8], #4
  [0,3]     D==========eeeeeeER .    .    ..   ldr d2, [x8]
  [0,4]     D================eeeER   .    ..   fmul v1.2s, v1.2s, v2.2s
  [0,5]     D================eeeER   .    ..   fmul v0.2s, v2.2s, v0.s[0]
  [0,6]     D===================eeER .    .. rev64      v1.2s, v1.2s
  [0,7]     D=====================eeER    .. fsub       v3.2s, v0.2s, v1.2s
  [0,8]     .D====================eeER ..   fadd       v0.2s, v0.2s, v1.2s
  [0,9] .D======================eeER  ..   mov        v3.s[1], v0.s[1]
  [0,10] .D========================eeER..   str        d3, [x0]
  [0,11] .D========================eeeeER   st1        { v2.s }[1], [x1]
```

VS:

  ```Timeline view:
 01234567
  Index     0123456789
  [0,0]     DeeeeeeER .    . .   ldp s0, s2, [x1]
  [0,1]     DeeeeeeER .    . .   ldr      s1, [x1, #8]
 [0,2]     DeeeeeeER .    . .   ldr      s4, [x0]
  [0,3]     D======eeeER . .   fmul     s3, s1, s0
  [0,4]     D======eeeER   . .   fmul     s0, s0, s2
  [0,5]     D=========eeeeER .   fnmsub   s2, s2, s4, s3
  [0,6] D=========eeeeER .   fmadd    s0, s1, s4, s0
  [0,7] D=============eeER   stp      s2, s0, [x0]
  [0,8]     .D============eeER str      s1, [x1]
```

So to me this looks like a combination of problems:
- we emit higher latency instructions, e.g. `LD1R` and `ST1`
- We emit more instruction, e.g. `REV` and `MOV` for the shuffle and extract.

More instructions doesn't need to mean slower, but in this case it is creating this dependency chains or critical paths, and there is not enough parallelism that this is profitable. 

To me, it looks like a lot of cost-modelling of insertelement, shuffle vector, and extractelement gone wrong here so am going to look into that. But if you have other ideas about this @fhahn or @davemgreen then I am open to suggestions of course.



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV11zo7gS_TX4pSsUH8YmD35IJpOqqTtTu5Wk9j4L1IASIflKwonvr99qCWzsfGx2ZlwOxo50zumWdOhm1opWIW6i4joqbhZscJ02G_uo0fAexSOaRaX5fvMNWA96i0qoFlwnLAhrBwSngQtbD9bCVlsrKonAtlujWd2hBWbBdQhboyuJPVjEnqZ0bIdQISoQHJUTjUAOTBpkfB_DtxjjKPsC_R567cSOOSKtmUUQFnZo9mBFLyQzhBXw8aLWfS-cQw4OrRuHK8jrArMlK9Iak3XW8CQp8_xyxesmQZYm6yoti5KnaZTcRMlVuD6wpxAmBrZGGOuOsKTt_vufsMPaaSMsc0IrkiYUR-SgtKOIG-FYJf3o507UHez1ALUeJPf5YJXcQzugtVDt4XGwDnCPFZNy4q41xxZVlF_BXF3n3NZG-VWU3UbZbat5paWLtWmj7Pb_UXb7dbV8-PEf-3I5n3Q9OMI0CIz-ajcwKffwv0E4BAYNPtOqqtZCq4lfK6DRJP4bcK2ibO38iCcQjmLVSu7BoGQ-4xpaVGjCSjU9s6AN5SGGBw1CysE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