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: SRA bit-field optimization


On Oct  3, 2007, Richard Sandiford <rsandifo@nildram.co.uk> wrote:

> For the record, it also causes many failures on mips-linux-gnu,
> such as the following execute.exp ones:

> FWIW, the gcc.c-torture/execute/20000113-1.c failures can easily be
> reproduced with a cross-compiler, because after the patch, foobar is
> optimised to a call to abort.

This patch appears to fix at least the first one.  I haven't given it
a full round of testing yet, FWIW.

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* tree-sra.c (sra_build_assignment): Set up mask depending on
	precision, not type.
	(sra_build_elt_assignment): Don't view-convert from signed to
	unsigned.
	(sra_explode_bitfield_assignment): Use bit-field type if
	possible.

Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c.orig	2007-10-01 17:38:16.000000000 -0300
+++ gcc/tree-sra.c	2007-10-03 13:36:08.000000000 -0300
@@ -2168,7 +2168,7 @@ sra_build_assignment (tree dst, tree src
       list = NULL;
 
       cst2 = size_binop (MINUS_EXPR, maxshift, minshift);
-      if (tree_int_cst_equal (cst2, TYPE_SIZE (utype)))
+      if (TREE_INT_CST_LOW (cst2) == TYPE_PRECISION (utype))
 	{
 	  unsignedp = true;
 	  mask = NULL_TREE;
@@ -2508,13 +2508,13 @@ sra_build_elt_assignment (struct sra_elt
 	    {
 	      list = NULL;
 
-	      if (!INTEGRAL_TYPE_P (TREE_TYPE (src))
-		  || !TYPE_UNSIGNED (TREE_TYPE (src)))
+	      if (!INTEGRAL_TYPE_P (TREE_TYPE (src)))
 		src = fold_build1 (VIEW_CONVERT_EXPR,
 				   lang_hooks.types.type_for_size
 				   (TREE_INT_CST_LOW
 				    (TYPE_SIZE (TREE_TYPE (src))),
 				    1), src);
+	      gcc_assert (TYPE_UNSIGNED (TREE_TYPE (src)));
 
 	      tmp = make_rename_temp (TREE_TYPE (src), "SR");
 	      stmt = build_gimple_modify_stmt (tmp, src);
@@ -2971,10 +2971,14 @@ sra_explode_bitfield_assignment (tree va
 
       if (fld->replacement)
 	{
-	  tree infld, invar, st;
+	  tree infld, invar, st, type;
 
 	  infld = fld->replacement;
 
+	  type = TREE_TYPE (infld);
+	  if (TYPE_PRECISION (type) != TREE_INT_CST_LOW (flen))
+	    type = lang_hooks.types.type_for_size (TREE_INT_CST_LOW (flen), 1);
+
 	  if (TREE_CODE (infld) == BIT_FIELD_REF)
 	    {
 	      fpos = size_binop (PLUS_EXPR, fpos, TREE_OPERAND (infld, 2));
@@ -2990,10 +2994,7 @@ sra_explode_bitfield_assignment (tree va
 				 DECL_SIZE (fld->element));
 	    }
 
-	  infld = fold_build3 (BIT_FIELD_REF,
-			       lang_hooks.types.type_for_size
-			       (TREE_INT_CST_LOW (flen), 1),
-			       infld, flen, fpos);
+	  infld = fold_build3 (BIT_FIELD_REF, type, infld, flen, fpos);
 	  BIT_FIELD_REF_UNSIGNED (infld) = 1;
 
 	  invar = size_binop (MINUS_EXPR, flp.field_pos, bpos);
@@ -3001,8 +3002,7 @@ sra_explode_bitfield_assignment (tree va
 	    invar = size_binop (PLUS_EXPR, invar, flp.overlap_pos);
 	  invar = size_binop (PLUS_EXPR, invar, vpos);
 
-	  invar = fold_build3 (BIT_FIELD_REF, TREE_TYPE (infld),
-			       var, flen, invar);
+	  invar = fold_build3 (BIT_FIELD_REF, type, var, flen, invar);
 	  BIT_FIELD_REF_UNSIGNED (invar) = 1;
 
 	  if (to_var)
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member         http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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