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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Assertion failed in Vectorize
        </td>
    </tr>

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

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

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

<pre>
    I compiled this code with -Os and a crash appeared in assertion failure:

```c
#include <stdint.h>
int32_t *c;
int8_t ****d;
uint64_t g;
int a();
long b(long, long h, long p3) {
 long e;
  int f = 0;
  if (h) {
    e = h;
    f = 1;
  }
 if (e > p3)
    f = 2;
  switch (f) {
  case 1:
    e++;
 case 2:
    e--;
  }
  if (e < h)
    e = h;
  return e;
}

uint8_t div_func_uint8_t_u_u(uint8_t ui1, uint8_t ui2)
{
  return (ui1 / ui2);
}

uint64_t j() {
  uint16_t k[8];
  int i;
  for (i = 0; *c + ****d + (int)g + i < 8; i++)
 k[b(0, g, 0)] = 6;
  *c = div_func_uint8_t_u_u(k[6], a());
}
```

The crash is:
```
clang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7369: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && " VPlan cost model and legacy cost model disagreed"' failed.
```

Details can be found here: https://godbolt.org/z/T81adKPY5


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VVuPmzgU_jUnL0cTweESeOAhlyKttlIrbTWrfYoc24C7xEbYTLf99SubhCGj6Ugosc_d3_l8zKxVrZayguwA2WnDJteZseJsFKplOo6iYnMx4mf1B3JzHVQvBbpOWeRGSPyhXIdPXywyLZAhH5ntkA2DZKMUqDQya-XolNHYMNVPo4RkD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