Bug 24750

Summary: [4.1 regression] global-alloc (reload) trips over own confusion for unexpected addressing modes
Product: gcc Reporter: Hans-Peter Nilsson <hp>
Component: middle-endAssignee: Hans-Peter Nilsson <hp>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs
Priority: P3 Keywords: ice-on-valid-code, patch
Version: 4.1.0   
Target Milestone: 4.1.0   
Host: x86_64-unknown-linux-gnu Target: cris-axis-elf
Build: Known to work:
Known to fail: Last reconfirmed: 2005-11-09 02:23:16
Attachments: Compile with -Os

Description Hans-Peter Nilsson 2005-11-09 02:10:57 UTC
The test-case to be attached "works" with 4.0.2.
For revision 106478 of "Fri Nov  4 03:11:30 UTC 2005", I get
/tmp/st18.c: In function âfâ:
/tmp/st18.c:73: error: insn does not satisfy its constraints:
(insn:QI 84 518 85 9 (set (cc0)
        (mem:QI (plus:SI (sign_extend:SI (reg:HI 10 r10))
                (reg:SI 1 r1)) [0 S1 A8])) 3 {tstqi} (nil)
    (nil))
/tmp/st18.c:73: internal compiler error: in reload_cse_simplify_operands, at postreload.c:393

It looks like reload trips over its confusion from reloading this insn:
(insn:QI 84 83 85 9 (set (cc0)
        (mem:QI (plus:SI (sign_extend:SI (mem:HI (post_inc:SI (reg/f:SI 12 r12 [orig:58 ivtmp.158 ] [58])) [2 S2 A8]))
                (reg/v/f:SI 16 srp [orig:68 c0 ] [68])) [0 S1 A8])) 3 {tstqi} (nil)
    (expr_list:REG_INC (reg/f:SI 12 r12 [orig:58 ivtmp.158 ] [58])
        (nil)))
where (reg:SI 16), "srp" is not valid in an address.
Comment 1 Hans-Peter Nilsson 2005-11-09 02:23:16 UTC
I should mention that
(plus:SI (sign_extend:SI (reg:HI 10 r10)) (reg:SI 1 r1))
is not a valid address, but
(plus:SI (sign_extend:SI (sign_extend:SI (mem:HI (post_inc:SI (reg/f:SI 12 r12)))))
         (reg:SI 1 r1))
is; the problem seems related to reload choosing to reload inner MEM expressions
replacing them with REG even though that's not needed and sometimes
(i.e. for some targets) not valid.  The "real" need is just to reload SRP.
Or perhaps that SRP was chosen as part of an address in the first place.
Or both.  Or maybe we should just bail out and declare LEGITIMIZE_RELOAD_ADDRESS
as a sometimes actually *necessary* macro rather than just for optimization, for
certain cases, like when a MEM inside an expression can't be validly replaced
with a REG.
Comment 2 Hans-Peter Nilsson 2005-11-09 02:30:53 UTC
Created attachment 10182 [details]
Compile with -Os

Note the brittleness of the test-case.  Apparently there's a bug, PR 20656,
causing the empty, seemingly-reducible, sometimes redundant for-loops aren't gone when RTL is generated and can't be replaced with a single assignment without causing the test-case to PASS.  For example,
the "for (i = 1; i <= u0; i++) { }" loop can't be removed.
Comment 3 Hans-Peter Nilsson 2005-11-09 03:17:46 UTC
Pinskia brings to attention that the loop removal thingy is more related to PR 23361.
Comment 4 Hans-Peter Nilsson 2005-11-09 03:24:05 UTC
And to PR 18527.
Comment 5 Hans-Peter Nilsson 2005-11-09 03:47:32 UTC
And PR 20656.
Comment 6 Hans-Peter Nilsson 2005-11-10 00:47:00 UTC
A much shorter, but CRIS-specific testcase, that fails for the same reason but
in a slightly different way is:

