https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118658

            Bug ID: 118658
           Summary: `(a | CST)` -> a if we know that a already contains
                    all bits of CST set
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
unsigned f1(unsigned a)
{
  if ((a & 3) != 3) __builtin_unreachable();
  return a | 1;
}
```

This should just optimize to `return a;`

(simplify
 (bit_ior SSA_NAME@0 INTEGER_CST@1)
 /* x | C -> x if we know that x & C == C.  */
 (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
      && wi::bit_and (get_known_nonzero_bits (@0), wi::to_wide (@1)) ==
wi::to_wide (@1))
  @0))

Reply via email to