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

            Bug ID: 115346
           Summary: [15] Volatile load elimination with packed struct
                    bitfields at -O2
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick at rivosinc dot com
  Target Milestone: ---

Testcase:
#pragma pack(1)
struct a {
  unsigned b;
  long c : 33;
  unsigned d : 31;
};
volatile struct a h[40];
int main() {
  for (int i = 0; i < 40; i++) {
    h[0];
  }
}

-O3 asm output:
main:
        xor     eax, eax
        ret
h:
        .zero   480

Removing the pack pragma causes the loads to be emitted.

Godbolt: https://godbolt.org/z/3YfrbzdPz
GCC 4.0.4 does not eliminate the loads: https://godbolt.org/z/frsP8o7YT

Reply via email to