public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fold VEC_[LR]SHIFT_EXPR (PR tree-optimization/57051)
@ 2013-04-26  0:32 Jakub Jelinek
  2013-04-26 11:06 ` Richard Biener
  2013-05-03 13:18 ` Jakub Jelinek
  0 siblings, 2 replies; 6+ messages in thread
From: Jakub Jelinek @ 2013-04-26  0:32 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

This patch adds folding of constant arguments v>> and v<<, which helps to
optimize the testcase from the PR back into constant store after vectorized
loop is unrolled.

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

2013-04-25  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/57051
	* fold-const.c (const_binop): Handle VEC_LSHIFT_EXPR
	and VEC_RSHIFT_EXPR if shift count is a multiple of element
	bitsize.

--- gcc/fold-const.c.jj	2013-04-12 10:16:25.000000000 +0200
+++ gcc/fold-const.c	2013-04-24 12:37:11.789122719 +0200
@@ -1380,17 +1380,42 @@ const_binop (enum tree_code code, tree a
       int count = TYPE_VECTOR_SUBPARTS (type), i;
       tree *elts = XALLOCAVEC (tree, count);
 
-      for (i = 0; i < count; i++)
+      if (code == VEC_LSHIFT_EXPR
+	  || code == VEC_RSHIFT_EXPR)
 	{
-	  tree elem1 = VECTOR_CST_ELT (arg1, i);
-
-	  elts[i] = const_binop (code, elem1, arg2);
+	  if (!host_integerp (arg2, 1))
+	    return NULL_TREE;
 
-	  /* It is possible that const_binop cannot handle the given
-	     code and return NULL_TREE */
-	  if (elts[i] == NULL_TREE)
+	  unsigned HOST_WIDE_INT shiftc = tree_low_cst (arg2, 1);
+	  unsigned HOST_WIDE_INT outerc = tree_low_cst (TYPE_SIZE (type), 1);
+	  unsigned HOST_WIDE_INT innerc
+	    = tree_low_cst (TYPE_SIZE (TREE_TYPE (type)), 1);
+	  if (shiftc >= outerc || (shiftc % innerc) != 0)
 	    return NULL_TREE;
+	  int offset = shiftc / innerc;
+	  if (code == VEC_LSHIFT_EXPR)
+	    offset = -offset;
+	  tree zero = build_zero_cst (TREE_TYPE (type));
+	  for (i = 0; i < count; i++)
+	    {
+	      if (i + offset < 0 || i + offset >= count)
+		elts[i] = zero;
+	      else
+		elts[i] = VECTOR_CST_ELT (arg1, i + offset);
+	    }
 	}
+      else
+	for (i = 0; i < count; i++)
+	  {
+	    tree elem1 = VECTOR_CST_ELT (arg1, i);
+
+	    elts[i] = const_binop (code, elem1, arg2);
+
+	    /* It is possible that const_binop cannot handle the given
+	       code and return NULL_TREE */
+	    if (elts[i] == NULL_TREE)
+	      return NULL_TREE;
+	  }
 
       return build_vector (type, elts);
     }

	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-17  8:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-26  0:32 [PATCH] Fold VEC_[LR]SHIFT_EXPR (PR tree-optimization/57051) Jakub Jelinek
2013-04-26 11:06 ` Richard Biener
2013-05-03 13:18 ` Jakub Jelinek
2013-05-16 18:01   ` Mikael Pettersson
2013-05-17  6:48     ` [PATCH] Fix VEC_[LR]SHIFT_EXPR folding for big-endian " Jakub Jelinek
2013-05-17  8:02       ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).