public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/97968] [9/10/11/12 Regression] Unnecessary mov instruction with comparison and cmov
Date: Wed, 01 Sep 2021 07:50:31 +0000	[thread overview]
Message-ID: <bug-97968-4-UGFTdH6OIJ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97968-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |11.1.0, 8.1.0
      Known to work|                            |7.1.0
     Ever confirmed|0                           |1
          Component|rtl-optimization            |middle-end
           Keywords|                            |ra
   Last reconfirmed|                            |2021-09-01
            Summary|Unnecessary mov instruction |[9/10/11/12 Regression]
                   |with comparison and cmov    |Unnecessary mov instruction
                   |                            |with comparison and cmov
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So looking into this, I think this is a register allocation issue. We produce:
(insn 23 6 2 2 (set (reg:SI 87)
        (reg:SI 5 di [ n ])) "/app/example.cpp":3:1 75 {*movsi_internal}
     (expr_list:REG_DEAD (reg:SI 5 di [ n ])
        (nil)))
(insn 2 23 24 2 (set (reg/v:SI 83 [ n ])
        (reg:SI 87)) "/app/example.cpp":3:1 75 {*movsi_internal}
     (expr_list:REG_DEAD (reg:SI 87)
        (nil)))
(insn 24 2 3 2 (set (reg:SI 88)
        (reg:SI 4 si [ j ])) "/app/example.cpp":3:1 75 {*movsi_internal}
     (expr_list:REG_DEAD (reg:SI 4 si [ j ])
        (nil)))
(note 3 24 4 2 NOTE_INSN_DELETED)
(note 4 3 20 2 NOTE_INSN_FUNCTION_BEG)
(insn 20 4 25 2 (set (reg:CCGC 17 flags)
        (compare:CCGC (reg/v:SI 83 [ n ])
            (reg:SI 88))) "/app/example.cpp":4:18 11 {*cmpsi_1}
     (expr_list:REG_DEAD (reg:SI 88)
        (nil)))
(insn 25 20 22 2 (set (reg:SI 86)
        (const_int 0 [0])) "/app/example.cpp":4:18 75 {*movsi_internal}
     (expr_list:REG_EQUIV (const_int 0 [0])
        (nil)))
(insn 22 25 17 2 (set (reg/v:SI 83 [ n ])
        (if_then_else:SI (gt (reg:CCGC 17 flags)
                (const_int 0 [0]))
            (reg/v:SI 83 [ n ])
            (reg:SI 86))) "/app/example.cpp":4:18 1140 {*movsicc_noc}
     (expr_list:REG_DEAD (reg:SI 86)
        (expr_list:REG_DEAD (reg:CCGC 17 flags)
            (nil))))
(insn 17 22 18 2 (set (reg/i:SI 0 ax)
        (reg/v:SI 83 [ n ])) "/app/example.cpp":5:1 75 {*movsi_internal}
     (expr_list:REG_DEAD (reg/v:SI 83 [ n ])
        (nil)))

But we tie the input to the movsicc_noc to the output early on with reg 83.
that means we select 83 to be ax which means emitting a move early on instead
of selecting 86 as ax and having the second 83 be ax.


Now it looks in GCC 7 we got this before RA:
(insn 26 27 17 2 (set (reg:SI 87 [ <retval> ])
        (if_then_else:SI (gt (reg:CCGC 17 flags)
                (const_int 0 [0]))
            (reg/v:SI 88 [ n ])
            (reg:SI 91))) "/app/example.cpp":4 968 {*movsicc_noc}
     (expr_list:REG_DEAD (reg:SI 91)
        (expr_list:REG_DEAD (reg/v:SI 88 [ n ])
            (expr_list:REG_DEAD (reg:CCGC 17 flags)
                (nil)))))
(insn 17 26 18 2 (set (reg/i:SI 0 ax)
        (reg:SI 87 [ <retval> ])) "/app/example.cpp":5 82 {*movsi_internal}
     (expr_list:REG_DEAD (reg:SI 87 [ <retval> ])
        (nil)))

The change looks like is the way we expand the code from gimple to RTL. In post
GCC 8, we tie right away the return value to the register which holds n and
move  0 into n.

  reply	other threads:[~2021-09-01  7:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 15:19 [Bug rtl-optimization/97968] New: " denis.campredon at gmail dot com
2021-09-01  7:50 ` pinskia at gcc dot gnu.org [this message]
2021-09-19 23:15 ` [Bug middle-end/97968] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
2021-09-19 23:16 ` pinskia at gcc dot gnu.org
2022-01-21 13:25 ` rguenth at gcc dot gnu.org
2022-01-21 15:20 ` denis.campredon at gmail dot com
2022-05-27  9:43 ` [Bug middle-end/97968] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:42 ` jakub at gcc dot gnu.org
2023-07-07 10:38 ` [Bug middle-end/97968] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-13 21:12 ` pinskia at gcc dot gnu.org
2024-03-10 23:11 ` [Bug middle-end/97968] [11 " law at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97968-4-UGFTdH6OIJ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).