https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109960
Bug ID: 109960
Summary: [10/11/12/13/14 Regression] missing combining of
`(a&1) != 0 || (a&2)!=0` into `(a&3)!=0`
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take the following C++ code (reduced from stmt_can_terminate_bb_p):
```
static inline bool f1(unsigned *a)
{
return (*a&1);
}
static inline bool f2(unsigned *a)
{
return (*a&2);
}
bool f(int c, unsigned *a)
{
if (c)
return 0;
return f2(a) || f1(a) ;
}
```
At -O1 we can produce:
```
movl $0, %eax
testl %edi, %edi
jne .L1
testb $3, (%rsi)
setne %al
.L1:
ret
```
But at -O2 we get:
xorl %eax, %eax
testl %edi, %edi
jne .L1
movl (%rsi), %edx
movl %edx, %eax
andl $1, %eax
andl $2, %edx
movl $1, %edx
cmovne %edx, %eax
.L1:
ret
Which is just so much worse.
This started in GCC 9.