public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/114208] New: DSE deletes a store that is not dead
@ 2024-03-02  9:45 gjl at gcc dot gnu.org
  2024-03-02  9:52 ` [Bug rtl-optimization/114208] RTL " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-03-02  9:45 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug rtl-optimization/114208] RTL DSE deletes a store that is not dead
  2024-03-02  9:45 [Bug rtl-optimization/114208] New: DSE deletes a store that is not dead gjl at gcc dot gnu.org
@ 2024-03-02  9:52 ` pinskia at gcc dot gnu.org
  2024-03-02 13:02 ` gjl at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-02  9:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I wonder if this is related to r14-6674-g4759383245ac97 .

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug rtl-optimization/114208] RTL DSE deletes a store that is not dead
  2024-03-02  9:45 [Bug rtl-optimization/114208] New: DSE deletes a store that is not dead gjl at gcc dot gnu.org
  2024-03-02  9:52 ` [Bug rtl-optimization/114208] RTL " pinskia at gcc dot gnu.org
@ 2024-03-02 13:02 ` gjl at gcc dot gnu.org
  2024-03-02 15:06 ` gjl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-03-02 13:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> I wonder if this is related to r14-6674-g4759383245ac97 .

Not unlikely. PR112525 tries to eliminate dead stores for arguments that are
passed.  It seems like that change misses some required conditions like
frame-pointer / arg-pointer adjustments.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug rtl-optimization/114208] RTL DSE deletes a store that is not dead
  2024-03-02  9:45 [Bug rtl-optimization/114208] New: DSE deletes a store that is not dead gjl at gcc dot gnu.org
  2024-03-02  9:52 ` [Bug rtl-optimization/114208] RTL " pinskia at gcc dot gnu.org
  2024-03-02 13:02 ` gjl at gcc dot gnu.org
@ 2024-03-02 15:06 ` gjl at gcc dot gnu.org
  2024-03-04 10:01 ` rguenth at gcc dot gnu.org
  2024-03-04 15:22 ` gjl at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-03-02 15:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> I wonder if this is related to r14-6674-g4759383245ac97 .

Seems unrelated: When I reverse-apply r14-6674 then the issue does not go away.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug rtl-optimization/114208] RTL DSE deletes a store that is not dead
  2024-03-02  9:45 [Bug rtl-optimization/114208] New: DSE deletes a store that is not dead gjl at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-03-02 15:06 ` gjl at gcc dot gnu.org
@ 2024-03-04 10:01 ` rguenth at gcc dot gnu.org
  2024-03-04 15:22 ` gjl at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-04 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Did it ever work?  I suppose 'st Y+,r20 is' post-inc so maybe DSE mishandles
this somehow.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug rtl-optimization/114208] RTL DSE deletes a store that is not dead
  2024-03-02  9:45 [Bug rtl-optimization/114208] New: DSE deletes a store that is not dead gjl at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-03-04 10:01 ` rguenth at gcc dot gnu.org
@ 2024-03-04 15:22 ` gjl at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-03-04 15:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #4)
> Did it ever work?
No.  I allowed -mfuse-add=3 to reproduce this PR because there seems to be a
problem with DSE, and for the case that someone is going to fix it before it
bites an important target.  The mfuse-add optimization tries to avoid the
broken parts of DSE and works around it; documented are only -mfuse-add=0...2 
It was added Feb 2024 as PR114100.

>  I suppose 'st Y+,r20 is' post-inc so maybe DSE mishandles this somehow.
That post-inc is only generated after .dse2: .split2 splits some move insns:
These cores don't have reg+offset addressing, so the backend must pretend to
support it.  Then .split2 generates pointer-adjust + mem-access +
undo-pointer-adjust.  The address adjustments are plain additions of the
address register (frame pointer in this case) and have according
REG_CFA_ADJUST_CFA notes.  Then .dse2 removes some non-dead stores.  The 'st
Y+,r20' you mentioned is only generated by .avr-fuse-add which runs after
.dse2.

I'd guess that GCC is not ready for targets with such tight addressing modes?
(without reg+offset addressing; stack-pointer cannot be used either, the only
SP accesses are PUSH and POP).

ad "needs-bisection": -mfuse-add is a new target optimization added as PR114100
in Feb 2024, so bi-secting won't work because -mfuse-add is not recognized
prior to that date.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-04 15:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-02  9:45 [Bug rtl-optimization/114208] New: DSE deletes a store that is not dead gjl at gcc dot gnu.org
2024-03-02  9:52 ` [Bug rtl-optimization/114208] RTL " pinskia at gcc dot gnu.org
2024-03-02 13:02 ` gjl at gcc dot gnu.org
2024-03-02 15:06 ` gjl at gcc dot gnu.org
2024-03-04 10:01 ` rguenth at gcc dot gnu.org
2024-03-04 15:22 ` gjl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).