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

            Bug ID: 126135
           Summary: a|CST should simplify to a if `(a&CST)==CST`
           Product: gcc
           Version: 17.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
            Blocks: 85316
  Target Milestone: ---

Take:
```
unsigned f2(unsigned a)
{
  if ((a&5)!=5) __builtin_unreachable();
  return a | 5;
}
```

This should just be `return a;`

The information from VRP is there already:
```
  # RANGE [irange] unsigned int [5, +INF] MASK 0xfffffffa VALUE 0x5
  unsigned int a_2(D) = a;
  unsigned int _3;

  <bb 2> [local count: 1073741824]:
  # RANGE [irange] unsigned int [5, +INF] MASK 0xfffffffa VALUE 0x5
  _3 = a_2(D) | 5;
```


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases

Reply via email to