public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "wilson at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/25130] [4.1/4.2 Regression] miscompilation in GCSE
Date: Tue, 29 Nov 2005 06:10:00 -0000	[thread overview]
Message-ID: <20051129061021.6007.qmail@sourceware.org> (raw)
In-Reply-To: <bug-25130-702@http.gcc.gnu.org/bugzilla/>



------- Comment #3 from wilson at gcc dot gnu dot org  2005-11-29 06:10 -------
This is indeed a gcse problem.  It is a problem with the load motion support.

There are some similarities to PR 24804 here.  We have multiple overlapping
objects on the stack, that have mems with different MEM_EXPR fields, that are
being treated as the same object because they have the same hash code.  This
results in some new RTL being emitted by gcse that has mems with incorrect
MEM_EXPR fields.  This doesn't cause the failure though, and seems to be
harmless for this testcase.  This is potentially a problem for other testcases
though.

The problem happens shortly before the printf call.  We have before gcse
(insn 60 58 61 3 (parallel [
            (set (mem/s/j/c:SI (plus:SI (reg/f:SI 20 frame)
                        (const_int -8 [0xfffffffffffffff8])) [0
clusters.D.1787\._M_impl._M_finish_cur+0 S4 A32])
                (plus:SI (mem/s/j/c:SI (plus:SI (reg/f:SI 20 frame)
                            (const_int -8 [0xfffffffffffffff8])) [0
clusters.D.\1787._M_impl._M_finish_cur+0 S4 A32])
                    (const_int 4 [0x4])))
            (clobber (reg:CC 17 flags))
        ]) 208 {*addsi_1} (nil)
    (nil))
;; End of basic block 3, registers live:
 (nil)

;; Start of basic block 4, registers live: (nil)
(code_label 61 60 62 4 4 "" [1 uses])

(note 62 61 64 4 [bb 4] NOTE_INSN_BASIC_BLOCK)

(insn 64 62 65 4 (set (reg:SI 72 [ clusters.D.1787._M_impl._M_finish_cur ])
        (mem/s/j/c:SI (plus:SI (reg/f:SI 20 frame)
                (const_int -8 [0xfffffffffffffff8])) [0
clusters.D.1787._M_impl\._M_finish_cur+0 S4 A32])) 40 {*movsi_1} (nil)
    (nil))

and after gcse we have
(insn 60 58 124 3 (parallel [
            (set (mem/s/j/c:SI (plus:SI (reg/f:SI 20 frame)
                        (const_int -8 [0xfffffffffffffff8])) [0
clusters.D.1787\._M_impl._M_finish_cur+0 S4 A32])
                (plus:SI (mem/s/j/c:SI (plus:SI (reg/f:SI 20 frame)
                            (const_int -8 [0xfffffffffffffff8])) [0
clusters.D.\1787._M_impl._M_finish_cur+0 S4 A32])
                    (const_int 4 [0x4])))
            (clobber (reg:CC 17 flags))
        ]) 208 {*addsi_1} (nil)
    (nil))

(jump_insn 124 60 125 3 (set (pc)
        (label_ref 61)) -1 (nil)
    (nil))
;; End of basic block 3, registers live:
 (nil)

(barrier 125 124 127)

;; Start of basic block 4, registers live: (nil)
(code_label 127 125 126 4 12 "" [1 uses])

(note 126 127 121 4 [bb 4] NOTE_INSN_BASIC_BLOCK)

(insn 121 126 61 4 (set (reg:SI 79 [ clusters.D.1787._M_impl._M_finish_cur ])
        (mem/s/j:SI (plus:SI (reg/f:SI 20 frame)
                (const_int -8 [0xfffffffffffffff8])) [0
<variable>._M_impl._M_s\tart_node+0 S4 A32])) 40 {*movsi_1} (nil)
    (nil))
;; End of basic block 4, registers live:
 (nil)

;; Start of basic block 5, registers live: (nil)
(code_label 61 121 62 5 4 "" [1 uses])

(note 62 61 65 5 [bb 5] NOTE_INSN_BASIC_BLOCK)

(insn 65 62 66 5 (set (mem:SI (plus:SI (reg/f:SI 7 sp)
                (const_int 8 [0x8])) [0 S4 A32])
        (reg:SI 79 [ clusters.D.1787._M_impl._M_finish_cur ])) 40 {*movsi_1}
(n\il)
    (nil))

For some reason, gcse thought that insn 64 was redundant, and deleted it,
adding a new basic block with a load as compensation code.  This results in reg
79 having the wrong value when we go from the increment to the printf.

I haven't pinpointed an exact cause of the problem.  The gcse algorithmics are
complicated.  I think the underlying failure is that we are adding mems to the
expression table, and adding their load/store insns to the ldst_table.  When we
find a load/store we can't handle, we remove it from the ldst_table.  However,
we never remove entries from the expression table.  Since there are still mems
in the expression table, gcse still tries to optimize them.  And this results
in bad code, because some load/store insns needs fixups when their mems are
optimized, and these fixups do not happen because the load/store insns are no
longer in the ldst_table.  The fixups are supposed to be emitted in
update_ld_motion_stores.


-- 

wilson at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wilson at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25130


  parent reply	other threads:[~2005-11-29  6:10 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-28  1:24 [Bug rtl-optimization/25130] New: 4.1: miscompilation in loop optimization gcc-bugzilla at gcc dot gnu dot org
2005-11-28  2:00 ` [Bug rtl-optimization/25130] [4.1/4.2 Regression] miscompilation in GCSE pinskia at gcc dot gnu dot org
2005-11-29  6:10 ` wilson at gcc dot gnu dot org [this message]
2005-12-16 23:58 ` steven at gcc dot gnu dot org
2005-12-17 11:27 ` steven at gcc dot gnu dot org
2005-12-17 11:31 ` steven at gcc dot gnu dot org
2005-12-17 15:09 ` steven at gcc dot gnu dot org
2005-12-17 15:14 ` steven at gcc dot gnu dot org
2005-12-17 18:24 ` steven at gcc dot gnu dot org
2005-12-18  0:49 ` steven at gcc dot gnu dot org
2005-12-18  1:38 ` steven at gcc dot gnu dot org
2005-12-19 18:33 ` mmitchel at gcc dot gnu dot org
2005-12-21 15:28 ` steven at gcc dot gnu dot org
2005-12-21 15:32 ` steven at gcc dot gnu dot org
2005-12-21 15:45 ` steven at gcc dot gnu dot org
2005-12-27  0:58 ` steven at gcc dot gnu dot org
2006-01-01 17:37 ` steven at gcc dot gnu dot org
2006-01-03  6:20 ` steven at gcc dot gnu dot org
2006-01-03 22:37 ` steven at gcc dot gnu dot org
2006-01-03 22:39 ` steven at gcc dot gnu dot org
2010-06-28 17:50 ` bernds at gcc dot gnu dot org
2010-06-29 22:41 ` bernds at gcc dot gnu dot org
     [not found] <bug-25130-4@http.gcc.gnu.org/bugzilla/>
2011-06-13 12:48 ` jakub at gcc dot gnu.org
2011-12-02 13:04 ` steven 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=20051129061021.6007.qmail@sourceware.org \
    --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).