Bug 21030 - [4.1 Regression] ICE in set_value_range building 176.gcc with -O2
Summary: [4.1 Regression] ICE in set_value_range building 176.gcc with -O2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Diego Novillo
URL:
Keywords: ice-on-valid-code, patch
: 21381 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-14 20:41 UTC by Janis Johnson
Modified: 2005-05-04 15:05 UTC (History)
8 users (show)

See Also:
Host: powerpc-linux
Target: powerpc-linux
Build: powerpc-linux
Known to work: 4.0.0
Known to fail: 4.1.0
Last reconfirmed: 2005-04-29 14:11:54


Attachments
minimized test case (244 bytes, text/plain)
2005-04-14 20:43 UTC, Janis Johnson
Details
patch (728 bytes, text/plain)
2005-04-14 23:01 UTC, Kazu Hirata
Details
an updated patch that does not break g++.dg/tree-ssa/pr18178.C (1.23 KB, text/plain)
2005-04-29 14:37 UTC, Kazu Hirata
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Janis Johnson 2005-04-14 20:41:22 UTC
Mainline GCC for powerpc-linux gets an ICE compiling 176.gcc from SPEC
CPU2000 with -O2, as shown with this minimized test case:
                                                                                
elm3b149% /home/janis/tools/gcc-mline-20050414/bin/gcc -O2 -c bug.c
bug.c: In function ‘schedule_unit’:
bug.c:5: internal compiler error: in set_value_range, at tree-vrp.c:124
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
                                                                                
That abort is in checking code added on 2005-04-09 by dnovillo.
Comment 1 Janis Johnson 2005-04-14 20:43:14 UTC
Created attachment 8633 [details]
minimized test case
Comment 2 Andrew Pinski 2005-04-14 20:44:19 UTC
Confirmed, also happens on i686-pc-linux-gnu.
Comment 3 Kazu Hirata 2005-04-14 22:14:05 UTC
Reduced down to:

void
foo (int unit)
{
  int i;

  for (i = 0; unit; i++, unit--)
    {
      if (i >= 0)
	{
	  int j = i;
	  while (j)
	    j--;
	}
    }
}
Comment 4 Kazu Hirata 2005-04-14 23:01:00 UTC
Created attachment 8638 [details]
patch
Comment 5 Kazu Hirata 2005-04-14 23:02:39 UTC
A comment in the patch says "Tested on i686-pc-linux-gnu", but
it just means that it will have been tested by the time I post this patch. :-)
Comment 6 wanderer 2005-04-19 20:08:44 UTC
Proposed patch (in #4) work fine at FreeBSD 5.1

And fix my tescase variant:

__inline void f(int a)
{
  int i;

  if (a < 0) {
    for (i = 0, a = ~a; a; i++) {
      if ((a & 1) != 0) {
        f(i);
      }
    }
  }
}

void g(void) { f(0); }

Without proposed patch i can't bootstrap LLVM using gcc CVS mainline.
bootstrap die at build of gcc version 3.4-llvm 20030924 (part of LLVM 
distribution):

gcc/haifa-sched.c:737: internal compiler error: in set_value_range, at tree-
vrp.c:124

Note: haifa-sched.c isn't modified.
Comment 7 Rainer Orth 2005-04-20 16:42:51 UTC
I observe the same ICE when bootstrapping with Ada on i386-pc-solaris2.10:

stage1/xgcc -Bstage1/ -B/vol/gcc/share/i386-pc-solaris2.10/bin/ -c -g -O2     
-gnatpg -gnata -I- -I. -Iada -I/vol/gnu/src/gcc/gcc-dist/gcc/ada
/vol/gnu/src/gcc/gcc-dist/gcc/ada/sem_intr.adb -o ada/sem_intr.o
+===========================GNAT BUG DETECTED==============================+
| 4.1.0 20050419 (experimental) (i386-pc-solaris2.10) GCC error:           |
| in set_value_range, at tree-vrp.c:124                                    |
| Error detected at sem_intr.adb:437:1                                     |

Unfortunately, the proposed patch doesn't fix this.
Comment 8 Tobias Schlüter 2005-04-22 19:36:02 UTC
Another testcase for something which looks like the same bug, this time in
Fortran (reduced from LAPACK by Steve Kargl):
      SUBROUTINE CHER2K(N, BETA, C, LDC)

      INTEGER I, J, N, LDC
      REAL BETA
      COMPLEX C(LDC,*), ZERO

      PARAMETER (ZERO = (0.0E+0, 0.0E+0))

      IF (BETA .EQ. REAL(ZERO)) THEN
         DO 20, J = 1, N
            DO 10, I = 1, J
               C(I,J) = ZERO
   10       CONTINUE
   20    CONTINUE
      ELSE
         DO 40, J = 1, N
            DO 30, I = 1, J - 1
               C(I,J) = BETA * C(I,J)
   30       CONTINUE
   40    CONTINUE
      END IF
      END
Comment 9 kargls 2005-04-22 22:34:49 UTC
This is a shorter version of the Fortran code.  The bug is now
critical to gfortran because almost all Fortran codes contain
nested do loops.

      SUBROUTINE CHER2K(N, C, LDC)

      INTEGER I, J, N, LDC
      COMPLEX C(LDC,*)

      DO 20, J = 1, N
         DO 10, I = 1, J
            C(I,J) = (0.0E+0, 0.0E+0)
   10    CONTINUE
   20 CONTINUE
      END
Comment 10 kargls 2005-04-22 23:03:27 UTC
Kazu, I just tried the patch, pr21030-vrp-ice.patch.
It seems to fix the problems with gfortran and -O2.
Comment 11 Toon Moene 2005-04-23 10:58:22 UTC
(In reply to comment #10)

> Kazu, I just tried the patch, pr21030-vrp-ice.patch.
> It seems to fix the problems with gfortran and -O2.

Kazu, could you propose your patch on gcc-patches or ping it ?  Without this
patch I won't be able to do any testing for my GCC Summit paper (deadline 1st of
May).

Thanks in advance.
Comment 12 Diego Novillo 2005-04-23 13:18:14 UTC
(In reply to comment #5)
> A comment in the patch says "Tested on i686-pc-linux-gnu", but
> it just means that it will have been tested by the time I post this patch. :-)
> 
Patch looks fine.  OK to install if it passes the usual testing.

It's odd that I don't seem to have received this patch.  Did you ever post it?


Diego.
Comment 13 Kazu Hirata 2005-04-23 14:13:31 UTC
Subject: Re:  [4.1 Regression] ICE in
 set_value_range building 176.gcc with -O2

Hi Toon,

> > Kazu, I just tried the patch, pr21030-vrp-ice.patch.
> > It seems to fix the problems with gfortran and -O2.
> 
> Kazu, could you propose your patch on gcc-patches or ping it ?  Without this
> patch I won't be able to do any testing for my GCC Summit paper (deadline 1st of
> May).

