Bug 26969 - [4.1 Regression] ICE with -O1 -funswitch-loops -ftree-vectorize
Summary: [4.1 Regression] ICE with -O1 -funswitch-loops -ftree-vectorize
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.1.2
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, monitored, patch
Depends on:
Blocks:
 
Reported: 2006-04-01 00:06 UTC by Mark Loeser
Modified: 2006-10-19 14:58 UTC (History)
10 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.4 4.2.0
Known to fail: 4.1.0
Last reconfirmed: 2006-05-21 20:59:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Loeser 2006-04-01 00:06:48 UTC
With the following code gcc-4.1 and 4.2 ICE when using "-O3 -ftree-vectorize".  The latest checkout I have of 4.0 worked just fine.

struct re_pattern_buffer
{
  char *buffer;
  char *fastmap;
  long options;
};
void
ruby_re_compile_fastmap (struct re_pattern_buffer *bufp)
{
  unsigned char *pattern = (unsigned char *) bufp->buffer;
  register char *fastmap = bufp->fastmap;
  register unsigned char *p = pattern;
  register int j;
  int options = bufp->options;
  while (p)
    {
      switch (*p++)
    {
    case 0:
      for (j = 0; j < (1 << 8); j++)
        {
          if (j != '\n' || (options & (((1L) << 1) << 1)))
        fastmap[j] = 1;
        }
    }
    }
}

gcc version 4.2.0 20060331 (experimental)

gcc -O3 -ftree-vectorize ruby.c -c

ruby.x.i: In function ‘ruby_re_compile_fastmap’:
ruby.x.i:9: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions
Comment 1 Andrew Pinski 2006-04-01 00:52:54 UTC
Confirmed, reduced testcase:
void
ruby_re_compile_fastmap (char *fastmap, int options)
{
  int j;
  for (j = 0; j < (1 << 8); j++)
   {
     if (j != '\n' || (options & 4))
        fastmap[j] = 1;
   }
}

-----
you can get the error with -O1 -funswitch-loops -ftree-vectorize
Comment 2 Richard Biener 2006-04-27 10:38:47 UTC
We ICE in rename_use_op on

  if (TREE_CODE (USE_FROM_PTR (op_p)) != SSA_NAME)
    return;

because *op_p->use is NULL and the stmt is broken:

(gdb) call debug_generic_expr(op_p->stmt)
SMT.6D.1867_40 = PHI <(13)>;

#0  0x081ed569 in rename_use_op (op_p=0xb7de40a0)
    at /space/rguenther/src/svn/trunk/gcc/tree-vectorizer.c:201
#1  0x081ed840 in rename_variables_in_bb (bb=0xb7d35a50)
    at /space/rguenther/src/svn/trunk/gcc/tree-vectorizer.c:243
#2  0x081ee0d4 in rename_variables_in_loop (loop=0x896e8f0)
    at /space/rguenther/src/svn/trunk/gcc/tree-vectorizer.c:259
#3  0x081eff18 in slpeel_tree_peel_loop_to_edge (loop=0x8961658, 
    loops=0x8948690, e=0xb7dd6820, first_niters=0xb7de3138, niters=0xb7dded68, 
    update_first_loop_count=1 '\001')
    at /space/rguenther/src/svn/trunk/gcc/tree-vectorizer.c:1135
#4  0x08203066 in vect_do_peeling_for_alignment (loop_vinfo=0x895ff18, 
    loops=0x8948690)
    at /space/rguenther/src/svn/trunk/gcc/tree-vect-transform.c:2813
#5  0x08203978 in vect_transform_loop (loop_vinfo=0x895ff18, loops=0x8948690)
    at /space/rguenther/src/svn/trunk/gcc/tree-vect-transform.c:3045
#6  0x081f29e5 in vectorize_loops (loops=0x8948690)
    at /space/rguenther/src/svn/trunk/gcc/tree-vectorizer.c:2046
#7  0x081dbdf1 in tree_vectorize ()
Comment 3 Richard Biener 2006-04-27 11:05:10 UTC
slpeel_update_phis_for_duplicate_loop does not do its job properly.  It fails to
update the PHI nodes of at least the new loops latch block:

