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

    <tr>
        <th>Summary</th>
        <td>
            Clang vectorizes simple loop in O3 worse than GCC does in O2.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Look at the sample:
```
void addition(std::array<int, 10000>& result,
 const std::array<int, 10000>& first,
              const std::array<int, 10000>& second)
{
    for (int i=0;i<10000;++i) {
        result[i] = first[i] + second[i];
    }
}
```
As we could see, the code can be effectively vectorised. Moreover it works with fixed count of elements(10000) which divides by 16 with no remainder, so thus the compiler don't have to create second loop to handle block of remainded elements with count of elements <16 - only simple vectorized loop would be enough.

The full snippet here: https://godbolt.org/z/fcedzGEYa
As we could see in the snippet, GCC doesn't create second loop to handle remainder, while Clang does.
Any reason why Clang does it? Is it possible to fix?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVE2P4ygQ_TX4UuoIQztODj7kYzxaaVd72cseMZRDbROIACeT_vUrYqdnZ0ZaNUKyVfhVvfeqjEqJTh6xY82eNcdKTdmG2Bn07yEKzqshmHv3ewhvoDJki5DU-eKQyR3jO7bmy-a7ayADyhjKFDwTm5RN-UjuVIzqzuSBfGbiADXnnDP5hYk1REyTK1HGd6CDTxk-Axsppifqh_X5FAl18IaJbVHR7pdMY4jAxIZ8BmLyyJncE5OHBbhnomxiYgvfMWUtOpo9seYITB4Xis-A2D8LzpGSa0az9vhgcPzJzV2CG4IOkzOQEAv9Yr4OBkErDwMCjiPqTFd0d7iiziFSQrOCP0LEcMUIlOEW4luCG2ULI31DUzL6DGEEdHhGnxMTm1me2MLNkrZg6EoGEwx3qNcz1geIeFbkDcZCJQXIdkoLpfOFHEYwpe1tBquuCDmAjqgyLsLBhXApUau8cQiDC_qt8HjmNR-M5pK_EIXSiDW8QPDuDonKFD51v-NS4PYwrJjjw3Syq-Iq3_1lEcbJOUieLhfMYDGWCQab8yWVWRE9E_0pmCG4vArxxET_zkQ_ajTvX7_8rX7tCJCff4c5ZXHl6-EAJmCabfhf-T-4ebPkEA5O-dMDX1jv_B0iqhQ83Oz9P4dAmckefisvcAkp0eAedo_0jcm-Mp00W7lVFXZ1-1rLtq6lrGw3jKJt2kY1yjRKrmsxasSm2ci1lKZtmoo6wUXDJW_rTS1qsTKvom0brYXcKinblr3ywtqtnLuei0kVpTRhV0su603l1IAuPe4RIXThy4QoV0rsCuBlmE6JvXJHKafvKTJlh90s76OZ6dneh2vk4U9ZJjkhZKv8h8-PE7Gqpui6nzpJ2U7DSoczE32ptTxeLjH8gzoz0T-4Jyb6hf61E_8GAAD__5jvlmA">