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]

[PATCH] Fold REDUC_*_EXPR


Hi!

This patch folds REDUC_*_EXPR (e.g. on pr54877.c -Ofast -mavx
testcase we end up with unfolded REDUC_PLUS_EXPR till *.optimized).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2012-10-10  Jakub Jelinek  <jakub@redhat.com>

	* fold-const.c (fold_unary_loc): Handle REDUC_MIN_EXPR,
	REDUC_MAX_EXPR and REDUC_PLUS_EXPR.

--- gcc/fold-const.c.jj	2012-10-09 13:42:30.000000000 +0200
+++ gcc/fold-const.c	2012-10-10 12:28:11.768999520 +0200
@@ -8294,6 +8294,40 @@ fold_unary_loc (location_t loc, enum tre
 	return build_vector (type, elts);
       }
 
+    case REDUC_MIN_EXPR:
+    case REDUC_MAX_EXPR:
+    case REDUC_PLUS_EXPR:
+      {
+	unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i;
+	tree *elts;
+	enum tree_code subcode;
+
+	if (TREE_CODE (op0) != VECTOR_CST)
+	  return NULL_TREE;
+
+	elts = XALLOCAVEC (tree, nelts);
+	if (!vec_cst_ctor_to_array (op0, elts))
+	  return NULL_TREE;
+
+	switch (code)
+	  {
+	  case REDUC_MIN_EXPR: subcode = MIN_EXPR; break;
+	  case REDUC_MAX_EXPR: subcode = MAX_EXPR; break;
+	  case REDUC_PLUS_EXPR: subcode = PLUS_EXPR; break;
+	  default: gcc_unreachable ();
+	  }
+
+	for (i = 1; i < nelts; i++)
+	  {
+	    elts[0] = const_binop (subcode, elts[0], elts[i]);
+	    if (elts[0] == NULL_TREE || !CONSTANT_CLASS_P (elts[0]))
+	      return NULL_TREE;
+	    elts[i] = build_zero_cst (TREE_TYPE (type));
+	  }
+
+	return build_vector (type, elts);
+      }
+
     default:
       return NULL_TREE;
     } /* switch (code) */

	Jakub


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