public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting
@ 2011-08-31 11:39 vries at gcc dot gnu.org
  2011-08-31 11:41 ` [Bug rtl-optimization/50249] " vries at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2011-08-31 11:39 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50249
           Summary: ira marks wrong value for inheriting
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vries@gcc.gnu.org


Using an approved-for-commit middle-end patch for bug 43864, I hit the
following
error in ira:

Before ira, insn 320 defines r588, which is used in identical loads insn 321
and
insn 329.

10.cc.188r.asmcons:
...
(insn 320 318 321 20 (set (reg/f:SI 588)
        (plus:SI (reg/f:SI 166)
            (const_int -12))) 5 {*thumb1_addsi3}
     (nil))

(insn 321 320 322 20 (set (reg:SI 379)
        (mem:SI (reg/f:SI 588))) 177 {*thumb1_movsi_insn}
     (nil))

(insn 322 321 326 20 (set (mem/s/f:SI (plus:SI (reg/f:SI 329)
        (reg:SI 379)))
        (reg/f:SI 170)) 177 {*thumb1_movsi_insn}
     (expr_list:REG_DEAD (reg:SI 379)
        (nil)))

(insn 326 322 329 20 (set (mem/s/c:SI (plus:SI (reg/f:SI 329)
                (const_int 4)))
        (reg:SI 338)) 177 {*thumb1_movsi_insn}
     (expr_list:REG_DEAD (reg:SI 338)
        (nil)))

(insn 329 326 330 20 (set (reg:SI 386)
        (mem:SI (reg/f:SI 588) )) 177 {*thumb1_movsi_insn}
     (nil))

(insn 330 329 331 20 (set (reg:SI 385)
        (plus:SI (reg/f:SI 329)
            (reg:SI 386))) 5 {*thumb1_addsi3}
     (expr_list:REG_DEAD (reg:SI 386)
        (nil)))
...


After ira, r588 is defined by insn 1140, insn 1141 an insn 320 in r10.
It is then copied to r1 by insn 1143, before being used in the first load,
insn 1144. This first load also overwrites r1.
The second load, insn 1146 however uses r1 as if is was still a copy of r10.

10.cc.191r.ira:
...
(insn 1140 1139 1141 20 (set (reg/f:SI 10 sl [588])
        (reg:SI 1 r1)) 177 {*thumb1_movsi_insn}
     (nil))

(insn 1141 1140 320 20 (set (reg:SI 2 r2)
        (const_int -12)) 177 {*thumb1_movsi_insn}
     (nil))

(insn 320 1141 321 20 (set (reg/f:SI 10 sl [588])
        (plus:SI (reg/f:SI 10 sl [588])
            (reg:SI 2 r2))) 5 {*thumb1_addsi3}
     (nil))

(note 321 320 1145 20 NOTE_INSN_DELETED)

(insn 1145 321 1142 20 (set (reg:SI 0 r0)
        (mem/c:SI (plus:SI (reg/f:SI 13 sp)
                (const_int 12))))
      177 {*thumb1_movsi_insn}
     (nil))

(insn 1142 1145 1143 20 (set (reg:SI 2 r2)
        (plus:SI (reg/f:SI 13 sp)
            (const_int 336))) 5 {*thumb1_addsi3}
     (nil))

(insn 1143 1142 1144 20 (set (reg:SI 1 r1)
        (reg/f:SI 10 sl [588])) 177 {*thumb1_movsi_insn}
     (nil))

(insn 1144 1143 322 20 (set (reg:SI 1 r1)
        (mem:SI (reg:SI 1 r1)))
      177 {*thumb1_movsi_insn}
     (nil))

(insn 322 1144 326 20 (set (mem/s/f:SI (plus:SI (reg:SI 2 r2)
                (reg:SI 1 r1)))
        (reg:SI 0 r0)) 177 {*thumb1_movsi_insn}
     (nil))

(insn 326 322 329 20 (set (mem/s/c:SI (plus:SI (reg/f:SI 13 sp)
            (const_int 340)))
        (reg:SI 3 r3 [338])) 177 {*thumb1_movsi_insn}
     (nil))

(note 329 326 1146 20 NOTE_INSN_DELETED)

(insn 1146 329 330 20 (set (reg:SI 1 r1)
        (mem:SI (reg:SI 1 r1)))
      177 {*thumb1_movsi_insn}
     (nil))

(insn 330 1146 332 20 (set (reg:SI 0 r0 [385])
        (plus:SI (reg:SI 2 r2)
            (reg:SI 1 r1))) 5 {*thumb1_addsi3}
     (nil))
...

The reloads for insn 322 are visible in the ira dump. Reload 1 is the copy from
r10 to r1. Reload 2 is the first load.

10.cc.191r.ira:
...
Reloads for insn # 322
Reload 0: reload_in (SI) = (plus:SI (reg/f:SI 13 sp)
                                                    (const_int 336))
        LO_REGS, RELOAD_FOR_OPERAND_ADDRESS (opnum = 0)
        reload_in_reg: (plus:SI (reg/f:SI 13 sp)
                                                    (const_int 336))
        reload_reg_rtx: (reg:SI 2 r2)
Reload 1: reload_in (SI) = (reg/f:SI 10 sl [588])
        BASE_REGS, RELOAD_FOR_OPERAND_ADDRESS (opnum = 0)
        reload_in_reg: (reg/f:SI 10 sl [588])
        reload_reg_rtx: (reg:SI 1 r1)
Reload 2: reload_in (SI) = (mem:SI (reg/f:SI 10 sl [588]))
        LO_REGS, RELOAD_FOR_OPERAND_ADDRESS (opnum = 0), can't combine
    reload_in_reg: (reg:SI 379)
        reload_reg_rtx: (reg:SI 1 r1)
Reload 3: LO_REGS, RELOAD_FOR_OPERAND_ADDRESS (opnum = 0), optional, can't
          combine, secondary_reload_p
Reload 4: reload_out (SI) = (mem/s/f:SI (plus:SI (plus:SI (reg/f:SI 13 sp)
                                                            (const_int 336))
                                                        (reg:SI 379 )))
    NO_REGS, RELOAD_FOR_OUTPUT (opnum = 0), optional
        reload_out_reg: (mem/s/f:SI (plus:SI (plus:SI (reg/f:SI 13 sp)
                                                        (const_int 336))
                                                        (reg:SI 379)))
        secondary_out_reload = 3
Reload 5: reload_in (SI) = (reg/f:SI 170)
        LO_REGS, RELOAD_FOR_INPUT (opnum = 1)
        reload_in_reg: (reg/f:SI 170)
        reload_reg_rtx: (reg:SI 0 r0)
...

in emit_reload_insns, ira determines which reloads can be inherited by later
instructions, by testing reload_reg_reaches_end_p (and
reload_regs_reach_end_p).
These tests return true for both reload 1 and reload 2, since they call the
functions with the same arguments.  It seems that the functions
mark_reload_reg_in_use and reload_reg_reaches_end_p and the underlying 
adminstration do not distinguish between the 2 reloads. They have the same
regno, opnum, type and mode.
So we end up setting reg_reloaded_contents twice, once for each reload. Since
we
do this in reload_order, we first handle reload 2 and then reload 1. So the
effective reg_reloaded_contents is the one of reload 1, while it should be the 
one of reload 2.


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

* [Bug rtl-optimization/50249] ira marks wrong value for inheriting
  2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
@ 2011-08-31 11:41 ` vries at gcc dot gnu.org
  2011-08-31 11:42 ` vries at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2011-08-31 11:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from vries at gcc dot gnu.org 2011-08-31 11:39:32 UTC ---
Created attachment 25150
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25150
test case

testcase reduced from
libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/10.cc.

to reproduce:
$ arm-none-linux-gnueabi-g++ -g -O2 ./10.cc -mthumb -S -fdump-rtl-all-all


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

* [Bug rtl-optimization/50249] ira marks wrong value for inheriting
  2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
  2011-08-31 11:41 ` [Bug rtl-optimization/50249] " vries at gcc dot gnu.org
