fold-const.c (fold_truthop): Optimize bitfield references with different masks as...
authorCharles M. Hannum <root@ihack.net>
Fri, 26 Mar 1999 22:46:33 +0000 (15:46 -0700)
committerJeff Law <law@gcc.gnu.org>
Fri, 26 Mar 1999 22:46:33 +0000 (15:46 -0700)
        * fold-const.c (fold_truthop): Optimize bitfield references with
        different masks as long as their size and bit position are the same.

From-SVN: r26006

gcc/ChangeLog
gcc/fold-const.c

index 8822a94d096420d50270358a889e3f4681546c41..f14f7df682d8fd1d36db8defe19f1cf3a4938194 100644 (file)
@@ -65,6 +65,9 @@ Fri Mar 26 10:43:47 1999  Nick Clifton  <nickc@cygnus.com>
 
 Fri Mar 26 01:59:15 1999  "Charles M. Hannum" <root@ihack.net>
 
+       * fold-const.c (fold_truthop): Optimize bitfield references with
+       different masks as long as their size and bit position are the same.
+
        * fold-const.c (fold_truthop): Build a type for both the lhs and
        rhs and use it appropriately.
 
index d96aa3c8279b62920e6a59c8b0c4d899198b4b69..9b003c2ec220ef2f4ccb254baa3d4dc626f99328 100644 (file)
@@ -3934,25 +3934,24 @@ fold_truthop (code, truth_type, lhs, rhs)
                             size_int (xrr_bitpos), 0);
 
       /* Make a mask that corresponds to both fields being compared.
-        Do this for both items being compared.  If the masks agree,
-        and the bits being compared are in the same position, and the
-        types agree, then we can do this by masking both and comparing
-        the masked results.  */
+        Do this for both items being compared.  If the operands are the
+        same size and the bits being compared are in the same position
+        then we can do this by masking both and comparing the masked
+        results.  */
       ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
       lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask, 0);
-      if (operand_equal_p (ll_mask, lr_mask, 0)
-         && lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos
-         && lntype == rntype)
+      if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos)
        {
          lhs = make_bit_field_ref (ll_inner, lntype, lnbitsize, lnbitpos,
                                    ll_unsignedp || rl_unsignedp);
+         if (! all_ones_mask_p (ll_mask, lnbitsize))
+           lhs = build (BIT_AND_EXPR, lntype, lhs, ll_mask);
+
          rhs = make_bit_field_ref (lr_inner, rntype, rnbitsize, rnbitpos,
                                    lr_unsignedp || rr_unsignedp);
-         if (! all_ones_mask_p (ll_mask, lnbitsize))
-           {
-             lhs = build (BIT_AND_EXPR, lntype, lhs, ll_mask);
-             rhs = build (BIT_AND_EXPR, rntype, rhs, ll_mask);
-           }
+         if (! all_ones_mask_p (lr_mask, rnbitsize))
+           rhs = build (BIT_AND_EXPR, rntype, rhs, lr_mask);
+
          return build (wanted_code, truth_type, lhs, rhs);
        }