I would like to, but currently my patch causes a regression in one of
the VRP testcases.  I have not checked if the failure is a real one or
not.  That is, it's plausible that we are looking for an optimization
that should not happen.

Kazu Hirata
Comment 14 kargls 2005-04-23 15:11:49 UTC
(In reply to comment #13)
> 
> I would like to, but currently my patch causes a regression in one of
> the VRP testcases.
> 

Not to sound like an idiot, but how likely is this one VRP
testcase to show up in real world code.  Because without
this patch, gfortran is pretty much useless on most real
world code.  I haven't checked 4.0.0 against my Fortran
testsuite; hopefully, this problem isn't present in 
gfortran's first exposure to the world.
Comment 15 Andrew Pinski 2005-04-23 15:15:07 UTC
(In reply to comment #14)
> I haven't checked 4.0.0 against my Fortran
> testsuite; hopefully, this problem isn't present in 
> gfortran's first exposure to the world.
It cannot be in 4.0.0 as the VRP code was just added in the last couple weeks.
Comment 16 Diego Novillo 2005-04-23 15:46:38 UTC
Subject: Re:  [4.1 Regression] ICE in set_value_range building 176.gcc with -O2

On Sat, Apr 23, 2005 at 03:11:52PM -0000, kargl at gcc dot gnu dot org wrote:
> 
> ------- Additional Comments From kargl at gcc dot gnu dot org  2005-04-23 15:11 -------
> (In reply to comment #13)
> > 
> > I would like to, but currently my patch causes a regression in one of
> > the VRP testcases.
> > 
Kazu, which test case is this?  Send me details?  I'll look at
this next week.  In the meantime, I would rather have sub-optimal
code than a broken FE.


> I haven't checked 4.0.0 against my Fortran
> testsuite; hopefully, this problem isn't present in 
> gfortran's first exposure to the world.
> 
No.  VRP is a 4.1 feature.


Diego.
Comment 17 Kazu Hirata 2005-04-24 14:02:20 UTC
I just went through the regression testing.  I get

FAIL: g++.dg/tree-ssa/pr18178.C scan-tree-dump-times if  1

It may be a good idea to check in this patch with the above testcase
XFAILed.
Comment 18 Kazu Hirata 2005-04-28 19:33:30 UTC
Diego,

I think it's OK to have contradictory information from an ASSERT_EXPR and
SCEV.

Let's say we have a loop counting from i = 0 upward.

It's possible that we "if (i < 0)" in the loop and see something like

  i_10 = ASSERT_EXPR <i_1, i_1 < 0>;

on the "then" arm of the conditional.  In this case, we know we are
counting upward, so SCEV tells us that the minimum value of i_10
should be 0, but the ASSERT_EXPR tells us that the range should be
[-INF, -1].  They are completely disjoint!

This weird situation comes from the fact that the "then" branch of the
conditional is dead.  In this case, probably the safest and simplest
thing to do is to ignoring what SCEV says.

Kazu Hirata
Comment 19 Francois-Xavier Coudert 2005-04-29 14:11:53 UTC
This breaks BLAS (optimzation >= -O2), the major Fortran library. The whole
fortran front-end is useless in this state.
Comment 20 Diego Novillo 2005-04-29 14:16:41 UTC
Working on it today.  Kazu, I hope you don't mind if I take it?
Comment 21 Kazu Hirata 2005-04-29 14:35:24 UTC
Diego, no, I don't mind.

But I have a patch whose bootstrap is almost over and
regression testing is about to start.

This patch does not break g++dg/tree-ssa/pr18178.C unlike my previous patch.

Let me attach my patch (and some analysis) just FWIW.

Comment 22 Kazu Hirata 2005-04-29 14:37:17 UTC
Created attachment 8764 [details]
an updated patch that does not break g++.dg/tree-ssa/pr18178.C
Comment 23 Diego Novillo 2005-04-29 14:46:29 UTC
Subject: Re:  [4.1 Regression] ICE in set_value_range building 176.gcc with -O2

On Fri, Apr 29, 2005 at 02:37:18PM -0000, kazu at cs dot umass dot edu wrote:
> 
> ------- Additional Comments From kazu at cs dot umass dot edu  2005-04-29 14:37 -------
> Created an attachment (id=8764)
>  --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8764&action=view)
> an updated patch that does not break g++.dg/tree-ssa/pr18178.C
> 
Kazu, did you mail your patch before attaching it to bugzilla?  I
haven't received it.  The same thing happened to your previous
patch for this PR and I missed it the first time.


Diego.
Comment 24 Kazu Hirata 2005-04-29 14:55:51 UTC
Subject: Re:  [4.1 Regression] ICE in
 set_value_range building 176.gcc with -O2

Hi Diego,

> Kazu, did you mail your patch before attaching it to bugzilla?  I
> haven't received it.  The same thing happened to your previous
> patch for this PR and I missed it the first time.

No, I did not send my previous to gcc-patches@ because I was not fully
satified with it.  Although I tested the patch, it broke pr18178.C,
and I did not analyze the failure at that time.

I have not sent my current patch to gcc-patches@ yet because I have
not finished testing it.  This time I will unless you beat me to it.

Kazu Hirata
Comment 25 Diego Novillo 2005-04-29 14:59:36 UTC
Subject: Re:  [4.1 Regression] ICE in set_value_range building 176.gcc with -O2

On Fri, Apr 29, 2005 at 02:55:58PM -0000, kazu at cs dot umass dot edu wrote:

> I have not sent my current patch to gcc-patches@ yet because I have
> not finished testing it.  This time I will unless you beat me to it.
> 
Oh, OK.  No, that's fine.  I'm now analyzing the test case.  I'll
check out your patch in a little while, if it matches what I
found, then it's OK to go in.


Diego.
Comment 26 Diego Novillo 2005-04-29 16:03:02 UTC
(In reply to comment #22)
> Created an attachment (id=8764)
> an updated patch that does not break g++.dg/tree-ssa/pr18178.C
> 

Kazu, your analysis is correct.  If this patch fixes the problem and passes
testing please commit it.


Diego.
Comment 27 Kazu Hirata 2005-04-29 16:25:31 UTC
Just checked in a patch.
Comment 28 Kazu Hirata 2005-04-29 16:27:28 UTC
Just checked in a patch.
Comment 29 GCC Commits 2005-04-29 16:29:02 UTC
Subject: Bug 21030

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	kazu@gcc.gnu.org	2005-04-29 16:23:20

Modified files:
	gcc            : ChangeLog tree-vrp.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/compile: pr21030.c 

Log message:
	gcc/
	PR tree-optimization/21030
	* tree-vrp.c (adjust_range_with_scev): Do not create invalid
	ranges where VR->MAX is smaller than VR->MIN.
	
	testsuite/
	PR tree-optimization/21030
	* gcc.dg/tree-ssa/pr21030.c: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8530&r2=2.8531
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-vrp.c.diff?cvsroot=gcc&r1=2.13&r2=2.14
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5417&r2=1.5418
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/pr21030.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 30 Rainer Orth 2005-04-29 19:57:42 UTC
Subject: Re:  [4.1 Regression] ICE in set_value_range building 176.gcc with -O2

Unfortunately, even with the patch applied, the Ada bootstrap failure on
i386-pc-solaris2.10 remains unchanged, a regression from 4.0:

stage1/xgcc -Bstage1/ -B/vol/gcc/share/i386-pc-solaris2.10/bin/ -c -g -O2      -gnatpg -gnata -I- -I. -Iada -I/vol/gnu/src/gcc/gcc-dist/gcc/ada /vol/gnu/src/gcc/gcc-dist/gcc/ada/sem_intr.adb -o ada/sem_intr.o
+===========================GNAT BUG DETECTED==============================+
| 4.1.0 20050429 (experimental) (i386-pc-solaris2.10) GCC error:           |
| in set_value_range, at tree-vrp.c:124                                    |
| Error detected at sem_intr.adb:437:1                                     |

	Rainer
Comment 31 Diego Novillo 2005-04-29 21:11:11 UTC
Subject: Re:  [4.1 Regression] ICE in set_value_range building 176.gcc with -O2

On Fri, Apr 29, 2005 at 07:57:43PM -0000, ro at techfak dot uni-bielefeld dot de wrote:
> 
> ------- Additional Comments From ro at techfak dot uni-bielefeld dot de  2005-04-29 19:57 -------
> Subject: Re:  [4.1 Regression] ICE in set_value_range building 176.gcc with -O2
> 
> Unfortunately, even with the patch applied, the Ada bootstrap failure on
> i386-pc-solaris2.10 remains unchanged, a regression from 4.0:
> 
> stage1/xgcc -Bstage1/ -B/vol/gcc/share/i386-pc-solaris2.10/bin/ -c -g -O2      -gnatpg -gnata -I- -I. -Iada -I/vol/gnu/src/gcc/gcc-dist/gcc/ada /vol/gnu/src/gcc/gcc-dist/gcc/ada/sem_intr.adb -o ada/sem_intr.o
> +===========================GNAT BUG DETECTED==============================+
> | 4.1.0 20050429 (experimental) (i386-pc-solaris2.10) GCC error:           |
> | in set_value_range, at tree-vrp.c:124                                    |
> | Error detected at sem_intr.adb:437:1                                     |
> 
> 	Rainer
> 
Huh.  Odd.  I just finished a bootstrap with

$ configure --enable-languages=c,ada
$ make bootstrap

on i686-pc-linux-gnu.


Diego.
Comment 32 Diego Novillo 2005-04-29 21:39:57 UTC
Subject: Re:  [4.1 Regression] ICE in set_value_range building 176.gcc with -O2

On Fri, Apr 29, 2005 at 09:11:12PM -0000, dnovillo at redhat dot com wrote:

> Huh.  Odd.  I just finished a bootstrap with
> 
> $ configure --enable-languages=c,ada
> $ make bootstrap
> 
> on i686-pc-linux-gnu.
> 
Just reproduced it with --target=i386-pc-linux-gnu.  Thanks
Andrew P. for pointing it out.  Will take a look.


Diego.
Comment 33 Diego Novillo 2005-05-02 15:29:57 UTC
Subject: Re:  [4.1 Regression] ICE in set_value_range building 176.gcc with -O2

On Fri, Apr 29, 2005 at 07:57:43PM -0000, ro at techfak dot uni-bielefeld dot de wrote:

> Unfortunately, even with the patch applied, the Ada bootstrap failure on
> i386-pc-solaris2.10 remains unchanged, a regression from 4.0:
> 
Would you mind filing a separate PR?  This is a different
problem.  The Ada FE is emitting a seemingly always-false
predicate that is causing VRP to create an invalid range
(http://gcc.gnu.org/ml/gcc/2005-05/msg00049.html).


Thanks.  Diego.
Comment 34 Andrew Pinski 2005-05-04 15:05:44 UTC
*** Bug 21381 has been marked as a duplicate of this bug. ***