https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108133
Bug ID: 108133
Summary: Failure to merge conditional bit clears
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
void foo (int *p)
{
if (*p & (1<<3))
*p &= ~(1<<3);
if (*p & (1<<5))
*p &= ~(1<<5);
if (*p & (1<<6))
*p &= ~(1<<6);
}
could be optimized to
if (*p & ((1<<3)|(1<<5)|(1<<6)))
*p &= ~((1<<3)|(1<<5)|(1<<6));
We have such code in tree-inline.cc:
/* Clear flags that need revisiting. */
if (gcall *call_stmt = dyn_cast <gcall *> (copy))
{
if (gimple_call_tail_p (call_stmt))
gimple_call_set_tail (call_stmt, false);
if (gimple_call_from_thunk_p (call_stmt))
gimple_call_set_from_thunk (call_stmt, false);