-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Open
Labels
TBAAType-Based Alias Analysis / Strict AliasingType-Based Alias Analysis / Strict Aliasingmissed-optimization
Description
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
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;
}
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
Metadata
Metadata
Assignees
Labels
TBAAType-Based Alias Analysis / Strict AliasingType-Based Alias Analysis / Strict Aliasingmissed-optimization