This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Thu, 6 Jul 2006, Mark Mitchell wrote:

> Richard Guenther wrote:
> 
> > So, what do you want me to do?
> 
> Please add the build_one_cst (or whatever spelling is agreed upon).
> Converting scalars to vectors is something that front ends should do, if
> appropriate; I don't think it's something that the middle end should
> ever be doing (except, perhaps, when vectorizing!), and so not something
> that belongs in fold_convert, ideally.

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

Ok for mainline?

Thanks,
Richard.

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

	PR middle-end/28268
	* tree.h (build_one_cst): Declare.
	* tree.c (build_one_cst): New function.
	* tree-ssa-math-opts.c (get_constant_one): Remove.
	(insert_reciprocals): Use build_one_cst.
	* fold-const.c (fold_plusminus_mult): Likewise.

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

Index: tree.h
===================================================================
*** tree.h	(revision 115221)
--- tree.h	(working copy)
*************** extern tree build_constructor_single (tr
*** 3534,3539 ****
--- 3534,3540 ----
  extern tree build_constructor_from_list (tree, tree);
  extern tree build_real_from_int_cst (tree, tree);
  extern tree build_complex (tree, tree, tree);
+ extern tree build_one_cst (tree);
  extern tree build_string (int, const char *);
  extern tree build_tree_list_stat (tree, tree MEM_STAT_DECL);
  #define build_tree_list(t,q) build_tree_list_stat(t,q MEM_STAT_INFO)
Index: tree-ssa-math-opts.c
===================================================================
*** tree-ssa-math-opts.c	(revision 115221)
--- tree-ssa-math-opts.c	(working copy)
*************** is_division_by (tree use_stmt, tree def)
*** 279,313 ****
  	 && TREE_OPERAND (TREE_OPERAND (use_stmt, 1), 1) == def;
  }
  
- /* Return the LHS of a RDIV_EXPR that computes a reciprocal in type TYPE.  */
- static tree
- get_constant_one (tree type)
- {
-   tree scalar, cst;
-   int i;
- 
-   gcc_assert (FLOAT_TYPE_P (type));
-   switch (TREE_CODE (type))
-     {
-     case REAL_TYPE:
-       return build_real (type, dconst1);
- 
-     case VECTOR_TYPE:
-       scalar = build_real (TREE_TYPE (type), dconst1);
- 
-       /* Create 'vect_cst_ = {cst,cst,...,cst}'  */
-       cst = NULL_TREE;
-       for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
-         cst = tree_cons (NULL_TREE, scalar, cst);
- 
-       return build_vector (type, cst);
- 
-     default:
-       /* Complex operations have been split already.  */
-       gcc_unreachable ();
-     }
- }
- 
  /* Walk the subset of the dominator tree rooted at OCC, setting the
     RECIP_DEF field to a definition of 1.0 / DEF that can be used in
     the given basic block.  The field may be left NULL, of course,
--- 279,284 ----
*************** insert_reciprocals (block_stmt_iterator 
*** 333,339 ****
        type = TREE_TYPE (def);
        recip_def = make_rename_temp (type, "reciptmp");
        new_stmt = build2 (MODIFY_EXPR, void_type_node, recip_def,
! 		         fold_build2 (RDIV_EXPR, type, get_constant_one (type),
  				      def));
    
    
--- 304,310 ----
        type = TREE_TYPE (def);
        recip_def = make_rename_temp (type, "reciptmp");
        new_stmt = build2 (MODIFY_EXPR, void_type_node, recip_def,
! 		         fold_build2 (RDIV_EXPR, type, build_one_cst (type),
  				      def));
    
    
Index: fold-const.c
===================================================================
*** fold-const.c	(revision 115221)
--- fold-const.c	(working copy)
*************** fold_plusminus_mult_expr (enum tree_code
*** 6727,6733 ****
    else
      {
        arg00 = arg0;
!       arg01 = fold_convert (type, integer_one_node);
      }
    if (TREE_CODE (arg1) == MULT_EXPR)
      {
--- 6727,6733 ----
    else
      {
        arg00 = arg0;
!       arg01 = build_one_cst (type);
      }
    if (TREE_CODE (arg1) == MULT_EXPR)
      {
*************** fold_plusminus_mult_expr (enum tree_code
*** 6737,6743 ****
    else
      {
        arg10 = arg1;
!       arg11 = fold_convert (type, integer_one_node);
      }
    same = NULL_TREE;
  
--- 6737,6743 ----
    else
      {
        arg10 = arg1;
!       arg11 = build_one_cst (type);
      }
    same = NULL_TREE;
  
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;
+ }
Index: tree.c
===================================================================
*** tree.c	(revision 115221)
--- tree.c	(working copy)
*************** build_complex (tree type, tree real, tre
*** 1161,1166 ****
--- 1161,1207 ----
    return t;
  }
  
+ /* Return a constant of arithmetic type TYPE which is the
+    multiplcative identity of the set TYPE.  */
+ 
+ tree
+ build_one_cst (tree type)
+ {
+   switch (TREE_CODE (type))
+     {
+     case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
+     case POINTER_TYPE: case REFERENCE_TYPE:
+     case OFFSET_TYPE:
+       return build_int_cst (type, 1);
+ 
+     case REAL_TYPE:
+       return build_real (type, dconst1);
+ 
+     case VECTOR_TYPE:
+       {
+ 	tree scalar, cst;
+ 	int i;
+ 
+ 	scalar = build_one_cst (TREE_TYPE (type));
+ 
+ 	/* Create 'vect_cst_ = {cst,cst,...,cst}'  */
+ 	cst = NULL_TREE;
+ 	for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
+ 	  cst = tree_cons (NULL_TREE, scalar, cst);
+ 
+ 	return build_vector (type, cst);
+       }
+ 
+     case COMPLEX_TYPE:
+       return build_complex (type,
+ 			    build_one_cst (TREE_TYPE (type)),
+ 			    fold_convert (TREE_TYPE (type), integer_zero_node));
+ 
+     default:
+       gcc_unreachable ();
+     }
+ }
+ 
  /* Build a BINFO with LEN language slots.  */
  
  tree


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]