diff mbox

Improve trivial foldings with VECTOR_CSTs

Message ID alpine.LNX.2.00.1203051227340.18230@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener March 5, 2012, 11:28 a.m. UTC
This handles VECTOR_CSTs in integer_zerop, integer_onep and 
integer_all_onesp to allow trivial foldings to work on them.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2012-03-05  Richard Guenther  <rguenther@suse.de>

	* tree.c (integer_zerop): Handle VECTOR_CSTs.
	(integer_onep): Likewise.
	(integer_all_onesp): Likewise.
diff mbox

Patch

Index: gcc/tree.c
===================================================================
--- gcc/tree.c	(revision 184390)
+++ gcc/tree.c	(working copy)
@@ -1714,12 +1714,25 @@  integer_zerop (const_tree expr)
 {
   STRIP_NOPS (expr);
 
-  return ((TREE_CODE (expr) == INTEGER_CST
-	   && TREE_INT_CST_LOW (expr) == 0
-	   && TREE_INT_CST_HIGH (expr) == 0)
-	  || (TREE_CODE (expr) == COMPLEX_CST
-	      && integer_zerop (TREE_REALPART (expr))
-	      && integer_zerop (TREE_IMAGPART (expr))));
+  switch (TREE_CODE (expr))
+    {
+    case INTEGER_CST:
+      return (TREE_INT_CST_LOW (expr) == 0
+	      && TREE_INT_CST_HIGH (expr) == 0);
+    case COMPLEX_CST:
+      return (integer_zerop (TREE_REALPART (expr))
+	      && integer_zerop (TREE_IMAGPART (expr)));
+    case VECTOR_CST:
+      {
+	tree elt;
+	for (elt = TREE_VECTOR_CST_ELTS (expr); elt; elt = TREE_CHAIN (elt))
+	  if (!integer_zerop (TREE_VALUE (elt)))
+	    return false;
+	return true;
+      }
+    default:
+      return false;
+    }
 }
 
 /* Return 1 if EXPR is the integer constant one or the corresponding
@@ -1730,12 +1743,25 @@  integer_onep (const_tree expr)
 {
   STRIP_NOPS (expr);
 
-  return ((TREE_CODE (expr) == INTEGER_CST
-	   && TREE_INT_CST_LOW (expr) == 1
-	   && TREE_INT_CST_HIGH (expr) == 0)
-	  || (TREE_CODE (expr) == COMPLEX_CST
-	      && integer_onep (TREE_REALPART (expr))
-	      && integer_zerop (TREE_IMAGPART (expr))));
+  switch (TREE_CODE (expr))
+    {
+    case INTEGER_CST:
+      return (TREE_INT_CST_LOW (expr) == 1
+	      && TREE_INT_CST_HIGH (expr) == 0);
+    case COMPLEX_CST:
+      return (integer_onep (TREE_REALPART (expr))
+	      && integer_zerop (TREE_IMAGPART (expr)));
+    case VECTOR_CST:
+      {
+	tree elt;
+	for (elt = TREE_VECTOR_CST_ELTS (expr); elt; elt = TREE_CHAIN (elt))
+	  if (!integer_onep (TREE_VALUE (elt)))
+	    return false;
+	return true;
+      }
+    default:
+      return false;
+    }
 }
 
 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
@@ -1754,6 +1780,15 @@  integer_all_onesp (const_tree expr)
       && integer_zerop (TREE_IMAGPART (expr)))
     return 1;
 
+  else if (TREE_CODE (expr) == VECTOR_CST)
+    {
+      tree elt;
+      for (elt = TREE_VECTOR_CST_ELTS (expr); elt; elt = TREE_CHAIN (elt))
+	if (!integer_all_onesp (TREE_VALUE (elt)))
+	  return 0;
+      return 1;
+    }
+
   else if (TREE_CODE (expr) != INTEGER_CST)
     return 0;