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

    <tr>
        <th>Summary</th>
        <td>
            clang/llvm fails to auto vector vector compare and select
        </td>
    </tr>

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

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

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

<pre>
    ```
float *f(float *a, float *b, float *c) {
        for (int i=0; i<4; i++) {
                c[i] = a[i]>b[i]?a[i]:b[i];
        }
        return c;
}
```

`./bin/clang -O3 --target=x86_64-linux-gnu -mavx2 -S n.c -emit-llvm -ffast-math` emits IR like
```
define dso_local noundef ptr @f(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b, ptr noundef returned writeonly %c) local_unnamed_addr #0 {
entry:
  %0 = load float, ptr %a, align 4, !tbaa !5
  %1 = load float, ptr %b, align 4, !tbaa !5
  %. = tail call fast float @llvm.maxnum.f32(float %0, float %1)
  store float %., ptr %c, align 4, !tbaa !5
  %arrayidx.1 = getelementptr inbounds i8, ptr %a, i64 4
  %2 = load float, ptr %arrayidx.1, align 4, !tbaa !5
  %arrayidx2.1 = getelementptr inbounds i8, ptr %b, i64 4
  %3 = load float, ptr %arrayidx2.1, align 4, !tbaa !5
  %..1 = tail call fast float @llvm.maxnum.f32(float %2, float %3)
  %arrayidx9.1 = getelementptr inbounds i8, ptr %c, i64 4
  store float %..1, ptr %arrayidx9.1, align 4, !tbaa !5
  %arrayidx.2 = getelementptr inbounds i8, ptr %a, i64 8
  %4 = load float, ptr %arrayidx.2, align 4, !tbaa !5
  %arrayidx2.2 = getelementptr inbounds i8, ptr %b, i64 8
  %5 = load float, ptr %arrayidx2.2, align 4, !tbaa !5
  %..2 = tail call fast float @llvm.maxnum.f32(float %4, float %5)
  %arrayidx9.2 = getelementptr inbounds i8, ptr %c, i64 8
  store float %..2, ptr %arrayidx9.2, align 4, !tbaa !5
  %arrayidx.3 = getelementptr inbounds i8, ptr %a, i64 12
  %6 = load float, ptr %arrayidx.3, align 4, !tbaa !5
  %arrayidx2.3 = getelementptr inbounds i8, ptr %b, i64 12
  %7 = load float, ptr %arrayidx2.3, align 4, !tbaa !5
  %..3 = tail call fast float @llvm.maxnum.f32(float %6, float %7)
  %arrayidx9.3 = getelementptr inbounds i8, ptr %c, i64 12
  store float %..3, ptr %arrayidx9.3, align 4, !tbaa !5
  ret ptr %c
}
```

The pair of `[‘llvm.vp.fcmp.*’](https://llvm.org/docs/LangRef.html#id2420)` and `[‘llvm.vp.select.*’](https://llvm.org/docs/LangRef.html#id2349)` may be better.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVl2PozYU_TXOyxXIXAOBBx4mm41UqVKlbd9Hxhji1pjUmNlJf31lAvmYZLpkVYSEP67PPfeeE8W871VjpCxIsiHJdsUHt-9s8f2fvj_-zVdlVx0LktLppVtCX2rdcQcEX2qC2XnCCX6B86y8mQmCOZD15nQepqfuLBDMlHGgCNtSwjZ-8CU-DXAzvg8Ozo8gyUaRZAuEbYFPE8K-lufh7rL6cln9AEfW29sFK91gDYhz5DniQyfOiyHBXakMwZ3Q3DQQ_MYgCBy3jXSEbd-z9DWNA63M8B40ZoCg5W_vCMHvYEIBgWyVC7R-ayGoa967oOVuT1IKfqOHX76BVn_JhxQqWSsjoeq7V90JrsF0g6lkDQdngcTUa-SHphP84AYrzwFW8qoz-ggEk1G8H4eVl7B503dKVvDdKifnsFHukc3rYAxvZfXKq8qLzehFTWmcPRL2MveeYEJHJXXHq5N35nQzQ65VYyD2Q4KRKzn33-QKIfocoVyGEI4IjisNgmsNXo_ZyTH1IoUtfzdDG9YMr34ACb22fBIRzGfU3nVWXrbCK1JiGSluLT-q6j081ddIJ7VspXEeRpnSy9GDyj42TKUxxFc4-B8NPqd4jhI-wal8xIn9mBMuJRVOZH5CPryRj13Jd0Uk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