Bug 21309 - [4.0/4.1/4.2 regression] internal compiler error: in expand_mult_const, at expmed.c:2884
Summary: [4.0/4.1/4.2 regression] internal compiler error: in expand_mult_const, at ex...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.0
: P5 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2005-04-30 22:04 UTC by matt
Modified: 2005-11-27 16:20 UTC (History)
1 user (show)

See Also:
Host:
Target: vax--netbsdelf
Build:
Known to work: 3.4.5
Known to fail: 4.0.1 4.1.0
Last reconfirmed: 2005-05-22 21:39:49


Attachments
source file exhibiting problem (13.01 KB, text/plain)
2005-04-30 22:04 UTC, matt
Details
C file causing the ICE (12.84 KB, text/plain)
2005-04-30 22:11 UTC, matt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description matt 2005-04-30 22:04:16 UTC
Using built-in specs.
Target: vax--netbsdelf
Configured with: /u1/toolchain/gcc/configure --target=vax--netbsdelf --build=x86
_64--netbsd --host=x86_64--netbsd --disable-shared --disable-threads --prefix=/u
sr/gcc
Thread model: single
gcc version 4.1.0 20050422 (experimental)
 /usr/gcc/libexec/gcc/vax--netbsdelf/4.1.0/cc1 -E -quiet -nostdinc -v -I. -isyst
em /u1/vax/root/usr/include /usr/src/games/hack/hack.bones.c -Wall -Wstrict-prot
otypes -Wmissing-prototypes -Wpointer-arith -Wno-sign-compare -Wno-traditional -
Wno-uninitialized -O2 -fpch-preprocess -o hack.bones.i
#include "..." search starts here:
#include <...> search starts here:
 .
 /u1/vax/root/usr/include
End of search list.
# cc1 0.02 0.01
 /usr/gcc/libexec/gcc/vax--netbsdelf/4.1.0/cc1 -fpreprocessed hack.bones.i -quie
t -dumpbase hack.bones.c -auxbase hack.bones -O2 -Wall -Wstrict-prototypes -Wmis
sing-prototypes -Wpointer-arith -Wno-sign-compare -Wno-traditional -Wno-uninitia
lized -version -o hack.bones.s
GNU C version 4.1.0 20050422 (experimental) (vax--netbsdelf)
        compiled by GNU C version 3.3.3 (NetBSD nb3 20040520).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
/usr/src/games/hack/hack.bones.c: In function 'savebones':
/usr/src/games/hack/hack.bones.c:89: internal compiler error: in expand_mult_con
st, at expmed.c:2884
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
# cc1 0.05 0.01


Breakpoint 1, fancy_abort (file=0x937520 "/u1/toolchain/gcc/gcc/expmed.c", 
    line=2884, function=0x9375f0 "expand_mult_const")
    at /u1/toolchain/gcc/gcc/diagnostic.c:571
571       internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
(gdb) where
#0  fancy_abort (file=0x937520 "/u1/toolchain/gcc/gcc/expmed.c", line=2884, 
    function=0x9375f0 "expand_mult_const")
    at /u1/toolchain/gcc/gcc/diagnostic.c:571
#1  0x000000000065f41b in expand_mult_const (mode=SImode, op0=0x2011e30c0, 
    val=26215, target=0x0, alg=0x7f7fffffcb50, variant=basic_variant)
    at /u1/toolchain/gcc/gcc/expmed.c:2884
#2  0x0000000000660b8a in expand_mult_highpart (mode=HImode, op0=0x2011d17e0, 
    op1=0x201183bd0, target=0x0, unsignedp=0, max_cost=2147483619)
    at /u1/toolchain/gcc/gcc/expmed.c:3484
#3  0x0000000000662038 in expand_divmod (rem_flag=0, code=TRUNC_DIV_EXPR, 
    mode=HImode, op0=0x2011d17e0, op1=0x200eed4a0, target=0x0, unsignedp=0)
    at /u1/toolchain/gcc/gcc/expmed.c:4143
#4  0x0000000000685866 in expand_expr_real_1 (exp=0x2010aecd0, target=0x0, 
    tmode=QImode, modifier=EXPAND_NORMAL, alt_rtl=0x0)
    at /u1/toolchain/gcc/gcc/expr.c:7799
#5  0x00000000006780ef in expand_expr_real (exp=0x2010aecd0, target=0x0, 
    tmode=QImode, modifier=EXPAND_NORMAL, alt_rtl=0x0)
    at /u1/toolchain/gcc/gcc/expr.c:6416
#6  0x000000000068d4e3 in expand_expr (exp=0x2010aecd0, target=0x0, 
    mode=QImode, modifier=EXPAND_NORMAL) at expr.h:487
#7  0x000000000067ebb7 in expand_expr_real_1 (exp=0x2010add00, target=0x0, 
    tmode=VOIDmode, modifier=EXPAND_NORMAL, alt_rtl=0x0)
    at /u1/toolchain/gcc/gcc/expr.c:7408
---Type <return> to continue, or q <return> to quit---
#8  0x00000000006780ef in expand_expr_real (exp=0x2010add00, target=0x0, 
    tmode=VOIDmode, modifier=EXPAND_NORMAL, alt_rtl=0x0)
    at /u1/toolchain/gcc/gcc/expr.c:6416
#9  0x000000000068d4e3 in expand_expr (exp=0x2010add00, target=0x0, 
    mode=VOIDmode, modifier=EXPAND_NORMAL) at expr.h:487
#10 0x000000000067770c in expand_operands (exp0=0x2010add00, exp1=0x20116e4e0, 
    target=0x0, op0=0x7f7fffffde58, op1=0x7f7fffffde50, modifier=EXPAND_NORMAL)
    at /u1/toolchain/gcc/gcc/expr.c:6143
#11 0x0000000000681d31 in expand_expr_real_1 (exp=0x2010aedc0, target=0x0, 
    tmode=QImode, modifier=EXPAND_NORMAL, alt_rtl=0x7f7fffffdfc0)
    at /u1/toolchain/gcc/gcc/expr.c:7618
#12 0x00000000006780ef in expand_expr_real (exp=0x2010aedc0, 
    target=0x2011e3080, tmode=QImode, modifier=EXPAND_NORMAL, 
    alt_rtl=0x7f7fffffdfc0) at /u1/toolchain/gcc/gcc/expr.c:6416
#13 0x000000000066e599 in store_expr (exp=0x2010aedc0, target=0x2011e3080, 
    call_param_p=0) at /u1/toolchain/gcc/gcc/expr.c:4170
#14 0x00000000006731af in store_field (target=0x2011e3000, bitsize=8, 
    bitpos=48, mode=QImode, exp=0x2010aedc0, type=0x20116f5b0, alias_set=0)
    at /u1/toolchain/gcc/gcc/expr.c:5360
#15 0x000000000066d67a in expand_assignment (to=0x20116ba80, from=0x2010aedc0)
    at /u1/toolchain/gcc/gcc/expr.c:3941
#16 0x0000000000688766 in expand_expr_real_1 (exp=0x2010aee10, target=0x0, 
    tmode=VOIDmode, modifier=EXPAND_NORMAL, alt_rtl=0x0)
---Type <return> to continue, or q <return> to quit---
    at /u1/toolchain/gcc/gcc/expr.c:8235
#17 0x00000000006780b9 in expand_expr_real (exp=0x2010aee10, 
    target=0x200eed400, tmode=VOIDmode, modifier=EXPAND_NORMAL, alt_rtl=0x0)
    at /u1/toolchain/gcc/gcc/expr.c:6410
#18 0x00000000007a54e3 in expand_expr (exp=0x2010aee10, target=0x200eed400, 
    mode=VOIDmode, modifier=EXPAND_NORMAL) at expr.h:487
#19 0x000000000079e715 in expand_expr_stmt (exp=0x2010aee10)
    at /u1/toolchain/gcc/gcc/stmt.c:1340
#20 0x00000000007fe8a2 in expand_gimple_basic_block (bb=0x20118b270, 
    dump_file=0x0) at /u1/toolchain/gcc/gcc/cfgexpand.c:1131
#21 0x00000000007fefea in tree_expand_cfg ()
    at /u1/toolchain/gcc/gcc/cfgexpand.c:1304
#22 0x00000000004c7e88 in execute_one_pass (pass=0xa8a6a0)
    at /u1/toolchain/gcc/gcc/tree-optimize.c:578
#23 0x00000000004c7f6f in execute_pass_list (pass=0xa8a6a0)
    at /u1/toolchain/gcc/gcc/tree-optimize.c:615
#24 0x00000000004c828f in tree_rest_of_compilation (fndecl=0x2010b0dd0)
    at /u1/toolchain/gcc/gcc/tree-optimize.c:728
#25 0x000000000041ed93 in c_expand_body (fndecl=0x2010b0dd0)
    at /u1/toolchain/gcc/gcc/c-decl.c:6411
