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

            Bug ID: 107047
           Summary: load introduced of struct fields after assigning it to
                    a local variable
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

for gcc-12.1.0, with this code:

struct S6 {
   short  f0;
   char  f1;
   int  f2;
};

struct S6 g_36 = {2UL,4L,0x32B3D10AL};
int g_48 = (-1L);


void func_30() {
    struct S6 f[4][7];
    f[1][6] = g_36;
    if (f[1][6].f0 || f[1][6].f1)
        g_48 = f[1][6].f1;
}

when compiled with -O1 option, generated binaries will be like:

0000000000401186 <func_30>:
  401186:       48 83 ec 70             sub    $0x70,%rsp
  40118a:       f7 05 d4 2e 00 00 ff    testl  $0xffffff,0x2ed4(%rip)        #
404068 <g_36>
  401191:       ff ff 00 
  401194:       74 0d                   je     4011a3 <func_30+0x1d>
  401196:       0f be 05 cd 2e 00 00    movsbl 0x2ecd(%rip),%eax        #
40406a <g_36+0x2>
  40119d:       89 05 bd 2e 00 00       mov    %eax,0x2ebd(%rip)        #
404060 <g_48>
  4011a3:       48 83 c4 70             add    $0x70,%rsp
  4011a7:       c3                      retq   

we can see the use of f[1][6] is replaced by g_36 in the if-condition and "g_48
= f[1][6].f1", and the f is not optimized away.

Reply via email to