https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120403
Bug ID: 120403
Summary: Can't collapse two equality into one
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: hiraditya at msn dot com
Target Milestone: ---
#include <stdint.h>
struct s {
int x, y;
};
bool cmp(struct s s1, struct s s2) {
return s1.x == s2.x && s1.y == s2.y;
}
struct t {
int16_t x, y;
};
bool cmp_t(struct t s1, struct t s2) {
return s1.x == s2.x && s1.y == s2.y;
}
$ gcc -O3 generates
```asm
cmp(s, s):
xor eax, eax
cmp edi, esi
je .L5
ret
.L5:
sar rdi, 32
sar rsi, 32
cmp edi, esi
sete al
ret
cmp_t(t, t):
xor eax, eax
cmp di, si
je .L9
ret
.L9:
sar edi, 16
sar esi, 16
cmp di, si
sete al
ret
```
clang -O3 generates
```asm
cmp(s, s):
cmp rdi, rsi
sete al
ret
cmp_t(t, t):
cmp edi, esi
sete al
ret
```
https://godbolt.org/z/8j71anzTW