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

            Bug ID: 114208
           Summary: DSE deletes a store that is not dead
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gjl at gcc dot gnu.org
  Target Milestone: ---

Created attachment 57594
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57594&action=edit
Reduced C test case

$ avr-gcc -mmcu=attiny40 bug-dse.c -S -Os -dp -mfuse-add=3 -fdse

the following C test case:

struct S { char a, b; };

__attribute__((__noinline__,__noclone__))
void test (const struct S *s)
{
    if (s->a != 3 || s->b != 4)
        __builtin_abort();
}

int main (void)
{
    struct S s = { 3, 4 };
    test (&s);

  return 0;
}

Then with DSE off (-fno-dse), main has a store of 3 into s.a:

main:
        ...
        ldi r20,lo8(3)   ;  22  [c=4 l=1]  movqi_insn/1
        ld __tmp_reg__,Y+        ;  24  [c=4 l=1]  *addhi3/3
        st Y+,r20                ;  48  [c=4 l=1]  movqi_insn/2
        ldi r20,lo8(4)   ;  27  [c=4 l=1]  movqi_insn/1
        st Y,r20                 ;  30  [c=4 l=1]  movqi_insn/2
        ...

but with DSE on, pass .dse2 removes the first store (insn 48, and in the wake
also insn 22) that sets s.a to 3:

main:
        ...
        ldi r20,lo8(4)   ;  27  [c=4 l=1]  movqi_insn/1
        subi r28,-2      ;  29  [c=4 l=2]  *addhi3/3
        sbci r29,-1
        st Y,r20                 ;  30  [c=4 l=1]  movqi_insn/2
        ...

Configured with: ../../source/gcc-master/configure --target=avr --disable-nls
--with-dwarf2 --with-gnu-as --with-gnu-ld --disable-shared
--enable-languages=c,c++
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 14.0.1 20240302 (experimental) (GCC)

Reply via email to