public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114100] New: [avr] Inefficient indirect addressing on Reduced Tiny
@ 2024-02-25 16:32 gjl at gcc dot gnu.org
  2024-02-25 16:33 ` [Bug target/114100] " gjl at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-02-25 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114100
           Summary: [avr] Inefficient indirect addressing on Reduced Tiny
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gjl at gcc dot gnu.org
  Target Milestone: ---

The Reduced Tiny core does not support indirect addressing with offset, which
basically means that every indirect memory access with a size of more than one
byte is effectively POST_INC or PRE_DEC.  The lack of that addressing mode is
currently handled by pretending to support it, and then let the insn printers
add and subtract again offsets as needed on the fly.

For example, the following C code

   int vars[10];

   void inc_var2 (void) {
      ++vars[2];
   }

is compiled to:

   ldi r30,lo8(vars)     ;  14   [c=4 l=2]  *movhi/4
   ldi r31,hi8(vars)
   subi r30,lo8(-(4))    ;  15   [c=8 l=6]  *movhi/2
   sbci r31,hi8(-(4))
   ld r20,Z+
   ld r21,Z
   subi r30,lo8((4+1))
   sbci r31,hi8((4+1))
   subi r20,-1             ;  16   [c=4 l=2]  *addhi3_clobber/1
   sbci r21,-1
   subi r30,lo8(-(4+1))    ;  17   [c=4 l=4]  *movhi/3
   sbci r31,hi8(-(4+1))
   st Z,r21
   st -Z,r20

where the code could be:

   ldi r30,lo8(vars+4)    ;  28   [c=4 l=2]  *movhi/4
   ldi r31,hi8(vars+4)
   ld r20,Z+              ;  17   [c=8 l=2]  *movhi/2
   ld r21,Z+
   subi r20,-1            ;  19   [c=4 l=2]  *addhi3_clobber/1
   sbci r21,-1
   st -Z,r21              ;  30   [c=4 l=2]  *movhi/3
   st -Z,r20

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

* [Bug target/114100] [avr] Inefficient indirect addressing on Reduced Tiny
  2024-02-25 16:32 [Bug target/114100] New: [avr] Inefficient indirect addressing on Reduced Tiny gjl at gcc dot gnu.org
@ 2024-02-25 16:33 ` gjl at gcc dot gnu.org
  2024-02-25 19:29 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-02-25 16:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
           Priority|P3                          |P4
           Keywords|                            |missed-optimization
             Target|                            |avr

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

* [Bug target/114100] [avr] Inefficient indirect addressing on Reduced Tiny
  2024-02-25 16:32 [Bug target/114100] New: [avr] Inefficient indirect addressing on Reduced Tiny gjl at gcc dot gnu.org
  2024-02-25 16:33 ` [Bug target/114100] " gjl at gcc dot gnu.org
@ 2024-02-25 19:29 ` pinskia at gcc dot gnu.org
  2024-02-29 19:42 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-25 19:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-02-25

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. One way of improving this is to slightly increase the cost of the
indirect addressing with offset for these cores.

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

* [Bug target/114100] [avr] Inefficient indirect addressing on Reduced Tiny
  2024-02-25 16:32 [Bug target/114100] New: [avr] Inefficient indirect addressing on Reduced Tiny gjl at gcc dot gnu.org
  2024-02-25 16:33 ` [Bug target/114100] " gjl at gcc dot gnu.org
  2024-02-25 19:29 ` pinskia at gcc dot gnu.org
@ 2024-02-29 19:42 ` cvs-commit at gcc dot gnu.org
  2024-03-01  9:15 ` gjl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-29 19:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 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:cda3836161834c5f21f264885891fe4d0ce90da1

commit r14-9244-gcda3836161834c5f21f264885891fe4d0ce90da1
Author: Georg-Johann Lay <avr@gjlay.de>
Date:   Thu Feb 29 17:19:27 2024 +0100

    AVR: target/114100 - Better indirect accesses for reduced Tiny

    The Reduced Tiny core does not support indirect addressing with offset,
    which basically means that every indirect memory access with a size
    of more than one byte is effectively POST_INC or PRE_DEC.  The lack of
    that addressing mode is currently handled by pretending to support it,
    and then let the insn printers add and subtract again offsets as needed.
    For example, the following C code

       int vars[10];

       void inc_var2 (void) {
          ++vars[2];
       }

    is compiled to:

       ldi r30,lo8(vars)     ;  14   [c=4 l=2]  *movhi/4
       ldi r31,hi8(vars)
       subi r30,lo8(-(4))    ;  15   [c=8 l=6]  *movhi/2
       sbci r31,hi8(-(4))
       ld r20,Z+
       ld r21,Z
       subi r30,lo8((4+1))
       sbci r31,hi8((4+1))
       subi r20,-1             ;  16   [c=4 l=2]  *addhi3_clobber/1
       sbci r21,-1
       subi r30,lo8(-(4+1))    ;  17   [c=4 l=4]  *movhi/3
       sbci r31,hi8(-(4+1))
       st Z,r21
       st -Z,r20

    where the code could be -- and with this patch actually is -- like

       ldi r30,lo8(vars+4)    ;  28   [c=4 l=2]  *movhi/4
       ldi r31,hi8(vars+4)
       ld r20,Z+              ;  17   [c=8 l=2]  *movhi/2
       ld r21,Z+
       subi r20,-1            ;  19   [c=4 l=2]  *addhi3_clobber/1
       sbci r21,-1
       st -Z,r21              ;  30   [c=4 l=2]  *movhi/3
       st -Z,r20

    This is achieved in two steps:

    - A post-reload split into "real" instructions during .split2.
    - A new avr-specific mini pass .avr-fuse-add that runs before
      RTL peephole and that tries to combine the generated pointer
      additions into memory accesses to form POST_INC or PRE_DEC.

    gcc/
            PR target/114100
            * doc/invoke.texi (AVR Options) <-mfuse-add>: Document.
            * config/avr/avr.opt (-mfuse-add=): New target option.
            * common/config/avr/avr-common.cc (avr_option_optimization_table)
            [OPT_LEVELS_1_PLUS]: Set -mfuse-add=1.
            [OPT_LEVELS_2_PLUS]: Set -mfuse-add=2.
            * config/avr/avr-passes.def (avr_pass_fuse_add): Insert new pass.
            * config/avr/avr-protos.h (avr_split_tiny_move)
            (make_avr_pass_fuse_add): New protos.
            * config/avr/avr.md [AVR_TINY]: New post-reload splitter uses
            avr_split_tiny_move to split indirect memory accesses.
            (gen_move_clobbercc): New define_expand helper.
            * config/avr/avr.cc (avr_pass_data_fuse_add): New pass data.
            (avr_pass_fuse_add): New class from rtl_opt_pass.
            (make_avr_pass_fuse_add, avr_split_tiny_move): New functions.
            (reg_seen_between_p, emit_move_ccc, emit_move_ccc_after): New
