I am using g++ to compile shogun 0.1.2 from http://www.fml.tuebingen.mpg.de/raetsch/projects/shogun. g++ however dies as soon as I turn on optimization -O1 with the following error (it will compile ok with -O0). c++ -O1 -fPIC -DLINUX -g -c -I. -I/usr/include/octave-2.1.73 -o guilib/GUIFeatures.cpp.o guilib/GUIFeatures.cpp guilib/GUIFeatures.cpp: In member function ‘CRealFeatures* CGUIFeatures::convert_sparse_real_to_simple_real(CSparseRealFeatures*, CHAR*)’: guilib/GUIFeatures.cpp:591: error: unrecognizable insn: (insn 204 209 208 20 ./features/SparseFeatures.h:227 (set (subreg:SI (reg:DI 199) 4) (plus:SI (reg:SI 197) (mem/s/j:SI (reg/f:SI 138 [ D.22963 ]) [0 <variable>.feat_index+0 S4 A64]))) -1 (nil) (nil)) guilib/GUIFeatures.cpp:591: internal compiler error: in extract_insn, at recog.c:2084 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. For Debian GNU/Linux specific bug reporting instructions, see <URL:file:///usr/share/doc/gcc-4.1/README.Bugs>. I am on a linux-ppc arch running debian sid: $ cat /proc/cpuinfo processor : 0 cpu : 7455, altivec supported clock : 1000.000000MHz revision : 0.3 (pvr 8001 0303) bogomips : 99.79 timebase : 33331495 platform : PowerMac machine : PowerBook3,5 motherboard : PowerBook3,5 MacRISC2 MacRISC Power Macintosh detected as : 80 (PowerBook Titanium IV) pmac flags : 0000001b L2 cache : 256K unified pmac-generation : NewWorld $ g++ -v Using built-in specs. Target: powerpc-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --disable-softfloat --enable-targets=powerpc-linux,powerpc64-linux --with-cpu=default32 --enable-checking=release powerpc-linux-gnu Thread model: posix gcc version 4.1.2 20060901 (prerelease) (Debian 4.1.1-13)
Created attachment 12338 [details] Preprocessed source I was kindly asked to: 'Preprocessed source stored into /tmp/ccQLsVtW.out file, please attach this to your bugreport.' So here we go :)
Reducing.
Confirmed, reduced testcase: struct TSparseEntry { int feat_index; double entry; }; struct TSparse { int vec_index; int num_feat_entries; struct TSparseEntry* features; }; void get_full_feature_matrix(struct TSparse* sparse_feature_matrix, int num_vec) { double* fm; for (int v=0; v<num_vec; v++) { for (int f=0; f<sparse_feature_matrix[v].num_feat_entries; f++) { long long offs = sparse_feature_matrix[v].vec_index + sparse_feature_matrix[v].features[f].feat_index; fm[offs]= sparse_feature_matrix[v].features[f].entry; } } }
How is expand even generating this? This is completely invalid RTL for PPC.
The expander is producing invalid RTL. If the index variable "offs" is changed from "long long" to "long", the code compiles correctly and the memory loads are placed in temporary pseudos. Only with "long long" does GCC punt and expand to a sum of memory references.
The reason this is going off the rails is a "long" index invokes expand_expr_real_1 with PLUS_EXP and modifier=EXPAND_NORMAL while "long long" invokes it with modifier=EXPAND_SUM. For EXPAND_NORMAL, GCC invokes expand_operands() and then calls expand_binop(), which tests predicates. For EXPAND_SUM, expand_operands() is followed by simplify_gen_binary(), which does not check predicates. Invalid RTL is created and fun ensues.
<plus_expr 3000d410 type <pointer_type 30013e38 type <real_type 30013d00 double DF size <integer_cst 30006760 constant invariant 64> unit size <integer_cst 30006780 constant invariant 8> align 64 symtab 0 alias set -1 precision 64 pointer_to_this <pointer_type 30013e38>> sizes-gimplified unsigned SI size <integer_cst 300065c0 constant invariant 32> unit size <integer_cst 30006280 constant invariant 4> align 32 symtab 0 alias set -1> arg 0 <convert_expr 300c67a0 type <pointer_type 30013e38> arg 0 <mult_expr 3000d3e8 type <integer_type 30013410 unsigned int> arg 0 <convert_expr 300c6740 type <integer_type 30013410 unsigned int> arg 0 <nop_expr 300c66a0 type <integer_type 30013548 long long int> arg 0 <plus_expr 3000d398 type <integer_type 300133a8 int> arg 0 <component_ref 3000d370 type <integer_type 300133a8 int> arg 0 <indirect_ref 300c6680> arg 1 <field_decl 300c5ee0 feat_index>> arg 1 <target_mem_ref 3013e7a8 type <integer_type 300133a8 int> arg 1 <var_decl 3013dcb0 D.2073> arg 2 <var_decl 3013dd20 D.2074> arg 5 <component_ref 301440f0> arg 6 <symbol_memory_tag 3000dcf8 SMT.6>>>>> arg 1 <integer_cst 300c6760 constant invariant 8>>> arg 1 <var_decl 30131150 fm type <pointer_type 30013e38> used tree_1 unsigned decl_5 SI file /farm/dje/gui.cc line 17 size <integer_cst 300065c0 32> unit size <integer_cst 30006280 4> align 32 context <function_decl 3012e100 get_full_feature_matrix> (reg/v/f:SI 151 [ fm ])>> The INDIRECT_REF case of expand_expr() sets modifier=EXPAND_SUM, but EXPAND_SUM only should apply to the top level.
Subject: Bug 29250 Author: dje Date: Sat Oct 14 03:03:23 2006 New Revision: 117724 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117724 Log: 2006-10-13 David Edelsohn <edelsohn@gnu.org> Ian Lance Taylor <ian@airs.com> PR middle-end/29250 * expr.c (expand_expr_real_1) <NON_LVALUE_EXPR, NOP_EXPR, CONVERT_EXPR>: Change EXPAND_SUM modifier to EXPAND_NORMAL when recursing. Modified: trunk/gcc/ChangeLog trunk/gcc/expr.c
A regression from 3.4.6, most likely exposed by the gimplifier or TER in out of SSA. I really want to say the gimplifier with respect of type casting.
A C89 testcase: struct TSparseEntry { int feat_index; double entry; }; struct TSparse { int vec_index; int num_feat_entries; struct TSparseEntry* features; }; void get_full_feature_matrix(struct TSparse* sparse_feature_matrix, int num_vec) { double* fm; int v, f; for (v=0; v<num_vec; v++) { for (f=0; f<sparse_feature_matrix[v].num_feat_entries; f++) { long long offs = sparse_feature_matrix[v].vec_index + sparse_feature_matrix[v].features[f].feat_index; fm[offs]= sparse_feature_matrix[v].features[f].entry; } } }
Subject: Bug 29250 Author: dje Date: Sun Oct 15 16:21:14 2006 New Revision: 117747 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117747 Log: PR middle-end/29250 * gcc.c-torture/compile/pr29250.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/compile/pr29250.c Modified: trunk/gcc/testsuite/ChangeLog
Subject: Bug 29250 Author: dje Date: Thu Nov 2 17:18:52 2006 New Revision: 118421 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118421 Log: 2006-10-13 David Edelsohn <edelsohn@gnu.org> Ian Lance Taylor <ian@airs.com> PR middle-end/29250 * expr.c (expand_expr_real_1) <NON_LVALUE_EXPR, NOP_EXPR, CONVERT_EXPR>: Change EXPAND_SUM modifier to EXPAND_NORMAL when recursing. Modified: branches/gcc-4_1-branch/gcc/ChangeLog branches/gcc-4_1-branch/gcc/expr.c
Fixed on mainline, 4.2.0, and 4.1.2. Won't fix on 4.0 branch.