int
f (short *a, char *y)
{  
  asm ("" : : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
  return y[*a];
}
Comment 7 Hans-Peter Nilsson 2005-11-10 01:23:57 UTC
The "slightly different way" being:
/tmp/st20.c: In function âfâ:
/tmp/st20.c:6: internal compiler error: output_operand: unexpected index-type in cris_print_index
Comment 8 Janis Johnson 2005-11-10 23:40:11 UTC
A regression hunt using a cris-axis-elf cross compiler on powerpc-linux
identified this patch:

r95823 | hp | 2005-03-03 03:53:29 +0000 (Thu, 03 Mar 2005) | 40 lines

http://gcc.gnu.org/viewcvs?view=rev&rev=95823
Comment 9 Hans-Peter Nilsson 2005-11-11 01:06:34 UTC
Subject: Re:  [4.1 regression] global-alloc (reload)
 trips over own confusion for unexpected addressing modes

On Thu, 10 Nov 2005, janis at gcc dot gnu dot org wrote:
> ------- Comment #8 from janis at gcc dot gnu dot org  2005-11-10 23:40 -------
> A regression hunt using a cris-axis-elf cross compiler on powerpc-linux
> identified this patch:
>
> r95823 | hp | 2005-03-03 03:53:29 +0000 (Thu, 03 Mar 2005) | 40 lines
>
> http://gcc.gnu.org/viewcvs?view=rev&rev=95823

(Wherein SRP and MOF are first described as actual registers.)
Yeah, well, sort-of.  Cause of exposure, but not the bug.
Nice to know that the reghunt scripts work, though!

brgds, H-P
Comment 10 Hans-Peter Nilsson 2005-11-11 06:03:06 UTC
Patch at <URL:http://gcc.gnu.org/ml/gcc-patches/2005-11/msg00790.html>.
Comment 11 Hans-Peter Nilsson 2005-11-11 23:17:20 UTC
Subject: Bug 24750

Author: hp
Date: Fri Nov 11 23:17:16 2005
New Revision: 106804

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106804
Log:
	PR middle-end/24750
	* reload.c (find_reloads_address_1) <case TRUNCATE, SIGN_EXTEND,
	ZERO_EXTEND>: New cases.

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

Comment 12 Hans-Peter Nilsson 2005-11-11 23:19:29 UTC
Subject: Bug 24750

Author: hp
Date: Fri Nov 11 23:19:26 2005
New Revision: 106806

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106806
Log:
	PR middle-end/24750
	* gcc.dg/torture/pr24750-1.c, gcc.target/cris/torture/pr24750-2.c:
        New tests.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr24750-1.c
    trunk/gcc/testsuite/gcc.target/cris/torture/pr24750-2.c
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 13 Hans-Peter Nilsson 2005-11-12 00:36:27 UTC
gah
Comment 14 Hans-Peter Nilsson 2005-11-19 21:56:22 UTC
Subject: Bug 24750

Author: hp
Date: Sat Nov 19 21:56:17 2005
New Revision: 107231

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107231
Log:
	PR middle-end/24912
	PR middle-end/24750
	* reload.c (find_reloads_address_1): Mention dependency on
	gen_reload.
	* reload1.c (gen_reload): For IN with an unary operation, try
	moving inner expression to OUT if trivial SET is not valid.
	Confirm that the result is valid.  Move common code block into...
	(emit_insn_if_valid_for_reload): New function.

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

Comment 15 Hans-Peter Nilsson 2005-11-19 21:59:53 UTC
Subject: Bug 24750

Author: hp
Date: Sat Nov 19 21:59:48 2005
New Revision: 107233

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107233
Log:
	PR middle-end/24912
	PR middle-end/24750
	* reload.c (find_reloads_address_1): Mention dependency on
	gen_reload.
	* reload1.c (gen_reload): For IN with an unary operation, try
	moving inner expression to OUT if trivial SET is not valid.
	Confirm that the result is valid.  Move common code block into...
	(emit_insn_if_valid_for_reload): New function.

Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/reload.c
    branches/gcc-4_1-branch/gcc/reload1.c