functions.
            (avr_legitimate_address_p) [AVR_TINY]: Don't restrict offsets
            of PLUS addressing for AVR_TINY.
            (avr_regno_mode_code_ok_for_base_p) [AVR_TINY]: Ignore -mstrict-X.
            (avr_out_plus_1) [AVR_TINY]: Tweak ++Y and --Y.
            (avr_mode_code_base_reg_class) [AVR_TINY]: Always return
POINTER_REGS.

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

* [Bug target/114100] [avr] Inefficient indirect addressing on Reduced Tiny
  2024-02-25 16:32 [Bug target/114100] New: [avr] Inefficient indirect addressing on Reduced Tiny gjl at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-02-29 19:42 ` cvs-commit at gcc dot gnu.org
@ 2024-03-01  9:15 ` gjl at gcc dot gnu.org
  2024-03-02  9:21 ` cvs-commit at gcc dot gnu.org
  2024-03-03 17:17 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-03-01  9:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Improved in v14

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

* [Bug target/114100] [avr] Inefficient indirect addressing on Reduced Tiny
  2024-02-25 16:32 [Bug target/114100] New: [avr] Inefficient indirect addressing on Reduced Tiny gjl at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-03-01  9:15 ` gjl at gcc dot gnu.org
@ 2024-03-02  9:21 ` cvs-commit at gcc dot gnu.org
  2024-03-03 17:17 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-02  9:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:96bad6c06d0108014a2b0e5d0921cb18066bb789

commit r14-9271-g96bad6c06d0108014a2b0e5d0921cb18066bb789
Author: Georg-Johann Lay <avr@gjlay.de>
Date:   Sat Mar 2 10:03:06 2024 +0100

    AVR: target/114100 - Factor in -mtiny-stack in frame pointer adjustments

    gcc/
            PR target/114100
            * config/avr/avr.cc (avr_out_plus_1) [-mtiny-stack]: Only adjust
            the low part of the frame pointer with 8-bit stack pointer.

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

* [Bug target/114100] [avr] Inefficient indirect addressing on Reduced Tiny
  2024-02-25 16:32 [Bug target/114100] New: [avr] Inefficient indirect addressing on Reduced Tiny gjl at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-03-02  9:21 ` cvs-commit at gcc dot gnu.org
@ 2024-03-03 17:17 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-03 17:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 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:c0f5b6caff669037444506cb6008a378356ec209

commit r14-9281-gc0f5b6caff669037444506cb6008a378356ec209
Author: Georg-Johann Lay <avr@gjlay.de>
Date:   Sun Mar 3 18:15:58 2024 +0100

    AVR: ad target/114100 - Don't print unused frame pointer adjustments.

    Without -mfuse-add, when fake reg+offset addressing is used, the
    output routines are saving some instructions when the base reg
    is unused after.  This patch adds that optimization for the case
    when the base is the frame pointer and the frame pointer adjustments
    are split away from the move insn by -mfuse-add in .split2.
       Direct usage of reg_unused_after is not possible because that
    function looks at the destination of the current insn, which won't
    work for offsetting the frame pointer in printing PLUS code.
    It can use an extended version of _reg_unused_after though.

    gcc/
            PR target/114100
            * config/avr/avr-protos.h (_reg_unused_after): Remove proto.
            * config/avr/avr.cc (_reg_unused_after): Make static.  And
            add 3rd argument to skip the current insn.
            (reg_unused_after): Adjust call of reg_unused_after.
            (avr_out_plus_1) [AVR_TINY && -mfuse-add >= 2]: Don't output
            unneeded frame pointer adjustments.

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-25 16:32 [Bug target/114100] New: [avr] Inefficient indirect addressing on Reduced Tiny gjl at gcc dot gnu.org
2024-02-25 16:33 ` [Bug target/114100] " gjl at gcc dot gnu.org
2024-02-25 19:29 ` pinskia at gcc dot gnu.org
2024-02-29 19:42 ` cvs-commit at gcc dot gnu.org
2024-03-01  9:15 ` gjl at gcc dot gnu.org
2024-03-02  9:21 ` cvs-commit at gcc dot gnu.org
2024-03-03 17:17 ` cvs-commit 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).