@ 2011-08-31 11:42 ` vries at gcc dot gnu.org
  2011-08-31 11:44 ` vries at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2011-08-31 11:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from vries at gcc dot gnu.org 2011-08-31 11:40:19 UTC ---
Created attachment 25151
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25151
dump before ira


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

* [Bug rtl-optimization/50249] ira marks wrong value for inheriting
  2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
  2011-08-31 11:41 ` [Bug rtl-optimization/50249] " vries at gcc dot gnu.org
  2011-08-31 11:42 ` vries at gcc dot gnu.org
@ 2011-08-31 11:44 ` vries at gcc dot gnu.org
  2011-08-31 11:57 ` vries at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2011-08-31 11:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from vries at gcc dot gnu.org 2011-08-31 11:40:47 UTC ---
Created attachment 25152
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25152
dump of ira


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

* [Bug rtl-optimization/50249] ira marks wrong value for inheriting
  2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-08-31 11:44 ` vries at gcc dot gnu.org
@ 2011-08-31 11:57 ` vries at gcc dot gnu.org
  2011-08-31 12:42 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2011-08-31 11:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from vries at gcc dot gnu.org 2011-08-31 11:52:12 UTC ---
Created attachment 25153
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25153
compiler patch necessary to trigger the problem

Attached patch was used on top of r178259, and build with configure as reported
by gcc -v:
...
$ ./arm-none-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=./install/bin/arm-none-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/scratch/vries/b5/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/install/bin/../libexec/gcc/arm-none-linux-gnueabi/4.7.0/lto-wrapper
Target: arm-none-linux-gnueabi
Configured with:
/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/src/gcc-mainline/configure
--build=i686-pc-linux-gnu --host=i686-pc-linux-gnu
--target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap
--disable-libssp --disable-libstdcxx-pch --enable-checking=yes,rtl
--with-gnu-as --with-gnu-ld --enable-languages=c,c++ --enable-shared
--enable-lto --enable-symvers=gnu --enable-__cxa_atexit --disable-nls
--prefix=/opt/codesourcery
--with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc
--with-build-sysroot=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/install/arm-none-linux-gnueabi/libc
--with-gmp=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/obj/host-libs-mainline-0-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr
--with-mpfr=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/obj/host-libs-mainline-0-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr
--with-mpc=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/obj/host-libs-mainline-0-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr
--with-ppl=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/obj/host-libs-mainline-0-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm'
--with-cloog=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/obj/host-libs-mainline-0-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr
--with-libelf=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/obj/host-libs-mainline-0-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr
--disable-libgomp --enable-poison-system-directories
--with-build-time-tools=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/install/arm-none-linux-gnueabi/bin
--with-build-time-tools=/home/vries/local/pr43864.38.all-fsf-mainline-arm-none-linux-gnueabi.cfg/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.7.0 20110829 (experimental) (GCC) 
...


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

