Issue |
145398
|
Summary |
Failure to recognize that `int` and `int[1]` cannot alias
|
Labels |
missed-optimization,
TBAA
|
Assignees |
|
Reporter |
Kmeakin
|
Thanks to C's strict aliasing rules, `s->x` and `a->xs[0]` cannot alias.
Therefore the second load of `s->x` in `src` is unnecessary.
https://godbolt.org/z/dcEPvE3ef
```c
typedef struct Singleton {
int x;
} Singleton;
typedef struct Array {
int xs[1];
} Array;
int src(Singleton* s, Array* a) {
s->x = 0;
a->xs[0] = 1;
return s->x;
}
int tgt(Singleton* s, Array* a) {
s->x = 0;
a->xs[0] = 1;
return 0;
}
```
```asm
src:
mov w8, #1
str wzr, [x0]
str w8, [x1]
ldr w0, [x0]
ret
tgt:
mov w8, #1
str wzr, [x0]
mov w0, wzr
str w8, [x1]
ret
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs