Bug 55684 - [4.8 Regression] ICE in remove_redundant_iv_tests, at tree-ssa-loop-ivcanon.c:559
Summary: [4.8 Regression] ICE in remove_redundant_iv_tests, at tree-ssa-loop-ivcanon.c...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
: 55208 55697 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-12-14 09:01 UTC by Richard Biener
Modified: 2012-12-18 07:47 UTC (History)
4 users (show)

See Also:
Host:
Target: i?86-*-*, x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-12-14 00:00:00


Attachments
preprocessed source (17.70 KB, application/octet-stream)
2012-12-14 09:01 UTC, Richard Biener
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2012-12-14 09:01:17 UTC
/usr/lib/gcc/i586-suse-linux/4.8/cc1 -fpreprocessed fileio.i -quiet -dumpbase fileio.c -mtune=generic -march=i586 -auxbase-strip libavrdude_a-fileio.o -g -O2 -Wno-pointer-sign -Wall -version -fomit-frame-pointer -fmessage-length=0 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -o fileio.s
GNU C (SUSE Linux) version 4.8.0 20121212 [trunk revision 194442] (i586-suse-linux)
        compiled by GNU C version 4.8.0 20121212 [trunk revision 194442], GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C (SUSE Linux) version 4.8.0 20121212 [trunk revision 194442] (i586-suse-linux)
        compiled by GNU C version 4.8.0 20121212 [trunk revision 194442], GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: e68fcd130690afd931631ae80bbb1d1f
fileio.c: In function 'ihex2b':
fileio.c:264:12: internal compiler error: in remove_redundant_iv_tests, at tree-ssa-loop-ivcanon.c:559
 static int ihex2b(char * infile, FILE * inf,
            ^
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugs.opensuse.org/> for instructions.
Comment 1 Richard Biener 2012-12-14 09:01:42 UTC
Created attachment 28950 [details]
preprocessed source
Comment 2 Richard Biener 2012-12-14 10:16:57 UTC
Reduced testcase:

typedef struct _IO_FILE FILE;
unsigned long int strtoul(const char *, char **, int);
char *fgets(char *, int, FILE *);
struct ihexrec {
    unsigned char reclen;
    unsigned char data[256];
};
static void srec_readrec(struct ihexrec * srec, char * rec)
{
  int i, j;
  char buf[8];
  int offset = 0, len;
  char * e;
  for (i=0; j<srec->reclen; j++)
    {
      if (offset+2 > len)
        return;
      for (i=0; i<2; i++)
        buf[i] = rec[offset++];
      srec->data[j] = strtoul(buf, &e, 16);
    }
  for (i=0; i<2; i++)
    buf[i] = rec[offset++];
}
void srec2b(FILE *inf)
{
  char buffer[256];
  struct ihexrec srec;
  while (fgets(buffer,256,inf)!=(void *)0)
    srec_readrec(&srec, buffer);
}

> ./cc1 -quiet -O2 fileio.3.3.i
fileio.3.3.i: In function 'srec2b':
fileio.3.3.i:25:6: internal compiler error: in remove_redundant_iv_tests, at tree-ssa-loop-ivcanon.c:559
 void srec2b(FILE *inf)
      ^
Comment 3 Jakub Jelinek 2012-12-14 10:46:55 UTC
Caused by http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193098
Comment 4 Richard Biener 2012-12-14 11:50:23 UTC
ICEing here is of course pointless.  Looks like a debugging leftover to me.

First when in estimate_numbers_of_iterations_loop, number_of_iterations_exit
succeeds, then in find_loop_niter called from canonicalize_loop_induction_variables it fails, so does it when called
from remove_redundant_iv_tests for that loop.

So it's quite by design that this can happen.  Testing the obvious patch.
Comment 5 Marek Polacek 2012-12-14 12:06:35 UTC
More reduced.

struct s { int data[1]; };

static void
bar (struct s *s, int *p)
{
  int i, o;
  while (i++)
    {
      if (o > 0)
	return;
      for (i = 0; i < 1; i++)
	p[o++];
      s->data[o] = baz ();
    }
}

void
foo ()
{
  struct s s;
  bar (&s, 0);
}
Comment 6 Richard Biener 2012-12-14 13:35:09 UTC
Author: rguenth
Date: Fri Dec 14 13:35:03 2012
New Revision: 194499

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194499
Log:
2012-12-14  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/55684
	* tree-ssa-loop-ivcanon.c (remove_redundant_iv_tests): Handle
	gracefully the case where we cannot compute the number of
	iterations at an exit.

	* gcc.dg/torture/pr55684.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr55684.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-loop-ivcanon.c
Comment 7 Richard Biener 2012-12-14 13:35:34 UTC
Fixed.
Comment 8 Jan Hubicka 2012-12-14 18:36:48 UTC
> First when in estimate_numbers_of_iterations_loop, number_of_iterations_exit
> succeeds, then in find_loop_niter called from
> canonicalize_loop_induction_variables it fails, so does it when called
> from remove_redundant_iv_tests for that loop.

It is a debugging lefover.  At the time I wrote the code we was inserting the
exits into upper bound list only when precise number of iterations was
determined at given time.  Sure we can also insert upper bounds there, but I
think we still don't.  Why number_of_iterations_exit changed the mind?

Honza
Comment 9 Andrew Pinski 2012-12-15 10:29:21 UTC
*** Bug 55697 has been marked as a duplicate of this bug. ***
Comment 10 Jakub Jelinek 2012-12-18 07:47:42 UTC
*** Bug 55208 has been marked as a duplicate of this bug. ***