Bug 44031 - [4.4/4.5 Regression] ice in subst_reloads, at reload.c:6327
Summary: [4.4/4.5 Regression] ice in subst_reloads, at reload.c:6327
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.6.0
: P2 normal
Target Milestone: 4.4.6
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 44816 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-05-07 21:03 UTC by John Regehr
Modified: 2011-02-02 18:09 UTC (History)
7 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work: 4.6.0
Known to fail: 4.5.3
Last reconfirmed: 2010-07-24 23:53:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2010-05-07 21:03:24 UTC
[regehr@bethe tmp600]$ current-gcc -v
Using built-in specs.
COLLECT_GCC=current-gcc
COLLECT_LTO_WRAPPER=/uusoc/exports/scratch/regehr/z/compiler-install/gcc-r159144-install/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --with-libelf=/usr/local --enable-lto --prefix=/home/regehr/z/compiler-install/gcc-r159144-install --program-prefix=r159144- --enable-languages=c,c++
Thread model: posix
gcc version 4.6.0 20100507 (experimental) (GCC) 

[regehr@bethe tmp600]$ current-gcc -O -c small.c         

small.c: In function 'int321':
small.c:35:1: internal compiler error: in subst_reloads, at reload.c:6327
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

[regehr@bethe tmp600]$ cat small.c

typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;

static uint32_t
safe_add_func_uint32_t_u_u (uint32_t ui1, uint32_t ui2)
{
  return ui1 + ui2;
}

static uint64_t
safe_div_func_uint64_t_u_u (uint64_t ui1, uint32_t ui2)
{
  return ui2 ? : (ui1 / ui2);
}

uint8_t g_55;
uint8_t *g_73 = &g_55;
uint8_t **g_332 = &g_73;

int func_38(uint8_t *,int);
int func_8(int);

int int321 (void)
{
  uint8_t l_26[4];
  uint8_t *l_238 = &l_26[2];
  uint8_t l_400;
  l_400 &=
    func_38 (&l_26[3],
	     safe_add_func_uint32_t_u_u (safe_div_func_uint64_t_u_u
					 (1, **g_332),
					 *l_238) >= *l_238 < func_8 (0)), 1;
  return 0;
}
Comment 1 H.J. Lu 2010-05-08 00:35:54 UTC
It failed with gcc 4.4.3 and 4.5.0.
Comment 2 H.J. Lu 2010-05-08 00:40:01 UTC
It is caused by revision 152533:

http://gcc.gnu.org/ml/gcc-cvs/2009-10/msg00182.html
Comment 3 Vladimir Makarov 2010-05-10 15:22:36 UTC
> It is caused by revision 152533:
> 
> http://gcc.gnu.org/ml/gcc-cvs/2009-10/msg00182.html
> 

If it is so, the patch triggered some reload bug IMO.  The patch itself was very safe because it resulted in creation of additional conflicts.

I hope that Jeff Law's work on new reload will fix it when it is in 4.6 finally.  Otherwise, we should work on this PR.
Comment 4 Jeffrey A. Law 2010-05-11 05:31:04 UTC
I doubt my work will make a significant difference for this test.

We're trying to reload an insn which matches:


(define_insn "*add<mode>3_cconly_overflow"
  [(set (reg:CCC FLAGS_REG)
        (compare:CCC
          (plus:SWI
            (match_operand:SWI 1 "nonimmediate_operand" "%0")
            (match_operand:SWI 2 "<general_operand>" "<r><i>m"))
          (match_dup 1)))
   (clobber (match_scratch:SWI 0 "=<r>"))]
  "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
  "add{<imodesuffix>}\t{%2, %0|%0, %2}"
  [(set_attr "type" "alu")
   (set_attr "mode" "<MODE>")])

