[PATCH] Fix PR28268, ICE building vector const { 1, 1 }

Richard Guenther rguenther@suse.de
Thu Jul 6 10:21:00 GMT 2006


This fixes PR28268 by teaching fold_convert to build a vector const { 1, 
1 }.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for mainline?

Thanks,
Richard.

:ADDPATCH middle-end:

2006-07-07  Richard Guenther  <rguenther@suse.de>

	PR middle-end/28268
	* fold-const.c (build_zero_vector): Rename to ...
	(build_cst_vector): ... this.  Handle any constants to
	build the vector.
	(fold_convert): Use it to also allow (vector) 1.

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

Index: fold-const.c
===================================================================
*** fold-const.c	(revision 115202)
--- fold-const.c	(working copy)
*************** fold_convert_const (enum tree_code code,
*** 1956,1970 ****
    return NULL_TREE;
  }
  
! /* Construct a vector of zero elements of vector type TYPE.  */
  
  static tree
! build_zero_vector (tree type)
  {
!   tree elem, list;
    int i, units;
  
!   elem = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node);
    units = TYPE_VECTOR_SUBPARTS (type);
    
    list = NULL_TREE;
--- 1956,1970 ----
    return NULL_TREE;
  }
  
! /* Construct a vector of ELEM elements of vector type TYPE.  */
  
  static tree
! build_cst_vector (tree type, tree elem)
  {
!   tree list;
    int i, units;
  
!   elem = fold_convert_const (NOP_EXPR, TREE_TYPE (type), elem);
    units = TYPE_VECTOR_SUBPARTS (type);
    
    list = NULL_TREE;
*************** fold_convert (tree type, tree arg)
*** 2084,2091 ****
  	}
  
      case VECTOR_TYPE:
!       if (integer_zerop (arg))
! 	return build_zero_vector (type);
        gcc_assert (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
        gcc_assert (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
  		  || TREE_CODE (orig) == VECTOR_TYPE);
--- 2084,2092 ----
  	}
  
      case VECTOR_TYPE:
!       if (integer_zerop (arg)
! 	  || integer_onep (arg))
! 	return build_cst_vector (type, arg);
        gcc_assert (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
        gcc_assert (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
  		  || TREE_CODE (orig) == VECTOR_TYPE);
Index: testsuite/gcc.dg/torture/pr28268.c
===================================================================
*** testsuite/gcc.dg/torture/pr28268.c	(revision 0)
--- testsuite/gcc.dg/torture/pr28268.c	(revision 0)
***************
*** 0 ****
--- 1,8 ----
+ /* { dg-do compile } */
+ 
+ int __attribute__((vector_size(8))) a;
+ 
+ void foo()
+ {
+     a += a*a;
+ }



More information about the Gcc-patches mailing list