public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/113927] New: [avr-tiny] Sets up a stack-frame even for trivial code
@ 2024-02-15  9:43 gjl at gcc dot gnu.org
  2024-02-15 12:47 ` [Bug other/113927] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-02-15  9:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113927
           Summary: [avr-tiny] Sets up a stack-frame even for trivial code
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gjl at gcc dot gnu.org
  Target Milestone: ---

Code like

char func (char c)
{
    return c;
}

compiles as expected to

func:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
/* epilogue start */
        ret

with  avr-gcc -S -Os -mmcu=attiny26 -da , but for attiny40 (Reduced Tiny with
16 GPRs only) the result is:

func:
        push r28
        push r29
        push __tmp_reg__
        in r28,__SP_L__
        in r29,__SP_H__
/* prologue: function */
/* frame size = 1 */
/* stack size = 3 */
.L__stack_usage = 3
/* epilogue start */
        pop __tmp_reg__
        pop r29
        pop r28
        ret

In .asmcons, i.e. just prior to register allocation, the code reads:

(insn 13 4 2 2 (set (reg:QI 46)
        (reg:QI 24 r24 [ c ])) "main.c":2:1 86 {movqi_insn_split}
     (expr_list:REG_DEAD (reg:QI 24 r24 [ c ])
        (nil)))
(insn 2 13 3 2 (set (reg/v:QI 44 [ c ])
        (reg:QI 46)) "main.c":2:1 86 {movqi_insn_split}
     (expr_list:REG_DEAD (reg:QI 46)
        (nil)))
(note 3 2 10 2 NOTE_INSN_FUNCTION_BEG)
(insn 10 3 11 2 (set (reg/i:QI 24 r24)
        (reg/v:QI 44 [ c ])) "main.c":4:1 86 {movqi_insn_split}
     (expr_list:REG_DEAD (reg/v:QI 44 [ c ])
        (nil)))
(insn 11 10 0 2 (use (reg/i:QI 24 r24)) "main.c":4:1 -1
     (nil))

so everything is fine and this PR is not a dup of PR110093.  According to
Vladimir Makarov, PR110093 is because DFA cannot handle subregs, but the RTL
code above does not have subregs.  What's the case is that IRA has very high
register costs, for example in .ira:

Pass 0 for finding pseudo/allocno costs

    a1 (r46,l0) best NO_REGS, allocno NO_REGS
    a0 (r44,l0) best NO_REGS, allocno NO_REGS

  a0(r44,l0) costs: POINTER_X_REGS:65535000 POINTER_Y_REGS:65535000
POINTER_Z_REGS:65535000 BASE_POINTER_REGS:65535000 POINTER_REGS:65535000
SIMPLE_LD_REGS:65535000 GENERAL_REGS:65535000 MEM:3000

whereas the .ira for attiny26 (ordinary core with 32 GPRs):

Pass 0 for finding pseudo/allocno costs

    a0 (r46,l0) best GENERAL_REGS, allocno GENERAL_REGS

  a0(r46,l0) costs: POINTER_X_REGS:4000 POINTER_Y_REGS:4000 POINTER_Z_REGS:4000
BASE_POINTER_REGS:4000 POINTER_REGS:4000 ADDW_REGS:4000 SIMPLE_LD_REGS:4000
LD_REGS:4000 NO_LD_REGS:4000 GENERAL_REGS:4000 MEM:4000

../../source/gcc-master/configure --target=avr --disable-nls --with-dwarf2
--with-gnu-as --with-gnu-ld --disable-shared --enable-languages=c,c++

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

* [Bug other/113927] [avr-tiny] Sets up a stack-frame even for trivial code
  2024-02-15  9:43 [Bug other/113927] New: [avr-tiny] Sets up a stack-frame even for trivial code gjl at gcc dot gnu.org
@ 2024-02-15 12:47 ` pinskia at gcc dot gnu.org
  2024-02-15 13:09 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-15 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization

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

* [Bug other/113927] [avr-tiny] Sets up a stack-frame even for trivial code
  2024-02-15  9:43 [Bug other/113927] New: [avr-tiny] Sets up a stack-frame even for trivial code gjl at gcc dot gnu.org
  2024-02-15 12:47 ` [Bug other/113927] " pinskia at gcc dot gnu.org
@ 2024-02-15 13:09 ` cvs-commit at gcc dot gnu.org
  2024-02-15 13:49 ` cvs-commit at gcc dot gnu.org
  2024-02-15 13:50 ` [Bug target/113927] " gjl at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-15 13:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Georg-Johann Lay <gjl@gcc.gnu.org>:

https://gcc.gnu.org/g:5cff288c2dae4ea709df067cf398f23e214b2e80

