2008-06-25 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 25 Jun 2008 08:41:14 +0000 (08:41 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 25 Jun 2008 08:41:14 +0000 (08:41 +0000)
PR tree-optimization/35518
* fold-const.c (fold_ternary): Strip trivial BIT_FIELD_REFs.
* tree-sra.c (instantiate_element): Use fold_build3 to build
BIT_FIELD_REFs.
(try_instantiate_multiple_fields): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@137100 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/tree-sra.c

index 35fc848..64423b1 100644 (file)
@@ -1,3 +1,11 @@
+2008-06-25  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/35518
+       * fold-const.c (fold_ternary): Strip trivial BIT_FIELD_REFs.
+       * tree-sra.c (instantiate_element): Use fold_build3 to build
+       BIT_FIELD_REFs.
+       (try_instantiate_multiple_fields): Likewise.
+
 2008-06-24  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        * config/rs6000/rs6000.md: Change all string instruction's clobber to
index aaae9d6..fc72b9b 100644 (file)
@@ -13117,6 +13117,13 @@ fold_ternary (enum tree_code code, tree type, tree op0, tree op1, tree op2)
                return fold_convert (type, integer_zero_node);
            }
        }
+
+      /* A bit-field-ref that referenced the full argument can be stripped.  */
+      if (INTEGRAL_TYPE_P (TREE_TYPE (arg0))
+         && TYPE_PRECISION (TREE_TYPE (arg0)) == tree_low_cst (arg1, 1)
+         && integer_zerop (op2))
+       return fold_convert (type, arg0);
+
       return NULL_TREE;
 
     default:
index 69d0700..391511f 100644 (file)
@@ -1284,13 +1284,13 @@ instantiate_element (struct sra_elt *elt)
       DECL_SIZE_UNIT (var) = DECL_SIZE_UNIT (elt->element);
 
       elt->in_bitfld_block = 1;
-      elt->replacement = build3 (BIT_FIELD_REF, elt->type, var,
-                                DECL_SIZE (var),
-                                BYTES_BIG_ENDIAN
-                                ? size_binop (MINUS_EXPR,
-                                              TYPE_SIZE (elt->type),
-                                              DECL_SIZE (var))
-                                : bitsize_int (0));
+      elt->replacement = fold_build3 (BIT_FIELD_REF, elt->type, var,
+                                     DECL_SIZE (var),
+                                     BYTES_BIG_ENDIAN
+                                     ? size_binop (MINUS_EXPR,
+                                                   TYPE_SIZE (elt->type),
+                                                   DECL_SIZE (var))
+                                     : bitsize_int (0));
     }
 
   /* For vectors, if used on the left hand side with BIT_FIELD_REF,
@@ -1698,8 +1698,7 @@ try_instantiate_multiple_fields (struct sra_elt *elt, tree f)
     type = build_nonstandard_integer_type (size, 1);
   gcc_assert (type);
   var = build3 (BIT_FIELD_REF, type, NULL_TREE,
-               bitsize_int (size),
-               bitsize_int (bit));
+               bitsize_int (size), bitsize_int (bit));
 
   block = instantiate_missing_elements_1 (elt, var, type);
   gcc_assert (block && block->is_scalar);
@@ -1709,10 +1708,10 @@ try_instantiate_multiple_fields (struct sra_elt *elt, tree f)
   if ((bit & ~alchk)
       || (HOST_WIDE_INT)size != tree_low_cst (DECL_SIZE (var), 1))
     {
-      block->replacement = build3 (BIT_FIELD_REF,
-                                  TREE_TYPE (block->element), var,
-                                  bitsize_int (size),
-                                  bitsize_int (bit & ~alchk));
+      block->replacement = fold_build3 (BIT_FIELD_REF,
+                                       TREE_TYPE (block->element), var,
+                                       bitsize_int (size),
+                                       bitsize_int (bit & ~alchk));
     }
 
   block->in_bitfld_block = 2;
@@ -1727,14 +1726,14 @@ try_instantiate_multiple_fields (struct sra_elt *elt, tree f)
 
       gcc_assert (fld && fld->is_scalar && !fld->replacement);
 
-      fld->replacement = build3 (BIT_FIELD_REF, field_type, var,
-                                DECL_SIZE (f),
-                                bitsize_int
-                                ((TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f))
-                                  * BITS_PER_UNIT
-                                  + (TREE_INT_CST_LOW
-                                     (DECL_FIELD_BIT_OFFSET (f))))
-                                 & ~alchk));
+      fld->replacement = fold_build3 (BIT_FIELD_REF, field_type, var,
+                                     DECL_SIZE (f),
+                                     bitsize_int
+                                     ((TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f))
+                                       * BITS_PER_UNIT
+                                       + (TREE_INT_CST_LOW
+                                          (DECL_FIELD_BIT_OFFSET (f))))
+                                      & ~alchk));
       fld->in_bitfld_block = 1;
     }