<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/115252>115252</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed strict aliasing optimization between structs with similar layouts
</td>
</tr>
<tr>
<th>Labels</th>
<td>
enhancement,
c,
TBAA
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
PiJoules
</td>
</tr>
</table>
<pre>
Given this example:
```
typedef struct {
int i1;
} s1;
typedef struct {
int i1;
} s2_alt;
int f2(s1 *s1p, s2_alt *s2p) {
s1p->i1 = 2;
s2p->i1 = 3;
return s1p->i1 * 3;
}
```
I *think* strict aliasing rules in C should indicate that pointers to `s1` and `s2` shouldn't alias and `f2` can just directly return 6. ToT clang doesn't seem to be doing that (compiling with `-O3 -fstrict-aliasing`):
```
f2:
mov dword ptr [rdi], 2
mov dword ptr [rsi], 3
mov eax, dword ptr [rdi]
lea eax, [rax + 2*rax]
ret
```
whereas ToT gcc seems to give
```
f2:
mov DWORD PTR [rdi], 2
mov eax, 6
mov DWORD PTR [rsi], 3
ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVF-PozYQ_zTmZZQIDwGSBx6SpalaqbrTaaU-Vg5MwFdjI3vI7vbTVyZkN6fbrrYI2czMb_79xliFoDtLVIn8IPI6URP3zldf9e9uMhSSk2tfql_1hSxwrwPQsxpGQyLbi7QW6W0t0uWdRX4ZqaUzBPZTwyDKw1UPoC2DliJbFKKsIbyJ_88P_1KG31TzGnFnFLgNEgTugxwFPizQWYGjwN1d5CDHlch-0RJEVgO-hgMIeG_J7iyeePL23hX3dwBR1u-ycl1_i2jutf07egX2umFQRqugbQc-kg7awgOE3k2mBW1b3Sgm4F4xjE5bJh-AHYgiDVIUKSjbzgJG4epmBZZL2Jv5PJsbZeH7FBha7alh83LrpljDo3uExijbQesoXEMEoiEmOxG0LlY4lyFw27hh1CZqnjT3McHqSwar87Wj1a2j2D3uPj4uZ3y1w_IM7jLv7ZPzLYzsQeQH32qR13Gg-Bl0uKGz99GknqP1vRQ_4A2pe3xEqWcQeAAUuPfq-c3DE38w-qeePKkw89w1zcztPMlOX-iT_NyKr__88q2Gr4_fPkXMUnrxvvXHWP9F28-9JW2VtbtspxKqZJmlu812U8qkr7K0oPZExTbHLC9RUr5Vqkw3VOApLTeU6ApT3EiZlmmWSinX57xtJO6aUqpNWZwLsUlpUNqsjbkMa-e7RIcwUSVljjkmRp3IhPnOQiTbK9vQQJYFosAHgdi8fj0e9vso5HXiqxhtdZq6IDap0YHDW3zWbKj6Q4dA7U-_pRtZD_ofxdpZOBE_EdnllgrX8x_0oI3yYNSLmzgkkzdVzzyGODo8Cjx2mvvptG7cIPAY0y7bavTuOzUs8Dj3GAQelzYvFf4bAAD__6HOlYc">