OSDN Git Service

* config/m32r/m32r.c (m32r_encode_section_info): Use gcc_assert
[pf3gnuchains/gcc-fork.git] / gcc / fold-const.c
index 9de988c..140f940 100644 (file)
@@ -6149,7 +6149,8 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
        || TYPE_UNSIGNED (TREE_TYPE (arg0)) == TYPE_UNSIGNED (shorter_type))
       && (TREE_TYPE (arg1_unw) == shorter_type
          || (TREE_CODE (arg1_unw) == INTEGER_CST
-             && TREE_CODE (shorter_type) == INTEGER_TYPE
+             && (TREE_CODE (shorter_type) == INTEGER_TYPE
+                 || TREE_CODE (shorter_type) == BOOLEAN_TYPE)
              && int_fits_type_p (arg1_unw, shorter_type))))
     return fold_build2 (code, type, arg0_unw,
                       fold_convert (shorter_type, arg1_unw));
@@ -8856,10 +8857,20 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
     case LT_EXPR:
     case GT_EXPR:
     case LE_EXPR:
-    case GE_EXPR:
+    case GE_EXPR:      
       /* If one arg is a real or integer constant, put it last.  */
       if (tree_swap_operands_p (arg0, arg1, true))
        return fold_build2 (swap_tree_comparison (code), type, op1, op0);
+       
+      /* bool_var != 0 becomes bool_var. */
+      if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)
+          && code == NE_EXPR)
+        return non_lvalue (fold_convert (type, arg0));
+       
+      /* bool_var == 1 becomes bool_var. */
+      if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1)
+          && code == EQ_EXPR)
+        return non_lvalue (fold_convert (type, arg0));
 
       /* If this is an equality comparison of the address of a non-weak
         object against zero, then we know the result.  */
@@ -9723,21 +9734,9 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
            {
              tree op0 = TREE_OPERAND (cref0, 0);
              tree op1 = TREE_OPERAND (cref1, 0);
-             if (TREE_CODE (op0) == INDIRECT_REF)
-               op0 = TREE_OPERAND (op0, 0);
-             else
-               {
-                 tree ptype = build_pointer_type (TREE_TYPE (op0));
-                 op0 = build1 (ADDR_EXPR, ptype, op0);
-               }
-             if (TREE_CODE (op1) == INDIRECT_REF)
-               op1 = TREE_OPERAND (op1, 0);
-             else
-               {
-                 tree ptype = build_pointer_type (TREE_TYPE (op1));
-                 op1 = build1 (ADDR_EXPR, ptype, op1);
-               }
-             return fold_build2 (code, type, op0, op1);
+             return fold_build2 (code, type,
+                                 build_fold_addr_expr (op0),
+                                 build_fold_addr_expr (op1));
            }
        }