* [Bug rtl-optimization/50249] ira marks wrong value for inheriting
  2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-08-31 11:57 ` vries at gcc dot gnu.org
@ 2011-08-31 12:42 ` vries at gcc dot gnu.org
  2011-09-07  2:58 ` mkuvyrkov at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2011-08-31 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from vries at gcc dot gnu.org 2011-08-31 12:14:12 UTC ---
I bisected the failure to r172389, but to me that looks more like a trigger
than a cause:
...
2011-04-13  Vladimir Makarov  <vmakarov@redhat.com>

    PR rtl-optimization/48455
    * ira-costs.c (find_costs_and_classes): Use i_mem_cost instead of
    `temp_costs->mem_cost'.
...


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

* [Bug rtl-optimization/50249] ira marks wrong value for inheriting
  2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2011-08-31 12:42 ` vries at gcc dot gnu.org
@ 2011-09-07  2:58 ` mkuvyrkov at gcc dot gnu.org
  2011-09-27 15:44 ` bernds at gcc dot gnu.org
  2011-09-27 16:11 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: mkuvyrkov at gcc dot gnu.org @ 2011-09-07  2:58 UTC (permalink / raw)
  To: gcc-bugs

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

Maxim Kuvyrkov <mkuvyrkov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mkuvyrkov at gcc dot
                   |                            |gnu.org

--- Comment #6 from Maxim Kuvyrkov <mkuvyrkov at gcc dot gnu.org> 2011-09-07 02:55:56 UTC ---
Vladimir,

Does the analysis done by Tom sound correct (see
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50249#c0) ?

To fix this RA bug, should we teach IRA to distinguish between Reload 1 and
Reload 2, or make sure that the reloads are evaluated in correct order, or
something else?

Thank you.


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

* [Bug rtl-optimization/50249] ira marks wrong value for inheriting
  2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2011-09-07  2:58 ` mkuvyrkov at gcc dot gnu.org
@ 2011-09-27 15:44 ` bernds at gcc dot gnu.org
  2011-09-27 16:11 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: bernds at gcc dot gnu.org @ 2011-09-27 15:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Bernd Schmidt <bernds at gcc dot gnu.org> 2011-09-27 14:55:16 UTC ---
Author: bernds
Date: Tue Sep 27 14:55:11 2011
New Revision: 179272

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179272
Log:
    PR rtl-optimization/50249
    * reload1.c (reload_reg_reaches_end_p): Accept a reloadnum argument
    instead of opnum and type.  All callers changed.  Remove useless
    declaration.
    Search forward for other reloads of the same type for the same operand
    using the same register; if any are found, return false.
    (reload_regs_reach_end_p): Same argument changes; all callers changed.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/reload1.c


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

* [Bug rtl-optimization/50249] ira marks wrong value for inheriting
  2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2011-09-27 15:44 ` bernds at gcc dot gnu.org
@ 2011-09-27 16:11 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2011-09-27 16:11 UTC (permalink / raw)
  To: gcc-bugs

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

vries at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
         AssignedTo|unassigned at gcc dot       |bernds at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #8 from vries at gcc dot gnu.org 2011-09-27 15:34:44 UTC ---
Bernd committed patch, marking fixed.


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

end of thread, other threads:[~2011-09-27 15:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-31 11:39 [Bug rtl-optimization/50249] New: ira marks wrong value for inheriting vries at gcc dot gnu.org
2011-08-31 11:41 ` [Bug rtl-optimization/50249] " vries at gcc dot gnu.org
2011-08-31 11:42 ` vries at gcc dot gnu.org
2011-08-31 11:44 ` vries at gcc dot gnu.org
2011-08-31 11:57 ` vries at gcc dot gnu.org
2011-08-31 12:42 ` vries at gcc dot gnu.org
2011-09-07  2:58 ` mkuvyrkov at gcc dot gnu.org
2011-09-27 15:44 ` bernds at gcc dot gnu.org
2011-09-27 16:11 ` vries 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).