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

            Bug ID: 97588
           Summary: Overzealous SRA of boolean bitfields
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rsandifo at gcc dot gnu.org
  Target Milestone: ---

For the nonsense code (reduced from real code):

--------------------------------------------------
struct s
{
  unsigned int foo : 11;
  unsigned int flag1 : 1;
  unsigned int bar : 11;
  unsigned int flag2 : 1;
};

void
f (int n, int *x, struct s *ptr, struct s flags)
{
  for (int i = 0; i < n; ++i)
    if (x[i] == 1)
      flags.flag1 = 1;
    else if (x[i] == 2)
      flags.flag2 = 1;
    else if (x[i] == 3)
      {
        if (flags.flag1)
          *ptr++ = flags;
      }
    else if (x[i] == 4)
      {
        if (flags.flag2)
          *ptr++ = flags;
      }
    else
      *ptr++ = flags;
}
--------------------------------------------------

SRA significantly pessimises the output.  At the machine level,
each update to flags is usually a simple register OR, bit-test,
or move, but SRA instead decides to split flags up into 4
pieces and reassemble it for "*ptr++ = flags" (which in the
original code is the hot statement).

Reply via email to