public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/107404] [12/13 Regression] Wrong code with -O3 since r12-6416-g037cc0b4a6646cc8
Date: Thu, 03 Nov 2022 09:29:35 +0000	[thread overview]
Message-ID: <bug-107404-4-IeG2UJI79N@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107404-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to rsandifo@gcc.gnu.org from comment #3)
> This is due to the peephole2 added in r12-2640-gf7bf03cf69cc:
> 
> ;; Eliminate a reg-reg mov by inverting the condition of a cmov (#2).
> ;; mov r2,r3; mov r0,r1; dec r0; cmov r0,r2 -> dec r1; mov r0,r3; cmov r0, r1

The "dec" above in fact matches many other instructions, including:

(insn 485 960 737 19 (parallel [
            (set (reg:CCC 17 flags)
                (compare:CCC (plus:DI (reg:DI 43 r15 [orig:157 _138 ] [157])
                        (reg:DI 3 bx [orig:99 _23 ] [99]))
                    (reg:DI 3 bx [orig:99 _23 ] [99])))
            (set (reg:DI 43 r15 [orig:157 _138 ] [157])
                (plus:DI (reg:DI 43 r15 [orig:157 _138 ] [157])
                    (reg:DI 3 bx [orig:99 _23 ] [99])))
        ]) "pr107404.cpp":28:46 413 {*adddi3_cc_overflow_2}
     (nil))


So, the processed sequence is:

bx <- [mem]
r15 <- r8
r15 <- r15 + bx
r15 <- (r15, bx)

and the sequence is converted to:

r8 <- r8 + bx
r15 <- [mem]
r15 <- (r8, r15)

However, the bx register in the first insn is uninitialized.

We can still allow unrelated registers in the "dec" instruction, under the
condition this register is not the one in the removed assignment. So, the
answer to:

> The conditions make sure that the 2<-3 and 0<-1 moves are independent,
> but they don't check what effect the 2<-3 move has on the third
> instruction.  I don't know if the intention was to exclude cases
> where operands 5 and 6 reference operand 2, or whether the intention
> was to cope with those cases where possible.

is that we want to exclude cases where operand 6 references operand 2 (please
note that operand 5 is a duplicate of operand 6).

  parent reply	other threads:[~2022-11-03  9:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26  0:40 [Bug tree-optimization/107404] New: [12/13 Regression] Wrong code with -O3 vsevolod.livinskiy at gmail dot com
2022-10-26  0:59 ` [Bug tree-optimization/107404] " pinskia at gcc dot gnu.org
2022-10-26  1:07 ` pinskia at gcc dot gnu.org
2022-10-26  6:36 ` [Bug tree-optimization/107404] [12/13 Regression] Wrong code with -O3 since r12-6416-g037cc0b4a6646cc8 marxin at gcc dot gnu.org
2022-10-26  6:36 ` marxin at gcc dot gnu.org
2022-10-26  8:58 ` rsandifo at gcc dot gnu.org
2022-10-26  9:05 ` jakub at gcc dot gnu.org
2022-10-26 11:13 ` rsandifo at gcc dot gnu.org
2022-11-03  9:29 ` ubizjak at gmail dot com [this message]
2022-11-03 10:00 ` [Bug target/107404] " ubizjak at gmail dot com
2022-11-03 13:18 ` cvs-commit at gcc dot gnu.org
2022-11-03 16:13 ` cvs-commit at gcc dot gnu.org
2022-11-03 16:18 ` ubizjak at gmail dot com

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-107404-4-IeG2UJI79N@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).