commit r14-9009-g5cff288c2dae4ea709df067cf398f23e214b2e80
Author: Georg-Johann Lay <avr@gjlay.de>
Date:   Thu Feb 15 13:53:34 2024 +0100

    AVR: target 113927 - Simple code triggers stack frame for Reduced Tiny.

    The -mmcu=avrtiny cores have no ADIW and SBIW instructions.  This was
    implemented by clearing all regs out of regclass ADDW_REGS so that
    constraint "w" never matched.  This corrupted the subset relations of
    the register classes as they appear in enum reg_class.

    This patch keeps ADDW_REGS like for all other cores, i.e. it contains
    R24...R31.  Instead of tests like  test_hard_reg_class (ADDW_REGS, *)
    the code now uses  avr_adiw_reg_p (*).  And all insns with constraint "w"
    get "isa" insn attribute value of "adiw".

    Plus, a new built-in macro __AVR_HAVE_ADIW__ is provided, which is more
    specific than __AVR_TINY__.

    gcc/
            PR target/113927
            * config/avr/avr.h (AVR_HAVE_ADIW): New macro.
            * config/avr/avr-protos.h (avr_adiw_reg_p): New proto.
            * config/avr/avr.cc (avr_adiw_reg_p): New function.
            (avr_conditional_register_usage) [AVR_TINY]: Don't clear ADDW_REGS.
            Replace test_hard_reg_class (ADDW_REGS, ...) with calls to
            * config/avr/avr.md: Same.
            (attr "isa") <tiny, no_tiny>: Remove.
            <adiw, no_adiw>: Add.
            (define_insn, define_insn_and_split): When an alternative has
            constraint "w", then set attribute "isa" to "adiw".
            * config/avr/avr-c.cc (avr_cpu_cpp_builtins) [AVR_HAVE_ADIW]:
            Built-in define __AVR_HAVE_ADIW__.
            * doc/invoke.texi (AVR Options): Document it.

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

* [Bug other/113927] [avr-tiny] Sets up a stack-frame even for trivial code
  2024-02-15  9:43 [Bug other/113927] New: [avr-tiny] Sets up a stack-frame even for trivial code gjl at gcc dot gnu.org
  2024-02-15 12:47 ` [Bug other/113927] " pinskia at gcc dot gnu.org
  2024-02-15 13:09 ` cvs-commit at gcc dot gnu.org
@ 2024-02-15 13:49 ` cvs-commit at gcc dot gnu.org
  2024-02-15 13:50 ` [Bug target/113927] " gjl at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-15 13:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Georg-Johann Lay
<gjl@gcc.gnu.org>:

https://gcc.gnu.org/g:0f0ca42fb5556f2c6b76b017fbbd90820a728ce0

commit r13-8327-g0f0ca42fb5556f2c6b76b017fbbd90820a728ce0
Author: Georg-Johann Lay <avr@gjlay.de>
Date:   Thu Feb 15 13:53:34 2024 +0100

    AVR: target 113927 - Simple code triggers stack frame for Reduced Tiny.

    The -mmcu=avrtiny cores have no ADIW and SBIW instructions.  This was
    implemented by clearing all regs out of regclass ADDW_REGS so that
    constraint "w" never matched.  This corrupted the subset relations of
    the register classes as they appear in enum reg_class.

    This patch keeps ADDW_REGS like for all other cores, i.e. it contains
    R24...R31.  Instead of tests like  test_hard_reg_class (ADDW_REGS, *)
    the code now uses  avr_adiw_reg_p (*).  And all insns with constraint "w"
    get "isa" insn attribute value of "adiw".

    Plus, a new built-in macro __AVR_HAVE_ADIW__ is provided, which is more
    specific than __AVR_TINY__.

    gcc/
            PR target/113927
            * config/avr/avr.h (AVR_HAVE_ADIW): New macro.
            * config/avr/avr-protos.h (avr_adiw_reg_p): New proto.
            * config/avr/avr.cc (avr_adiw_reg_p): New function.
            (avr_conditional_register_usage) [AVR_TINY]: Don't clear ADDW_REGS.
            Replace test_hard_reg_class (ADDW_REGS, ...) with calls to
            * config/avr/avr.md: Same.
            (attr "isa") <tiny, no_tiny>: Remove.
            <adiw, no_adiw>: Add.
            (define_insn, define_insn_and_split): When an alternative has
            constraint "w", then set attribute "isa" to "adiw".
            * config/avr/avr-c.cc (avr_cpu_cpp_builtins) [AVR_HAVE_ADIW]:
            Built-in define __AVR_HAVE_ADIW__.
            * doc/invoke.texi (AVR Options): Document it.

    (cherry picked from commit 5cff288c2dae4ea709df067cf398f23e214b2e80)

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

* [Bug target/113927] [avr-tiny] Sets up a stack-frame even for trivial code
  2024-02-15  9:43 [Bug other/113927] New: [avr-tiny] Sets up a stack-frame even for trivial code gjl at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-02-15 13:49 ` cvs-commit at gcc dot gnu.org
@ 2024-02-15 13:50 ` gjl at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-02-15 13:50 UTC (permalink / raw)
  To: gcc-bugs

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

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
           Keywords|missed-optimization         |
   Target Milestone|---                         |13.3
          Component|other                       |target
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Fixed in v13.3+

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

end of thread, other threads:[~2024-02-15 13:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-15  9:43 [Bug other/113927] New: [avr-tiny] Sets up a stack-frame even for trivial code gjl at gcc dot gnu.org
2024-02-15 12:47 ` [Bug other/113927] " pinskia at gcc dot gnu.org
2024-02-15 13:09 ` cvs-commit at gcc dot gnu.org
2024-02-15 13:49 ` cvs-commit at gcc dot gnu.org
2024-02-15 13:50 ` [Bug target/113927] " 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).