Bug 39856 - [4.4/4.5 Regression] ICE in subst_stack_regs_pat, at reg-stack.c:1386
Summary: [4.4/4.5 Regression] ICE in subst_stack_regs_pat, at reg-stack.c:1386
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.0
: P1 normal
Target Milestone: 4.4.1
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 50316 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-04-22 21:08 UTC by Richard Biener
Modified: 2021-08-09 03:51 UTC (History)
6 users (show)

See Also:
Host:
Target: i?86-*-*
Build:
Known to work: 4.3.3
Known to fail: 4.4.0 4.5.0
Last reconfirmed: 2009-04-22 22:05:27


Attachments
reduced testcase (609 bytes, text/plain)
2009-04-22 21:08 UTC, Richard Biener
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2009-04-22 21:08:08 UTC
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.
Comment 1 Richard Biener 2009-04-22 21:08:38 UTC
Created attachment 17678 [details]
reduced testcase
Comment 2 Jakub Jelinek 2009-04-22 22:05:27 UTC
ICEs since http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143757
Comment 3 Jakub Jelinek 2009-04-23 08:45:43 UTC
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);
}
Comment 4 Jakub Jelinek 2009-04-23 08:50:27 UTC
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);
}
Comment 5 Jakub Jelinek 2009-04-23 09:13:38 UTC
I guess this is related to the (sometimes) uninitialized r variable (the same as in the original povray sources).
Comment 6 Vladimir Makarov 2009-04-23 17:27:33 UTC
Jakub, thanks for reducing the test.  I'll investigate this bug more.
Comment 7 Vladimir Makarov 2009-04-24 15:53:44 UTC
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.

Comment 8 Jakub Jelinek 2009-05-21 14:07:20 UTC
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?
Comment 9 Vladimir Makarov 2009-05-22 18:59:46 UTC
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

Comment 10 Vladimir Makarov 2009-05-22 19:01:06 UTC
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

Comment 11 Jakub Jelinek 2009-05-28 22:39:35 UTC
Fixed.
Comment 12 Andrew Pinski 2021-08-09 03:51:37 UTC
*** Bug 50316 has been marked as a duplicate of this bug. ***