SPEC CPU 2006 453.povray ICEs compiling super.cpp with > g++-4.4 -S -O3 -fomit-frame-pointer -msse3 -m32 -march=i586 super.ii super.cpp: In function 'void pov::Superellipsoid_Normal(double*, pov::OBJECT*, pov::INTERSECTION*)': super.cpp:515: internal compiler error: in subst_stack_regs_pat, at reg-stack.c:1386 Please submit a full bug report, with preprocessed source if appropriate. See <http://bugs.opensuse.org/> for instructions.
Created attachment 17678 [details] reduced testcase
ICEs since http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143757
Simplified testcase (ICEs with both C and C++ FEs): extern double pow (double, double); extern double fabs (double); void foo (double *); void bar (double *); static double baz (double x, double e) { if ((int) e == 1) return x; return pow (x, e); } void test (double *x, double *y) { double P[3], r; bar (P); if (P[2] != 0) baz (fabs (P[2]), y[2]); if (fabs (P[0]) > fabs (P[1])) r = baz (fabs (P[1] / P[0]), y[0]); if (P[2]) P[2] *= (1 + r); foo (x); }
Even more reduced: extern double pow (double, double); extern double fabs (double); void foo (double *); static double bar (double x, double e) { if ((int) e == 1) return x; return pow (x, e); } void test (double *x, double *y) { double r; if (x[2]) bar (x[2], y[1]); if (x[0]) r = bar (fabs (x[1]), y[0]); if (x[2]) x[2] *= (1 + r); foo (x); }
I guess this is related to the (sometimes) uninitialized r variable (the same as in the original povray sources).
Jakub, thanks for reducing the test. I'll investigate this bug more.
In gcc4.4 we have before reg-stack.c (insn 96 82 97 4 /home/vmakarov/build/bb.ii:8 (parallel [ (set (mem/c:SI (plus:SI (reg/f:SI 7 sp) (const_int 28 [0x1c])) [0 S4 A32]) (fix:SI (reg:DF 9 st(1)))) (clobber (reg:XF 9 st(1))) ]) 119 {fix_truncsi_i387_fisttp} (expr_list:REG_DEAD (reg:DF 9 st(1)) (nil))) in subst_stack_regs first it is changed to (insn:TI 96 82 97 4 /home/vmakarov/build/bb.ii:8 (parallel [ (set (mem/c:SI (plus:SI (reg/f:SI 7 sp) (const_int 28 [0x1c])) [0 S4 A32]) (fix:SI (reg:DF 8 st))) (clobber (reg:XF 9 st(1))) ]) 119 {fix_truncsi_i387_fisttp} (expr_list:REG_DEAD (reg:DF 8 st) (nil))) Then it is trying to change clobber and fail because there is no note about dead or unused reg 9, it fails in subst_stack_regs_pat on the assert: if (note) emit_pop_insn (insn, regstack, *dest, EMIT_BEFORE); else { note = find_reg_note (insn, REG_UNUSED, *dest); gcc_assert (note); } The gcc4.3 has analogous insn before reg-stack.c (insn 106 92 107 4 bb.ii:8 (parallel [ (set (mem/c:SI (plus:SI (reg/f:SI 7 sp) (const_int 28 [0x1c])) [0 S4 A8]) (fix:SI (reg:DF 11 st(3)))) (clobber (reg:XF 11 st(3))) ]) 159 {fix_truncsi_i387_fisttp} (expr_list:REG_DEAD (reg:DF 11 st(3)) (expr_list:REG_UNUSED (reg:XF 11 st(3)) (nil)))) The difference is in presense of REG_UNUSED (reg:XF 11 st(3)) which does not permit the gcc_assert aborts gcc4.3. The note is present because LR_OUT at BB 4 does not contain 11 st(3). Quite opposite, 9 st(1) is in LR_OUT at BB 4 in gcc4.4. Therefore REG_UNUSED note is not generated for gcc4.4. So why there is such difference in LR_OUT for 4.3 vs 4.4? Gcc4.3 is lucky to use 11 st (3) only in BB3 (where insn 116 is placed). Gcc4.4 uses 9 st(1) in insn 96 and reuses it in many other BBs. Because of partially set register for variable R, we got that LR_OUT is set up in BB 3. If somebody is interesting here is the CFG with LR_OUT & LR_IN and usage of 9 st (1): 0 | v 2--> | | v | 3->| lr_out:9 set 9;use 9;clobber 9 | | v | 4 | lr_out:9 call | | v | 5<- lr_in:9 lr_out:9 |\ | \ 6->| lr_out:9 set 9 | | | | 7 | lr_in:9 lr_out:9 use 9 .. set 9 | | | | 8<- lr_in:9 lr_out:9 |\ | \ 9 | lr_in:9 use 9 | | | | 10<- So the code if (note) emit_pop_insn (insn, regstack, *dest, EMIT_BEFORE); else { note = find_reg_note (insn, REG_UNUSED, *dest); gcc_assert (note); } does not take situation of reusage of hard register for partially set variable. IMHO, the code should be Index: reg-stack.c =================================================================== --- reg-stack.c (revision 146648) +++ reg-stack.c (working copy) @@ -1381,11 +1381,9 @@ subst_stack_regs_pat (rtx insn, stack re if (note) emit_pop_insn (insn, regstack, *dest, EMIT_BEFORE); else - { - note = find_reg_note (insn, REG_UNUSED, *dest); - gcc_assert (note); - } - remove_note (insn, note); + note = find_reg_note (insn, REG_UNUSED, *dest); + if (note) + remove_note (insn, note); replace_reg (dest, FIRST_STACK_REG + 1); } else I'll send the patch soon.
Patch has been posted almost a month ago: http://gcc.gnu.org/ml/gcc-patches/2009-04/msg01926.html Vlad, could you please ping it?
Subject: Bug 39856 Author: vmakarov Date: Fri May 22 18:59:30 2009 New Revision: 147803 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147803 Log: 2009-05-22 Vladimir Makarov <vmakarov@redhat.com> PR target/39856 * reg-stack.c (subst_stack_regs_pat): Remove gcc_assert for note for clobber. Modified: branches/gcc-4_4-branch/gcc/ChangeLog branches/gcc-4_4-branch/gcc/reg-stack.c
Subject: Bug 39856 Author: vmakarov Date: Fri May 22 19:00:45 2009 New Revision: 147804 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147804 Log: 2009-05-22 Vladimir Makarov <vmakarov@redhat.com> PR target/39856 * reg-stack.c (subst_stack_regs_pat): Remove gcc_assert for note for clobber. Modified: trunk/gcc/ChangeLog trunk/gcc/reg-stack.c
Fixed.
*** Bug 50316 has been marked as a duplicate of this bug. ***