(gdb) p debug_reload()
Reload 0: reload_in (SI) = (reg:SI 6 bp)
	reload_out (SI) = (scratch:SI)
	GENERAL_REGS, RELOAD_OTHER (opnum = 0), can't combine
	reload_in_reg: (subreg:SI (reg:DI 6 bp [orig:66 D.2764 ] [66]) 0)
	reload_out_reg: (scratch:SI)
$14 = void
(gdb) p debug_rtx (insn)
(insn 25 24 26 5 j.c:26 (parallel [
            (set (reg:CCC 17 flags)
                (compare:CCC (plus:SI (subreg:SI (reg:DI 6 bp [orig:66 D.2764 ] [66]) 0)
                        (reg:SI 3 bx [orig:58 D.2737 ] [58]))
                    (subreg:SI (reg:DI 6 bp [orig:66 D.2764 ] [66]) 0)))
            (clobber (scratch:SI))
        ]) 316 {*addsi3_cconly_overflow} (expr_list:REG_DEAD (reg:DI 6 bp [orig:66 D.2764 ] [66])
        (expr_list:REG_DEAD (reg:SI 3 bx [orig:58 D.2737 ] [58])
            (nil))))

I think the only way to satisfy this reload is to allocate the scratch to (subreg: SI (reg:DI 6))  I have no clue why reload doesn't do that.  
Comment 5 Uroš Bizjak 2010-07-25 18:06:47 UTC
*** Bug 44816 has been marked as a duplicate of this bug. ***
Comment 6 Uroš Bizjak 2010-08-01 11:41:08 UTC
FYI, following shoot-in-the-dark patch didn't help, but I guess it is needed together with some further reload surgery:

Index: gensupport.c
===================================================================
--- gensupport.c	(revision 162794)
+++ gensupport.c	(working copy)
@@ -1050,7 +1050,7 @@ static const struct std_pred_table std_p
   {"address_operand", true, true, {SUBREG, REG, MEM, PLUS, MINUS, MULT}},
   {"register_operand", false, false, {SUBREG, REG}},
   {"pmode_register_operand", true, false, {SUBREG, REG}},
-  {"scratch_operand", false, false, {SCRATCH, REG}},
+  {"scratch_operand", false, false, {SCRATCH, SUBREG, REG}},
   {"immediate_operand", false, true, {UNKNOWN}},
   {"const_int_operand", false, false, {CONST_INT}},
   {"const_double_operand", false, false, {CONST_INT, CONST_DOUBLE}},
Comment 7 Eric Botcazou 2011-01-26 18:13:17 UTC
Works on the mainline, still fails on the 4.5 branch.
Comment 8 Jeffrey A. Law 2011-01-26 22:11:55 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/26/11 11:14, ebotcazou at gcc dot gnu.org wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44031
> 
> Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |ebotcazou at gcc dot
>                    |                            |gnu.org
>       Known to work|                            |4.6.0
>    Target Milestone|4.6.0                       |4.4.6
>             Summary|[4.4/4.5/4.6 Regression]    |[4.4/4.5 Regression] ice in
>                    |ice in subst_reloads, at    |subst_reloads, at
>                    |reload.c:6327               |reload.c:6327
>       Known to fail|                            |4.5.3
> 
> --- Comment #7 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2011-01-26 18:13:17 UTC ---
> Works on the mainline, still fails on the 4.5 branch.
FWIW, I have no idea which change might have fixed it on the trunk; more
likely than not it was by accident rather than by design.  As such I
doubt there's a particular patch that could be pulled from the trunk and
applied to the 4.5 branch to resolve this issue.

jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNQJwdAAoJEBRtltQi2kC7XRoH/RSyn/+awVJ01vTwYqGu/lZm
fRED3JruXqXvg7KH2xdbL9I/BEHczNvC3YzjFJvb+RjD1MxHt4+7AmPkMMkJJPPu
NoPL5iNGitLfok2Sy2YNgOKEr7t6MW0fpbcpmhx2tRk7tySsm6iWlo1Yh0ruu4rH
XDROh1n8oRE1V+ERFlYhJtc6sqnu4Ma1nHQ57pZeUvd53VSCHpnKF/E3hsDUyh5O
gwkWN0E+zgREQnxGGMGqbcS4BuUHwvVdsCtvVb9SSWkdbwXdPtAdxH0c/7Irbh0E
iBYU/8oTh9RY/Q6fbZfNnJn1YVGGWNHEbFRYP32ZriazIAwjHHbky79i6CuHgSE=
=Zwj2
-----END PGP SIGNATURE-----
Comment 9 Mikael Pettersson 2011-01-28 15:02:42 UTC
This test case stopped failing on 4.6 with r162726:

Author: bernds
Date: Fri Jul 30 23:50:00 2010
New Revision: 162726

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162726
Log:
	* rtlanal.c (simplify_subreg_regno): Don't treat
	HARD_FRAME_POINTER_REGNUM specially.

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

See also http://gcc.gnu.org/ml/gcc-patches/2010-07/msg00756.html
Comment 10 Mikael Pettersson 2011-01-28 18:28:11 UTC
Backporting r162726 to 4.5.2 and 4.4.5 prevents the ICE there too.
Comment 11 Jeffrey A. Law 2011-01-28 18:42:34 UTC
The patch Mikael references removes some bogus code which prevents simplification of a subreg of the frame pointer which was causing some problems for the ARM.  This case (x86) shows the same failing behaviour, we have a subreg of the frame pointer which triggers a reload we're ultimately unable to handle.

I'm going to go ahead and mark this as resolved since I believe Bernd nailed it which is reinforced by Mikael's comments that backporting that fix to the 4.5 and 4.4 branches fixes the problem on the branches as well.
Comment 12 Jeffrey A. Law 2011-01-28 18:43:27 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/28/11 11:28, mikpe at it dot uu.se wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44031
> 
> --- Comment #10 from Mikael Pettersson <mikpe at it dot uu.se> 2011-01-28 18:28:11 UTC ---
> Backporting r162726 to 4.5.2 and 4.4.5 prevents the ICE there too.
Thanks for verifiying this.  That, in my mind seals the deal.


jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNQw5FAAoJEBRtltQi2kC7D3cH/jgVewbZnt4E34iQ2omhb0js
rmeyyJJslfr7WT2meajockBImFP/47qIDSX2e8f0wwXW8uQSBQ0FG7RLMQRipOE2
oH6reoXzLve1PFaRmtkKJ7+vcdEwGGf81YZnmBWR0cnqlecG1r3siTGlv+jHpKnp
Xa/Q7JWP62aQe6yBcEbOC9IhNlFdx9dci7GrGB13Le8xvpFFjOiUw+nOP5E7pQHC
El2IyPqt0wKdZraCcG/sroippAUjts1pL0otxP03EYgqHHVLGdBsFZm2H0ArhJha
IK9SXqI0WBI3m5MNRKn/51qAMVZg/7FNUKQ4/kuha/7aGvvG0+H7btU7dp/nlqM=
=Zdmq
-----END PGP SIGNATURE-----
Comment 13 Eric Botcazou 2011-01-31 10:45:23 UTC
Author: ebotcazou
Date: Mon Jan 31 10:45:20 2011
New Revision: 169433

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169433
Log:
	PR rtl-optimization/44031
	* gcc.c-torture/compile/20110131-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/20110131-1.c
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 14 Diego Novillo 2011-02-02 18:09:15 UTC
Author: dnovillo
Date: Wed Feb  2 18:09:04 2011
New Revision: 169713

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169713
Log:
	PR rtl-optimization/44031
	* gcc.c-torture/compile/20110131-1.c: New test.

Added:
    branches/google/integration/gcc/testsuite/gcc.c-torture/compile/20110131-1.c
Modified:
    branches/google/integration/gcc/testsuite/ChangeLog