Bug 39588 - [4.3/4.4/4.5 Regression] internal compiler error: in trunc_int_for_mode, at explow.c:55
Summary: [4.3/4.4/4.5 Regression] internal compiler error: in trunc_int_for_mode, at e...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.3.3
: P3 normal
Target Milestone: 4.3.4
Assignee: Eric Botcazou
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2009-03-30 13:28 UTC by Olivier ROUSSEL
Modified: 2009-04-01 20:51 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2009-03-31 15:43:52


Attachments
test source file (144 bytes, text/x-csrc)
2009-03-30 13:48 UTC, Olivier ROUSSEL
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier ROUSSEL 2009-03-30 13:28:49 UTC
# gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.3.3/configure --prefix=/tmp/gcc433 --enable-languages=c,c++
Thread model: posix
gcc version 4.3.3 (GCC)

with the following, self-contained file buc.c

#define lit_from_int(in) ((in<0)?(((-in)<<1)|1):(in<<1))
void init_clause(int* literals,int size, int *lits)
{
  int i;
  for(i=0; i < size; i++) {
    lits[i] = lit_from_int(literals[i]);
  }
}

On a x86_64 host, both gcc 4.3.1 (handmade compilation), gcc 4.3.2 (Fedora Core 10 package) and gcc 4.3.3 (handmade compilation) crash with -O3 optimization

# gcc -O3 -c bug.c 
bug.c: In function ‘init_clause’:
bug.c:10: internal compiler error: in trunc_int_for_mode, at explow.c:55

This bug doesn't occur on a i686 host (gcc 4.3.2). On a x86_64 host, it doesn't  occur when -O2 is used with gcc 4.3.3 or when gcc 4.2.4 is used.
Comment 1 Olivier ROUSSEL 2009-03-30 13:48:20 UTC
Created attachment 17558 [details]
test source file
Comment 2 Richard Biener 2009-03-30 14:24:14 UTC
Confirmed.  -ftree-vectorize is the problem or maybe triggers a target problem.

#1  0x0000000000605517 in trunc_int_for_mode (c=0, mode=V4SImode)
    at /space/rguenther/src/svn/trunk/gcc/explow.c:56
56        gcc_assert (SCALAR_INT_MODE_P (mode));

#1  0x0000000000605517 in trunc_int_for_mode (c=0, mode=V4SImode)
    at /space/rguenther/src/svn/trunk/gcc/explow.c:56
#2  0x0000000000e481a3 in merge_outer_ops (pop0=0x7fffffffd228, 
    pconst0=0x7fffffffd220, op1=NEG, const1=0, mode=V4SImode, 
    pcomp_p=0x7fffffffd21c)
    at /space/rguenther/src/svn/trunk/gcc/combine.c:8962
#3  0x0000000000e494f5 in simplify_shift_const_1 (code=ASHIFT, 
    result_mode=V4SImode, varop=0x7ffff61a9850, orig_count=1)
    at /space/rguenther/src/svn/trunk/gcc/combine.c:9486
#4  0x0000000000e49dfb in simplify_shift_const (x=0x7ffff61a25c0, code=ASHIFT, 
    result_mode=V4SImode, varop=0x7ffff61a9850, count=1)
    at /space/rguenther/src/svn/trunk/gcc/combine.c:9723
#5  0x0000000000e3e277 in combine_simplify_rtx (x=0x7ffff61a25c0, 
    op0_mode=V4SImode, in_dest=0)
    at /space/rguenther/src/svn/trunk/gcc/combine.c:5225
#6  0x0000000000e3c4e1 in subst (x=0x7ffff61a25c0, from=0x7ffff61a24e0, 
    to=0x7ffff61a9850, in_dest=0, unique_copy=0)
    at /space/rguenther/src/svn/trunk/gcc/combine.c:4543
#7  0x0000000000e3c2e7 in subst (x=0x7ffff61a25e0, from=0x7ffff61a24e0, 
    to=0x7ffff61a9850, in_dest=0, unique_copy=0)
    at /space/rguenther/src/svn/trunk/gcc/combine.c:4481
#8  0x0000000000e370bf in try_combine (i3=0x7ffff61a0b40, i2=0x7ffff61a0af0, 
    i1=0x0, new_direct_jump_p=0x7fffffffda34)
    at /space/rguenther/src/svn/trunk/gcc/combine.c:2726
#9  0x0000000000e336bc in combine_instructions (f=0x7ffff61a8080, nregs=111)
    at /space/rguenther/src/svn/trunk/gcc/combine.c:1256
#10 0x0000000000e5197b in rest_of_handle_combine ()
    at /space/rguenther/src/svn/trunk/gcc/combine.c:12999
Comment 3 Richard Biener 2009-03-30 14:56:20 UTC
We want to simplify

(ashift:V4SI (neg:V4SI (reg:V4SI 87))
    (const_int 1 [0x1]))

to

(neg:V4SI (ashift:V4Si (reg:V4SI 87)
    (const_int 1 [0x1]))

but the code obviously doesn't expect vector modes.  For the particular
case of shifts we pass down zero, so the following would fix^Wworkaround
the issue

Index: gcc/combine.c
===================================================================
--- gcc/combine.c       (revision 145291)
+++ gcc/combine.c       (working copy)
@@ -8974,7 +8974,8 @@ merge_outer_ops (enum rtx_code *pop0, HO
   /* ??? Slightly redundant with the above mask, but not entirely.
      Moving this above means we'd have to sign-extend the mode mask
      for the final test.  */
-  const0 = trunc_int_for_mode (const0, mode);
+  if (const0 != 0)
+    const0 = trunc_int_for_mode (const0, mode);
 
   *pop0 = op0;
   *pconst0 = const0;
Comment 4 Eric Botcazou 2009-04-01 20:46:46 UTC
Subject: Bug 39588

Author: ebotcazou
Date: Wed Apr  1 20:46:30 2009
New Revision: 145430

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145430
Log:
	PR rtl-optimization/39588
	* combine.c (merge_outer_ops): Do not set the constant when this
	is not necessary.
	(simplify_shift_const_1): Do not modify it either in this case.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/20090401-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/combine.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Eric Botcazou 2009-04-01 20:47:48 UTC
Subject: Bug 39588

Author: ebotcazou
Date: Wed Apr  1 20:47:37 2009
New Revision: 145431

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145431
Log:
	PR rtl-optimization/39588
	* combine.c (merge_outer_ops): Do not set the constant when this
	is not necessary.
	(simplify_shift_const_1): Do not modify it either in this case.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/20090401-1.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/combine.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 6 Eric Botcazou 2009-04-01 20:48:44 UTC
Subject: Bug 39588

Author: ebotcazou
Date: Wed Apr  1 20:48:33 2009
New Revision: 145432

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145432
Log:
	PR rtl-optimization/39588
	* combine.c (merge_outer_ops): Do not set the constant when this
	is not necessary.
	(simplify_shift_const_1): Do not modify it either in this case.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/20090401-1.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/combine.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 7 Eric Botcazou 2009-04-01 20:51:42 UTC
Thanks for the reduced testcase.