(gdb) call debug_bb (new_loop->latch)
;; basic block 14, loop depth 1, count 0
;; prev block 13, next block 4
;; pred:       13 [98.8%]  (dfs_back,true,exec)
;; succ:       13 [100.0%]  (fallthru,exec)
# SMT.6_40 = PHI <(13)>;
# j_41 = PHI <(13)>;
<L23>:;
goto <bb 13> (<L24>);
Comment 4 Mark Mitchell 2006-05-25 02:31:42 UTC
Will not be fixed in 4.1.1; adjust target milestone to 4.1.2.
Comment 5 Victor Kaplansky 2006-06-07 20:47:12 UTC
This happens because (vect_do_peeling_for_alignment) was designed in an assumption that latch is empty. Thus it doesn't handle PHIs in latches. (vect_analyze_loop_form) checks the latch is empty, but doesn't check that list of
its PHIs is empty as too.
Comment 6 Victor Kaplansky 2006-06-07 21:29:46 UTC
patch: http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00376.html
Comment 7 patchapp@dberlin.org 2006-06-08 02:48:04 UTC
Subject: Bug number PR tree-optimizations/26969

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00376.html
Comment 8 patchapp@dberlin.org 2006-08-01 11:45:17 UTC
Subject: Bug number PR tree-optimizations/26969

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00006.html
Comment 9 victork 2006-08-07 11:28:41 UTC
Subject: Bug 26969

Author: victork
Date: Mon Aug  7 11:28:31 2006
New Revision: 115995

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115995
Log:
ChangeLog
        PR tree-optimization/26969
        * tree-vect-analyze.c (vect_analyze_loop_form): Add check of latch
         witch an empty list of PHIs.

testsuite/Changelog:
        PR tree-optimizations/26969
        * gcc.dg/vect/vect.exp: Compile tests prefixed with
	"unswitch-loops" with -funswitch-loops.
        * gcc.dg/vect/unswitch-loops-pr26969.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/vect/unswitch-loops-pr26969.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/vect/vect.exp
    trunk/gcc/tree-vect-analyze.c

Comment 10 Dorit Naishlos 2006-08-31 08:22:18 UTC
I think this can be closed?
(I opened a missed-optimization PR instead - PR28643)

Comment 11 Andrew Pinski 2006-08-31 10:34:03 UTC
(In reply to comment #10)
> I think this can be closed?
Except we still crash on the 4.1 branch.
Comment 12 Dorit Naishlos 2006-09-01 05:43:48 UTC
oops - I didn't notice it was open against 4.1.
So hopefully porting Victor's patch to 4.1 would fix it.
Comment 13 Victor Kaplansky 2006-09-03 07:51:21 UTC
this bug looks very similar to PR28839 which already have a fix in
patch http://gcc.gnu.org/ml/gcc-patches/2006-08/msg01171.html

We need to check if above patch fixes PR26969 as well.
Comment 14 Victor Kaplansky 2006-09-11 08:16:56 UTC
I will look if patch http://gcc.gnu.org/ml/gcc-patches/2006-08/msg01171.html
fixes this one too and will remap it to 4.1

Comment 15 Ira Rosen 2006-10-18 11:03:55 UTC
(In reply to comment #13)
> We need to check if above patch fixes PR26969 as well.

Checked, it does not.
Comment 16 irar 2006-10-19 11:18:36 UTC
Subject: Bug 26969

Author: irar
Date: Thu Oct 19 11:18:25 2006
New Revision: 117883

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117883
Log:
        Backport from mainline:
        2006-08-07  Victor Kaplansky <victork@il.ibm.com>

        PR tree-optimization/26969
        * tree-vect-analyze.c (vect_analyze_loop_form): Add check of latch
        with an empty list of PHIs.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/vect/unswitch-loops-pr26969.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/vect/vect.exp
    branches/gcc-4_1-branch/gcc/tree-vect-analyze.c

Comment 17 Andrew Pinski 2006-10-19 14:58:01 UTC
Fixed.