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

    <tr>
        <th>Summary</th>
        <td>
            The unroll_count pragma does not work together with vectorize(disable)
        </td>
    </tr>

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

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

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

<pre>
    When I try to use both unroll_count(8) and vectorize(disable) on a loop, I get unexpected results.

Example, compiled with -O3:
```
typedef struct { int i, j; } Pair;
void j(Pair *p);
void f(void) {
    Pair p[640];
#pragma clang loop unroll_count(8) vectorize(disable)
    for (int j = 0; j < 640; ++j)
 p[j] = (Pair){0, 1000};
    j(p);
}
```
The loop is unrolled with factor 5 instead of 8 as specified in the unroll_count: https://godbolt.org/z/Keoxqob57

If I change the trip count to 64, it's completely unrolled which is also unexpected.

If I remove "vectorize(disable)", the loop is unrolled with factor 8 as I expect.

I think there are some issues with followup metadata. The unroll_count is placed in a "llvm.loop.vectorize.followup_all" metadata node, and vectorization is disabled, meaning the followup metadata isn't promoted to become normal loop metadata. So the UnrollPass doesn't see it.

For the unexpected full unroll with a lower trip count: this happens in the FullUnrollPass, which is before LoopVectorizePass, so the followup metadata hasn't even had a chance to become normal loop metadata. This seems like a flaw in the followup metadata design.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVdFu4zYQ_Br6ZXGCTFmW_KCHOK6BoAV6QNP28UBJK4kOxVVJyk7u64uV5Di55HCAYcsmOTsznF0r73VrEQuR7kV6WKkxdOSK_oxOP3lPdlVS_VL826GFBwjuBQLB6BFKCh2M1pEx3yoabRAyz4XcgbI1nLEK5PR3FDKvtVelQV4iCwoM0SDkPTxAiwFGi88DVgFrcOhHE3wk4oOI7-b3355VP_Dhe6ioH7TBGi46dPDlz0QkyyaxjZfX9DW8DFhjAz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