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

    <tr>
        <th>Summary</th>
        <td>
            Loops combining and separation is often pessimization
        </td>
    </tr>

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

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

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

<pre>
    I often noticed that the clang is very fond of splitting cycles into several cycles, which often leads to the fact that it cannot optimize useless cycles.
For example, recently I wanted to improve the push back of a vector so that it is better optimized for types whose destructor does nothing after the move (almost all types do).
Here is the link:

https://github.com/llvm/llvm-project/compare/main...kelbon:llvm-project:vector_reallocate_optimization

(its just example, i know about additional check about disabled exceptions/iterator ++ exceptions/support custom allocators/possibility to not check if dctor is noexcept bcs its just precondition of STL etc etc)

The problem is that the clan (apparently) separates these cycles, and then cannot optimize what happened, while it should have seen inside the body of the cycle that the destructor after the move does nothing, remove it, then see that the destructor is called == no one else accesses this value, so you can remove the default value of the old value (as happens often in the muv constructor)

Here clang makes useless loop, while gcc makes just memcpy + delete as needed

https://godbolt.org/z/ccE1YYsE8


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVMGOGjkQ_RpzKS0Cd8PAoQ8zO0EbKbfNJafIbRe0g9tluaoh5OtX7m5mSHa1Ug6AsF1Vr-q9V4bZnyJiozYvavO6MIN0lJszhpbioiV3az4CHQUjRBJv0YF0RkA6BBtMPIFnuGC-wZGiAzoCp-BFfDyBvdmADD4KAeMFswnzmdJ_wrXztptTBzSOQWhMezRWpiJewJoYSYCS-N7_QBgYAzLPeZZq9apWzwfKgN9NnwKWzBktRgk3-AhXE6VAJvB9ynTBsUIauIPW2HPBa-CCVigD01tVz9CiCOa3wg6OlEFuCRmuHTGCQ5Y8jJGOkMt4utK1OZa4UqYv9ZTemdATC5gQ5gSOlN7P2P_C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