#26 0x000000000081e932 in cgraph_expand_function (node=0x201179a90)
    at /u1/toolchain/gcc/gcc/cgraphunit.c:924
#27 0x000000000081ebc4 in cgraph_expand_all_functions ()
---Type <return> to continue, or q <return> to quit---
    at /u1/toolchain/gcc/gcc/cgraphunit.c:988
#28 0x000000000081ef17 in cgraph_optimize ()
    at /u1/toolchain/gcc/gcc/cgraphunit.c:1090
#29 0x00000000004219d2 in c_write_global_declarations ()
    at /u1/toolchain/gcc/gcc/c-decl.c:7395
#30 0x00000000007b20d5 in compile_file ()
    at /u1/toolchain/gcc/gcc/toplev.c:1013
#31 0x00000000007b38bd in do_compile () at /u1/toolchain/gcc/gcc/toplev.c:2123
#32 0x00000000007b3924 in toplev_main (argc=19, argv=0x7f7fffffeaa8)
    at /u1/toolchain/gcc/gcc/toplev.c:2155
#33 0x0000000000499057 in main (argc=19, argv=0x7f7fffffeaa8)
    at /u1/toolchain/gcc/gcc/main.c:35
Comment 1 matt 2005-04-30 22:04:58 UTC
Created attachment 8776 [details]
source file exhibiting problem
Comment 2 matt 2005-04-30 22:11:43 UTC
Created attachment 8777 [details]
C file causing the ICE
Comment 3 matt 2005-05-08 15:32:37 UTC
This bug is to due to struct mult_cost having its member defined as shorts. 
Since MAX_COST is defined to be INT_MAX, when a cost value is moved from div_mod
to mult_cost, the upper bits are truncated and the 0x7fffffd9 cost becomes
0xffd9. This results is a negative cost and causes a premature to happen in
synth_mult due to:

  if (cost_limit->cost < 0
      || (cost_limit->cost == 0 && cost_limit->latency <= 0))
    return;

And so the algorithm fails to be set resulting in the eventual call to
gcc_unreachable.

Simply changing the members of mult_cost from short to int causes the ICE to be
avoided.

--- expmed.c    27 Apr 2005 16:02:33 -0000      1.228
+++ expmed.c    8 May 2005 15:32:04 -0000
@@ -2315,8 +2315,8 @@ enum alg_code { alg_unknown, alg_zero, a
    leaves and rtx_cost(op) + max(latency(a), latency(b)) otherwise.  */
 
 struct mult_cost {
-  short cost;     /* Total rtx_cost of the multiplication sequence.  */
-  short latency;  /* The latency of the multiplication sequence.  */
+  int cost;     /* Total rtx_cost of the multiplication sequence.  */
+  int latency;  /* The latency of the multiplication sequence.  */
 };
 
 /* This macro is used to compare a pointer to a mult_cost against an
Comment 4 Serge Belyshev 2005-05-22 21:39:48 UTC
Confirmed, reduced testcase:

char c; void f () { c /= 10; }
Comment 5 Roger Sayle 2005-11-26 04:07:02 UTC
Subject: Bug 21309

Author: sayle
Date: Sat Nov 26 04:06:57 2005
New Revision: 107537

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107537
Log:

	PR middle-end/21309
	* expmed.c (choose_mult_variant): Return immediately when mult_cost
	is less than zero.  Limit mult_cost to a reasonable upper bound for
	the synthetic multiplication sequence.


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

Comment 6 Roger Sayle 2005-11-26 21:46:22 UTC
Subject: Bug 21309

Author: sayle
Date: Sat Nov 26 21:46:19 2005
New Revision: 107542

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107542
Log:

	PR middle-end/21309
	* expmed.c (choose_mult_variant): Return immediately when mult_cost
	is less than zero.  Limit mult_cost to a reasonable upper bound for
	the synthetic multiplication sequence.


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

Comment 7 Roger Sayle 2005-11-27 14:27:31 UTC
Subject: Bug 21309

Author: sayle
Date: Sun Nov 27 14:27:26 2005
New Revision: 107567

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107567
Log:

	PR middle-end/21309
	* expmed.c (choose_mult_variant): Return immediately when mult_cost
	is less than zero.  Limit mult_cost to a reasonable upper bound for
	the synthetic multiplication sequence.


Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/expmed.c

Comment 8 Andrew Pinski 2005-11-27 16:20:19 UTC
Fixed.