Issue 115252
Summary Missed strict aliasing optimization between structs with similar layouts
Labels enhancement, c, TBAA
Assignees
Reporter PiJoules
    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
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to