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

    <tr>
        <th>Summary</th>
        <td>
            Bad codegen after e1dd2cd06 with optimizations enabled
        </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 a bunch of internal tests that started to fail which I bisected one down to the commit e1dd2cd063785ea3a6004c8d173f13113b1b8265. The tests produce the wrong output when compiled with optimizations.

Consider the code test.cpp:
```c++
#include <stdio.h>
typedef char __attribute__((ext_vector_type(4))) char4;
typedef char __attribute__((ext_vector_type(16))) char16;
#define char4_wxxy(__A) (__A.wxxy)
#define char4_yywz(__A) (__A.yywz)
char4 main_id6650{(char)-97930665};
int main() {
  for (char id6651_idx = 0; id6651_idx < 2; ++id6651_idx) {
    char4 id6652{(char)-10402671, (char)-30075058};
    main_id6650 ^= id6652;
  }
  char4 id6649 char4_wxxy(main_id6650);
  char4 id6648 char4_yywz(id6649);
  char16 id6647 = __builtin_shufflevector(id6648, id6648, 2, 3, 3, 6, 5, 0, 1,
                                          3, 7, 0, 4, 1, 6, 4, 3, 0);
  printf("%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", id6647[0],
         id6647[1], id6647[2], id6647[3], id6647[4], id6647[5], id6647[6],
         id6647[7], id6647[8], id6647[9], id6647[10], id6647[1], id6647[12],
         id6647[13], id6647[4], id6647[5]);
}
```
Before e1dd2cd063785ea3a6004c8d173f13113b1b8265, when compiled with optimizations, the code would produce the following output:
```
$ ~/src/upstream/16f9c5577d2f498ba459de1862f8474882ea0690-linux/bin/clang -O2 -mavx test.cpp -o test.good.out
$ ./test.good.out
0 57 57 0 57 57 57 57 57 57 57 57 0 57 57 57
```
But after e1dd2cd063785ea3a6004c8d173f13113b1b8265, compiling the same code with optimizations now produces the following output:
```
$ ~/src/upstream/e1dd2cd063785ea3a6004c8d173f13113b1b8265-linux/bin/clang -O2 -mavx test.cpp -o test.bad.out
$ ./test.bad.out
4e ffffffc6 ffffffc6 4e ffffffc6 ffffffc6 ffffffc6 ffffffc6 ffffffc6 ffffffc6 ffffffc6 ffffffc6 4e ffffffc6 ffffffc6 ffffffc6
```
I realize that this change was reverted in d7592bbb0362b38d82bdf6e97294f54059e3f456 (for a different reason), but if it will be resubmitted, it will contain the problem I have described here and it should be fixed before resubmitting.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytFsuOozjwa8jFCjJ-8DjkMJ3uSHPay0p7RAYXwSsCEZhO0l-_ZZOEzmNnekYTWY5d7yoXVVV0-rT6B0it3oEoUoxtWZOuIqa10LeqIRYGOxBbK0sGq3oLmtiOVMo05FAbJP5OCjNA6RBdC0R3h9ZR2BpI2e12xhKItGalpjFPUgmKq5hSUaY6SngV8SjiRVSkLJYh-RuZJoX7vtNjCV7Moe_aLelGux8tKoXWCd6bBjUejEVz99bszIeypmuHMKCvAf027WsEGA392Ro9SQ_L_T7gZ5IgptMqA_bi1gRl3LRlMyJHwNeD1aYL64C_TVh72oOGipS16kmeK2t7U4wW8jxgKS442vwdQ9L1uSNFiAhYNi3PJAL-8ruiovhWFt75bDXKMvgKXkl-OB5PyJHn3xzxdAonYPac43Q6fDxwTMAzh6cjO2Xa3Og4ljRIMGypAyPNMksyThEcJK9XszCXPIP3CKUmZzghVdeTMzPx0iIUesSQvxKK7LewNWEONj3TjLkTSSZPJlZ2a1xEBWVxEgVsTT6BOaWJpDL9bLMT9MlJEsg3Z9VZ6kzleM7HWa_Ibh_gc7QwjjP3J5b09gUmMY_UUTyRJz5IeV6MprEofajHqmpgSpULf-ocnU_Mbfy6xW6TbqNuc1GZff_az8tJriLERc4kW1xV3bm97zElKp8OaJPEx_1jWyDXrZd6djwJ5AsN5Oujc1d0NKFnALsH8HuAuAfIe0D8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