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

    <tr>
        <th>Summary</th>
        <td>
            Bad codegen after 8adfa29706e
        </td>
    </tr>

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

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

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

<pre>
    We have an internal test that recently started to fail which I bisected back to 8adfa29706e5407b62a4726e2172894e0dfdc1e8.

I was able to reduce the test a little bit to the following:
```c++
extern "C" void printf(...);
typedef float __m128 __attribute__((__vector_size__(16)));
typedef int __v8su __attribute__((__vector_size__(32)));
typedef float __m256 __attribute__((__vector_size__(32)));
__m256 _mm256_max_ps___b, _mm256_hadd_ps___b, _mm256_hsub_ps___b,
    test89___trans_tmp_15, test89___trans_tmp_14, test89___trans_tmp_13,
    test89___trans_tmp_12, test89___trans_tmp_11, test89___trans_tmp_10,
    test89___trans_tmp_8, test89___trans_tmp_7, test89___trans_tmp_6,
    test89___trans_tmp_5, test89___trans_tmp_4, test89___trans_tmp_3,
    test89_id18854, test89_id18860, test89_id18872, test89_id18873;
template <typename T> T zero_upper(T in, unsigned) { return in; }
void init(char pred, void *data, unsigned size) {
  unsigned char *bytes = (unsigned char *)data;
  for (unsigned i = 0; i != size; ++i)
    bytes[i] = pred + i;
}
typedef long __attribute__((ext_vector_type(2))) ll2;
ll2 test89_id18839 = -1964383749;
__m128 test89_id18845, test89_id18879, test89_id18881;
void test89() {
  test89___trans_tmp_3 = __builtin_ia32_vcvtph2ps256(test89_id18839);
  init(69, &test89_id18845, sizeof(test89_id18845));
  test89___trans_tmp_4 = __builtin_shufflevector(test89_id18845, test89_id18845,
                                                 0, 1, 2, 3, 1, 1, 1, 1);
  __m256 id18844, id18870;
  test89___trans_tmp_5 = __builtin_ia32_rcpps256(id18844);
  test89___trans_tmp_6 =
      __builtin_ia32_maxps256(test89___trans_tmp_5, _mm256_max_ps___b);
  init(211, &test89_id18854, sizeof(test89_id18854));
  test89___trans_tmp_7 = (__v8su)test89___trans_tmp_6 & (__v8su)test89_id18854;
  init(205, &test89_id18860, sizeof(test89_id18860));
  test89___trans_tmp_8 =
      __builtin_ia32_hsubps256(test89_id18860, _mm256_hsub_ps___b);
  for (int id18871_idx = 0; id18871_idx < 92; ++id18871_idx) {
    init(220, &test89_id18872, sizeof(test89_id18872));
    id18870 *= test89_id18872;
  }
  init(220, &test89_id18873, sizeof(test89_id18873));
  __m128 id18878;
  init(252, &id18878, sizeof(id18878));
  for (int id18880_idx = 0; id18880_idx < 31; ++id18880_idx)
    test89_id18879 -= test89_id18881;
  __m128 __a = id18878;
  __a[0] += test89_id18881[0];
  test89___trans_tmp_10 =
      __builtin_shufflevector(__a, __a, 0, 1, 2, 3, 1, 1, 1, 1);
  __m256 id18874(zero_upper(test89___trans_tmp_10, 8));
  test89___trans_tmp_11 =
      __builtin_ia32_blendvps256(id18870, test89_id18873, id18874);
  test89___trans_tmp_12 = __builtin_shufflevector(
      test89___trans_tmp_8, test89___trans_tmp_11, 0, 8, 1, 1, 4, 2, 1, 1);
  test89___trans_tmp_13 =
      __builtin_ia32_haddps256(test89___trans_tmp_12, _mm256_hadd_ps___b);
  test89___trans_tmp_14 =
      ~(__v8su)test89___trans_tmp_7 & (__v8su)test89___trans_tmp_13;
  test89___trans_tmp_15 =
      (__v8su)test89___trans_tmp_3 | (__v8su)test89___trans_tmp_14;
  printf("%f\n", test89___trans_tmp_15[0]);
}
int main() { test89(); }
```
When the above code is compiled with optimizations targeting btver2 (`-O2 -march=btver2`), it generates a different value after 8adfa29706e5407b62a4726e2172894e0dfdc1e8:
```
$ ~/src/upstream/ffe1661fabc9cf379a10a0bf15268c6549e4836f-linux/bin/clang++ -O2 -march=btver2 test.cpp -o test.good.elf
$ ./test.good.elf
-268361104.000000
$ ~/src/upstream/8adfa29706e5407b62a4726e2172894e0dfdc1e8-linux/bin/clang++ -O2 -march=btver2 test.cpp -o test.bad.elf
$ ./test.bad.elf
-3701730859659994532950310912.000000
```
Here is a link to godbolt showing the output difference between trunk and LLVM 15: https://godbolt.org/z/E63hbbTfs
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylWEuTmzgQ_jX4orJLSDwPPiSeTG2qsrWX1OZICRBGuxgoEJ7M_PptSQbz8jDZuLABtdTv_tRyXKWvxx8c5ezKESuRKCVvSlYgyVuJZM4kanjCS1m8olayRvIUyQplTBToJRdJjr6iWLQ8UYSYJf8qasDSjJHQxx53HezHHmGOTzxObJ8EocNxmqWJzYODhZ8s_Mn8fkUvrEUsLrhi0fC0S-Ap50YThgohJdBiIRVdEbKqKKoXUZ4teuNhedhciUU-q0uP8p_KJmQRcoIvulYiRXUDlmYWCQ6Hg0VCi97myteapzxDWVGB6VF0sUkANyZlI-JO8iiCNXBF0RVsrpqoFW9m0PYUH3PNuYEsYHIN2u5jvCh5zGvQjLje_-fWr7-oW3RhP6O6jaIotsipH8xZmq6Mtl18HzXMEHxUlIIQhmXDyjaSlzqyXbVujeA8ItBNnuTRUvsRAW_xDB6s9B-Me1sMH9n9yOxVq0VqB4E7XqJHPDwf8clihN6zhl_qgkmOLHpSGVSyC0ffLfoFfUdvvKmirq55A0nyHZJU8enKVpxLnkKyIMv_DIUou0bhArCEgSfDVteQKIWElUnOGqgnteRkissin1Im2ZgdUtl449mbOtA0B1gUv4IVoOkTvAQLKqzWXOnAIKuayUyh12KlKTwSW71puUp1DQhC1cDgaS3PcmHUfdJLlRVqJhKDlMHkvv6Kqjyv1R2gTF95aiqM3MsOFQUZOMLzJFo01LL3dug5NKC-M6lShT_j2Y67iHY4HwnsgYOOh6FpNScBWEtFrQsUdycKKcpIMEqia3KVdU7qFgAAuEyVH6MK6nPC0zpZxFuqrgJSZTM2ijTjtFY_M-XavMuyghuvr3A8LT13D_4vfXTRaYTRxUaH18nPWP0bwBrJuopNsPD7Jrp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