public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/103860] [9/10/11/12 Regression] wrong code at -O3 with -fPIC on x86_64-linux-gnu
Date: Wed, 29 Dec 2021 17:32:23 +0000	[thread overview]
Message-ID: <bug-103860-4-Rz6LRdJHaV@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103860-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This seems to be clearly a shrink-wrapping bug.
Before pro_and_epilogue we have in RTL:
(note 4 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 4 3 2 NOTE_INSN_FUNCTION_BEG)
(insn 3 2 34 2 (set (reg/v:QI 0 ax [orig:84 l ] [84])
        (const_int -1 [0xffffffffffffffff])) "pr103860.c":14:10 83
{*movqi_internal}
     (expr_list:REG_EQUAL (const_int -1 [0xffffffffffffffff])
        (nil)))

(code_label 34 3 6 3 7 (nil) [1 uses])
(note 6 34 7 3 [bb 3] NOTE_INSN_BASIC_BLOCK)
(note 7 6 10 3 NOTE_INSN_DELETED)
(insn 10 7 11 3 (set (reg:CCGOC 17 flags)
        (compare:CCGOC (mem/c:SI (symbol_ref:DI ("d") [flags 0x2]  <var_decl
0x7f8ba5c9ac60 d>) [1 d+0 S4 A32])
            (const_int 0 [0]))) 7 {*cmpsi_ccno_1}
     (nil))
(jump_insn 11 10 13 3 (set (pc)
        (if_then_else (ge (reg:CCGOC 17 flags)
                (const_int 0 [0]))
            (label_ref 16)
            (pc))) 873 {*jcc}
     (int_list:REG_BR_PROB 118111604 (nil))
 -> 16)

(code_label 13 11 12 5 5 (nil) [1 uses])
(note 12 13 52 5 [bb 5] NOTE_INSN_BASIC_BLOCK)
(jump_insn 52 12 53 5 (set (pc)
        (label_ref 13)) 874 {jump}
     (nil)
 -> 13)

(barrier 53 52 16)

(code_label 16 53 17 6 4 (nil) [1 uses])
(note 17 16 19 6 [bb 6] NOTE_INSN_BASIC_BLOCK)
(jump_insn 19 17 20 6 (set (pc)
        (if_then_else (eq (reg:CCGOC 17 flags)
                (const_int 0 [0]))
            (label_ref 27)
            (pc))) "pr103860.c":18:10 873 {*jcc}
     (int_list:REG_BR_PROB 536870916 (nil))

The problem is that shrink-wrapping decides to put the
(insn/f 55 77 56 12 (parallel [
            (set (reg/f:DI 7 sp)
                (plus:DI (reg/f:DI 7 sp)
                    (const_int -8 [0xfffffffffffffff8])))
            (clobber (reg:CC 17 flags))
            (clobber (mem:BLK (scratch) [0  A8]))
        ]) "pr103860.c":12:1 -1
     (expr_list:REG_CFA_ADJUST_CFA (set (reg/f:DI 7 sp)
            (plus:DI (reg/f:DI 7 sp)
                (const_int -8 [0xfffffffffffffff8])))
        (nil)))
instruction on the edge in between bb3 and bb6, but that isn't correct, because
the flags register is live on that edge (set in insn 10, used in insns 11 and
19) and the prologue instruction clobbers it.

So we end up with:
main:
        movl    d(%rip), %edx
        movl    $-1, %eax
        testl   %edx, %edx
        jns     .L12
.L11:
        jmp     .L11
.L12:
        subq    $8, %rsp
.L4:
        je      .L6
        movq    f@GOTPCREL(%rip), %rax
        movl    $0, (%rax)
        movl    $0, 0
        ud2
.L6:
(.palign* and .cfi* directives and useless labels manually elided), which is
wrong, because je .L6 is done depending on whether %rsp was 8 before the
subtration (pretty much never), rather than depending on whether %edx is 0.

  parent reply	other threads:[~2021-12-29 17:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-29 16:08 [Bug tree-optimization/103860] New: " zhendong.su at inf dot ethz.ch
2021-12-29 17:17 ` [Bug rtl-optimization/103860] [9/10/11/12 Regression] " jakub at gcc dot gnu.org
2021-12-29 17:32 ` jakub at gcc dot gnu.org [this message]
2021-12-29 18:10 ` jakub at gcc dot gnu.org
2021-12-29 18:23 ` jakub at gcc dot gnu.org
2021-12-29 19:43 ` segher at gcc dot gnu.org
2021-12-29 19:58 ` jakub at gcc dot gnu.org
2021-12-29 20:30 ` segher at gcc dot gnu.org
2021-12-30 13:24 ` cvs-commit at gcc dot gnu.org
2021-12-30 13:39 ` [Bug rtl-optimization/103860] [9/10/11 " jakub at gcc dot gnu.org
2022-01-04  9:13 ` cvs-commit at gcc dot gnu.org
2022-01-04 13:59 ` rguenth at gcc dot gnu.org
2022-01-24  9:20 ` cvs-commit at gcc dot gnu.org
2022-01-24  9:30 ` [Bug rtl-optimization/103860] [9/10 " jakub at gcc dot gnu.org
2022-05-10  8:22 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:23 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:36 ` jakub 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-103860-4-Rz6LRdJHaV@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).