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

            Bug ID: 123035
           Summary: missing optimization with bitfields on the gimple
                    level
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 19466, 99919
  Target Milestone: ---

Take:
```
struct B { char i: 1; };

void g (struct B b)
{
  if (!b.i)
    {
      int t = b.i;
      if (t) __builtin_trap();
    }
}
```

The call to __builtin_trap should be removed on the gimple level but currently
it is not.

This is due to the way `if (!b.i)` is translated to:
```
  _1 = BIT_FIELD_REF <b, 8, 0>;
  _2 = _1 & 1;
  if (_2 == 0)
```

Early on and then the load from b.i is not noticed to be the same as _2. 

This is extracted out from PR 99919.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19466
[Bug 19466] [meta-bug] bit-fields are non optimal
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99919
[Bug 99919] [13/14/15/16 Regression] bogus -Wmaybe-uninitialized with a _Bool
bit-field

Reply via email to