]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const.c (fold, [...]): When folding VAR++ == CONST or VAR-- == CONST construct...
authorAndreas Schwab <schwab@issan.informatik.uni-dortmund.de>
Tue, 2 Jun 1998 21:53:37 +0000 (21:53 +0000)
committerJeff Law <law@gcc.gnu.org>
Tue, 2 Jun 1998 21:53:37 +0000 (15:53 -0600)
        * fold-const.c (fold, case EQ_EXPR): When folding VAR++ == CONST
        or VAR-- == CONST construct a proper mask if VAR is a bitfield.
        Cope with CONST being out of range for the bitfield.

From-SVN: r20198

gcc/ChangeLog
gcc/fold-const.c

index 7a0e7a46d07becb2dcaca712ef4b74056caa9e13..af9dab8ee9ce26d167d1cd16305055f2a386f447 100644 (file)
@@ -1,3 +1,9 @@
+Tue Jun  2 22:50:10 1998  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>
+
+       * fold-const.c (fold, case EQ_EXPR): When folding VAR++ == CONST
+       or VAR-- == CONST construct a proper mask if VAR is a bitfield.
+       Cope with CONST being out of range for the bitfield.
+
 Tue Jun  2 22:28:31 1998  Bernd Schmidt <crux@ohara.Informatik.RWTH-Aachen.DE>
 
        * expr.c (emit_move_insn_1): When moving complex values in several
index 9d1cb36458d8b1db7994f83ab90b75caca842e28..d8477645c530375890b385602c27024ec62c628b 100644 (file)
@@ -5222,11 +5222,35 @@ fold (expr)
                      = TREE_INT_CST_LOW (DECL_SIZE
                                          (TREE_OPERAND
                                           (TREE_OPERAND (varop, 0), 1)));
-
+                   tree mask, unsigned_type;
+                   int precision;
+                   tree folded_compare;
+
+                   /* First check whether the comparison would come out
+                      always the same.  If we don't do that we would
+                      change the meaning with the masking.  */
+                   if (constopnum == 0)
+                     folded_compare = fold (build (code, type, constop,
+                                                   TREE_OPERAND (varop, 0)));
+                   else
+                     folded_compare = fold (build (code, type,
+                                                   TREE_OPERAND (varop, 0),
+                                                   constop));
+                   if (integer_zerop (folded_compare)
+                       || integer_onep (folded_compare))
+                     return omit_one_operand (type, folded_compare, varop);
+
+                   unsigned_type = type_for_size (size, 1);
+                   precision = TYPE_PRECISION (unsigned_type);
+                   mask = build_int_2 (~0, ~0);
+                   TREE_TYPE (mask) = unsigned_type;
+                   force_fit_type (mask, 0);
+                   mask = const_binop (RSHIFT_EXPR, mask,
+                                       size_int (precision - size), 0);
                    newconst = fold (build (BIT_AND_EXPR,
                                            TREE_TYPE (varop), newconst,
                                            convert (TREE_TYPE (varop),
-                                                    build_int_2 (size, 0))));
+                                                    mask)));
                  }
                                                         
 
@@ -5255,11 +5279,32 @@ fold (expr)
                      = TREE_INT_CST_LOW (DECL_SIZE
                                          (TREE_OPERAND
                                           (TREE_OPERAND (varop, 0), 1)));
-
+                   tree mask, unsigned_type;
+                   int precision;
+                   tree folded_compare;
+
+                   if (constopnum == 0)
+                     folded_compare = fold (build (code, type, constop,
+                                                   TREE_OPERAND (varop, 0)));
+                   else
+                     folded_compare = fold (build (code, type,
+                                                   TREE_OPERAND (varop, 0),
+                                                   constop));
+                   if (integer_zerop (folded_compare)
+                       || integer_onep (folded_compare))
+                     return omit_one_operand (type, folded_compare, varop);
+
+                   unsigned_type = type_for_size (size, 1);
+                   precision = TYPE_PRECISION (unsigned_type);
+                   mask = build_int_2 (~0, ~0);
+                   TREE_TYPE (mask) = TREE_TYPE (varop);
+                   force_fit_type (mask, 0);
+                   mask = const_binop (RSHIFT_EXPR, mask,
+                                       size_int (precision - size), 0);
                    newconst = fold (build (BIT_AND_EXPR,
                                            TREE_TYPE (varop), newconst,
                                            convert (TREE_TYPE (varop),
-                                                    build_int_2 (size, 0))));
+                                                    mask)));
                  }