Bug 28982 - Incorrect reloading of automodification expressions
Summary: Incorrect reloading of automodification expressions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: rsandifo@gcc.gnu.org
URL:
Keywords: ice-on-valid-code, wrong-code
Depends on:
Blocks:
 
Reported: 2006-09-08 08:35 UTC by rsandifo@gcc.gnu.org
Modified: 2006-09-13 06:32 UTC (History)
2 users (show)

See Also:
Host:
Target: arm-none-linux-gnueabi
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Testcase (420 bytes, text/plain)
2006-09-08 08:37 UTC, rsandifo@gcc.gnu.org
Details

Note You need to log in before you can comment on or make changes to this bug.
Description rsandifo@gcc.gnu.org 2006-09-08 08:35:08 UTC
If reload decides to create an automodification reload (POST_MODIFY, etc.),
inc_for_reload will not deal correctly with any reloads for the base and
index registers.  This problem is related to:

2006-03-29  Paul Brook  <paul@codesourcery.com>

	* reload1.c (choose_reload_regs): Check for all RTX_AUTOINC operators.
	(inc_for_reload): Handle PRE_MODIFY and POST_MODIFY addresses.

...before which, any attempt to create PRE_MODIFY and POST_MODIFY
reloads would cause an ICE.

The symptoms are twofold.  If an index register is reloaded from
a spill slot, you'll get an ICE such as:

error: unrecognizable insn:
(insn 481 479 482 3 (set (reg:SI 1 r1)
        (plus:SI (reg:SI 1 r1)
            (mem/c:SI (plus:SI (reg/f:SI 13 sp)
                    (const_int 176 [0xb0])) [25 pretmp.56+0 S4 A32]))) -1 (nil)
    (nil))

If the base register is reloaded from a spill slot, the modification
will be lost.

There is a third problem.  Suppose there's a RELOAD_FOR_INPUT reload (A)
that reloads a PRE_MODIFY or POST_MODIFY and a reload (B) that reloads
the index of that PRE_MODIFY or POST_MODIFY.  (B) will then be a
RELOAD_FOR_INPUT_ADDRESS.  This is incorrect, as inc_for_reload might
only read the index _after_ setting (A)'s reload register, so (B)'s
reload register must live longer than a normal RELOAD_FOR_INPUT_ADDRESS
is required to.

Because Paul's patch is 4.2-only, and because POST_MODIFY reloads
would ICE before his patch, the bug is only a 4.2 regression in
the sense that an ice-on-valid-code bug can now sometimes be a
more serious wrong-code bug.
Comment 1 rsandifo@gcc.gnu.org 2006-09-08 08:37:46 UTC
Created attachment 12211 [details]
Testcase

This brute-force test fails with -O2 -mfloat-abi=softfp.
Comment 2 rsandifo@gcc.gnu.org 2006-09-13 06:31:11 UTC
Subject: Bug 28982

Author: rsandifo
Date: Wed Sep 13 06:30:59 2006
New Revision: 116919

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116919
Log:
gcc/
	PR rtl-optimization/28982
	* reload.c (find_reloads_address_1): Use RELOAD_OTHER for the
	index of a PRE_MODIFY or POST_MODIFY address.
	* reload1.c (inc_for_reload): Use find_replacement on the original
	base and index registers.

gcc/testsuite/
	PR rtl-optimization/28982
	* gcc.c-torture/execute/pr28982a.c: New test.
	* gcc.c-torture/execute/pr28982b.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr28982a.c
    trunk/gcc/testsuite/gcc.c-torture/execute/pr28982b.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/reload.c
    trunk/gcc/reload1.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 rsandifo@gcc.gnu.org 2006-09-13 06:32:48 UTC
Patch applied