Bug 33373

Summary: [4.3 Regression] ICE in vectorizable_type_demotion, at tree-vect-transform.c:4098
Product: gcc Reporter: marcus
Component: tree-optimizationAssignee: dorit
Status: RESOLVED FIXED    
Severity: normal CC: belyshev, gcc-bugs, pinskia
Priority: P3 Keywords: ice-on-valid-code
Version: 4.3.0   
Target Milestone: 4.3.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2007-09-14 19:15:21
Attachments: dosmem.i

Description marcus 2007-09-10 05:41:36 UTC
current SVN:

/home/marcus/projects/gcc/BIN/bin/gcc -m32 -c -O3 -ftree-vectorize -msse3   dosmem.i 
dosmem.i: In function 'DOSMEM_FillIsrTable':
dosmem.i:1: internal compiler error: in vectorizable_type_demotion, at tree-vect-transform.c:4098
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 marcus 2007-09-10 05:41:53 UTC
Created attachment 14181 [details]
dosmem.i
Comment 2 dorit 2007-09-10 09:08:07 UTC
Testing this patch (it's a bug in the fix for PR33301. I accidentally treated TYPE_SIZE_UNIT as a constant, whereas it's really a tree...):

Index: tree-vect-analyze.c
===================================================================
*** tree-vect-analyze.c (revision 128322)
--- tree-vect-analyze.c (working copy)
*************** vect_determine_vectorization_factor (loo
*** 242,252 ****
              operation = GIMPLE_STMT_OPERAND (stmt, 1);
              if (TREE_CODE (operation) == NOP_EXPR
                  || TREE_CODE (operation) == CONVERT_EXPR
!                 || TREE_CODE (operation) ==  WIDEN_MULT_EXPR)
                {
                  tree rhs_type = TREE_TYPE (TREE_OPERAND (operation, 0));
!                 if (TYPE_SIZE_UNIT (rhs_type) < TYPE_SIZE_UNIT (scalar_type))
!                   scalar_type = TREE_TYPE (TREE_OPERAND (operation, 0));
                }

              if (vect_print_dump_info (REPORT_DETAILS))
--- 242,253 ----
              operation = GIMPLE_STMT_OPERAND (stmt, 1);
              if (TREE_CODE (operation) == NOP_EXPR
                  || TREE_CODE (operation) == CONVERT_EXPR
!                 || TREE_CODE (operation) == WIDEN_MULT_EXPR)
                {
                  tree rhs_type = TREE_TYPE (TREE_OPERAND (operation, 0));
!                 if (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (rhs_type)) <
!                     TREE_INT_CST_LOW (TYPE_SIZE_UNIT (scalar_type)))
!                   scalar_type = rhs_type;
                }

              if (vect_print_dump_info (REPORT_DETAILS))
Comment 3 dorit 2007-09-12 07:10:01 UTC
Subject: Bug 33373

Author: dorit
Date: Wed Sep 12 07:09:38 2007
New Revision: 128415

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128415
Log:
        PR tree-optimization/33373
        * tree-vect-analyze (vect_determine_vectorization_factor): Call
        TREE_INT_CST_LOW when comparing TYPE_SIZE_UNIT.


Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr33373.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vect-analyze.c

Comment 4 Serge Belyshev 2007-09-14 19:15:20 UTC
Very similar testcase with the difference that it is not fixed by r128415 and makes current trunk segfault in VEC_tree_base_pop():

void f (unsigned int *d, unsigned int *s, int w)
{
  int i;
  for (i = 0; i < w; ++i)
    d [i] = s [i] * (unsigned short) (~d [i] >> 24);
}
Comment 5 dorit 2007-09-14 20:53:18 UTC
(In reply to comment #4)
> Very similar testcase with the difference that it is not fixed by r128415 and
> makes current trunk segfault in VEC_tree_base_pop():
> void f (unsigned int *d, unsigned int *s, int w)
> {
>   int i;
>   for (i = 0; i < w; ++i)
>     d [i] = s [i] * (unsigned short) (~d [i] >> 24);
> }

this should fix it:

Index: tree-vect-transform.c
===================================================================
*** tree-vect-transform.c       (revision 128501)
--- tree-vect-transform.c       (working copy)
*************** vect_get_vec_defs_for_stmt_copy (enum ve
*** 1938,1944 ****
    vec_oprnd = vect_get_vec_def_for_stmt_copy (dt[0], vec_oprnd);
    VEC_quick_push (tree, *vec_oprnds0, vec_oprnd);

!   if (vec_oprnds1)
      {
        vec_oprnd = VEC_pop (tree, *vec_oprnds1);
        vec_oprnd = vect_get_vec_def_for_stmt_copy (dt[1], vec_oprnd);
--- 1938,1944 ----
    vec_oprnd = vect_get_vec_def_for_stmt_copy (dt[0], vec_oprnd);
    VEC_quick_push (tree, *vec_oprnds0, vec_oprnd);

!   if (vec_oprnds1 && *vec_oprnds1)
      {
        vec_oprnd = VEC_pop (tree, *vec_oprnds1);
        vec_oprnd = vect_get_vec_def_for_stmt_copy (dt[1], vec_oprnd);

(and by the way, I think this is a totally different issue than what this PR was originally opened for, and should be a separate PR. I think this regression is due to r128289)
Comment 6 Serge Belyshev 2007-09-15 21:54:04 UTC
Fixed.

http://gcc.gnu.org/viewcvs?view=rev&revision=128514