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] BIT_FIELD_REF on VECTOR_CST


Hi!

Is BIT_FIELD_REF supposed to be valid on trees other than
structures and unions?  tree-complex.c seems to assume that it is,
but it is not documented in tree.def:
/* Reference to a group of bits within an object.  Similar to COMPONENT_REF
   except the position is given explicitly rather than via a FIELD_DECL.
   Operand 0 is the structure or union expression;
   operand 1 is a tree giving the number of bits being referenced;
   operand 2 is a tree giving the position of the first referenced bit.
   The field can be either a signed or unsigned field;
   BIT_FIELD_REF_UNSIGNED says which.  */

If it is valid, I think we should change tree.def's comment and e.g. patch
like this might be useful (noticed while looking at PR21817), because
otherwise we keep around stuff like:
BIT_FIELD_REF <{ 1.0e+9, 1.0e+9, 1.0e+9, 1.0e+9 }, 32, 64>
until RTL expansion.

2005-05-30  Jakub Jelinek  <jakub@redhat.com>

	* fold-const.c (fold_ternary): Optimize BIT_FIELD_REF of VECTOR_CST.

--- gcc/fold-const.c.jj	2005-05-24 23:01:40.000000000 +0200
+++ gcc/fold-const.c	2005-05-30 21:06:56.000000000 +0200
@@ -10308,6 +10308,29 @@ fold_ternary (enum tree_code code, tree 
 	}
       return NULL_TREE;
 
+    case BIT_FIELD_REF:
+      if (TREE_CODE (arg0) == VECTOR_CST
+	  && type == TREE_TYPE (TREE_TYPE (arg0))
+	  && host_integerp (arg1, 1)
+	  && host_integerp (op2, 1))
+	{
+	  unsigned HOST_WIDE_INT width = tree_low_cst (arg1, 1);
+	  unsigned HOST_WIDE_INT idx = tree_low_cst (op2, 1);
+
+	  if (width != 0
+	      && simple_cst_equal (arg1, TYPE_SIZE (type)) == 1
+	      && (idx % width) == 0
+	      && (idx = idx / width)
+		 < TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)))
+	    {
+	      tree elements = TREE_VECTOR_CST_ELTS (arg0);
+	      while (idx-- > 0)
+		elements = TREE_CHAIN (elements);
+	      return TREE_VALUE (elements);
+	    }
+	}
+      return NULL_TREE;
+
     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]