On Thu, Jul 28, 2011 at 11:21 AM, Kai Tietz <kti...@redhat.com> wrote:
> Hello,
>
> this patch removes the handling for TRUTH_NOT_EXPR in tree-vrp.c and adjust 
> some simplifications to be compatible with BIT_NOT_EXPR.
>
> ChangeLog
>
> 2011-07-28  Kai Tietz  <kti...@redhat.com>
>
>        * tree-vrp.c (simplify_stmt_using_ranges): Remove
>        TRUTH_NOT_EXPR case.
>        (simplify_truth_ops_using_ranges): Likewise.
>        (build_assert_expr_for): Remove TRUTH_NOT_EXPR case
>        and handle BIT_NOT_EXPR for truth-operation.
>        (build_assert_expr_for_1): Likewise.
>
> Bootstrapped and regression-tested for all languages (+ Ada, Obj-C++) on host 
> x86_64-pc-linux-gnu.  Ok for apply?
>
> Regards,
> Kai
>
> Index: gcc-head/gcc/tree-vrp.c
> ===================================================================
> --- gcc-head.orig/gcc/tree-vrp.c
> +++ gcc-head/gcc/tree-vrp.c
> @@ -3972,7 +3972,8 @@ build_assert_expr_for (tree cond, tree v
>       tree a = build2 (ASSERT_EXPR, TREE_TYPE (v), v, cond);
>       assertion = gimple_build_assign (n, a);
>     }
> -  else if (TREE_CODE (cond) == TRUTH_NOT_EXPR)
> +  else if (TREE_CODE (cond) == BIT_NOT_EXPR
> +          && TYPE_PRECISION (TREE_TYPE (cond)) == 1)

As said previously at least two times (*sigh*), this is dead code.  Just
remove handling of TRUTH_NOT_EXPR here.

Ok with that change.

Thanks,
Richard.

>     {
>       /* Given !V, build the assignment N = false.  */
>       tree op0 = TREE_OPERAND (cond, 0);
> @@ -4525,7 +4526,8 @@ register_edge_assert_for_1 (tree op, enu
>       retval |= register_edge_assert_for_1 (gimple_assign_rhs2 (op_def),
>                                            code, e, bsi);
>     }
> -  else if (gimple_assign_rhs_code (op_def) == TRUTH_NOT_EXPR)
> +  else if (gimple_assign_rhs_code (op_def) == BIT_NOT_EXPR
> +          && TYPE_PRECISION (TREE_TYPE (gimple_assign_lhs (op_def))) == 1)
>     {
>       /* Recurse, flipping CODE.  */
>       code = invert_tree_comparison (code, false);
> @@ -6754,6 +6756,9 @@ simplify_truth_ops_using_ranges (gimple_
>   bool sop = false;
>   bool need_conversion;
>
> +  /* We handle only !=/== case here.  */
> +  gcc_assert (rhs_code == EQ_EXPR || rhs_code == NE_EXPR);
> +
>   op0 = gimple_assign_rhs1 (stmt);
>   if (TYPE_PRECISION (TREE_TYPE (op0)) != 1)
>     {
> @@ -6770,52 +6775,40 @@ simplify_truth_ops_using_ranges (gimple_
>         return false;
>     }
>
> -  if (rhs_code == TRUTH_NOT_EXPR)
> +  op1 = gimple_assign_rhs2 (stmt);
> +
> +  /* Reduce number of cases to handle.  */
> +  if (is_gimple_min_invariant (op1))
>     {
> -      rhs_code = NE_EXPR;
> -      op1 = build_int_cst (TREE_TYPE (op0), 1);
> +      if (!integer_zerop (op1)
> +         && !integer_onep (op1)
> +         && !integer_all_onesp (op1))
> +       return false;
> +
> +      /* Limit the number of cases we have to consider.  */
> +      if (rhs_code == EQ_EXPR)
> +       {
> +         rhs_code = NE_EXPR;
> +         /* OP1 is a constant.  */
> +         op1 = fold_unary (TRUTH_NOT_EXPR, TREE_TYPE (op1), op1);
> +       }
>     }
>   else
>     {
> -      op1 = gimple_assign_rhs2 (stmt);
> +      /* Punt on A == B as there is no BIT_XNOR_EXPR.  */
> +      if (rhs_code == EQ_EXPR)
> +       return false;
>
> -      /* Reduce number of cases to handle.  */
> -      if (is_gimple_min_invariant (op1))
> +      if (TYPE_PRECISION (TREE_TYPE (op1)) != 1)
>        {
> -          /* Exclude anything that should have been already folded.  */
> -         if (rhs_code != EQ_EXPR
> -             && rhs_code != NE_EXPR)
> +         vr = get_value_range (op1);
> +         val = compare_range_with_value (GE_EXPR, vr, integer_zero_node, 
> &sop);
> +         if (!val || !integer_onep (val))
>            return false;
>
> -         if (!integer_zerop (op1)
> -             && !integer_onep (op1)
> -             && !integer_all_onesp (op1))
> +         val = compare_range_with_value (LE_EXPR, vr, integer_one_node, 
> &sop);
> +         if (!val || !integer_onep (val))
>            return false;
> -
> -         /* Limit the number of cases we have to consider.  */
> -         if (rhs_code == EQ_EXPR)
> -           {
> -             rhs_code = NE_EXPR;
> -             op1 = fold_unary (TRUTH_NOT_EXPR, TREE_TYPE (op1), op1);
> -           }
> -       }
> -      else
> -       {
> -         /* Punt on A == B as there is no BIT_XNOR_EXPR.  */
> -         if (rhs_code == EQ_EXPR)
> -           return false;
> -
> -         if (TYPE_PRECISION (TREE_TYPE (op1)) != 1)
> -           {
> -             vr = get_value_range (op1);
> -             val = compare_range_with_value (GE_EXPR, vr, integer_zero_node, 
> &sop);
> -             if (!val || !integer_onep (val))
> -               return false;
> -
> -             val = compare_range_with_value (LE_EXPR, vr, integer_one_node, 
> &sop);
> -             if (!val || !integer_onep (val))
> -               return false;
> -           }
>        }
>     }
>
> @@ -7514,11 +7507,9 @@ simplify_stmt_using_ranges (gimple_stmt_
>        {
>        case EQ_EXPR:
>        case NE_EXPR:
> -       case TRUTH_NOT_EXPR:
> -          /* Transform EQ_EXPR, NE_EXPR, TRUTH_NOT_EXPR into BIT_XOR_EXPR
> -            or identity if the RHS is zero or one, and the LHS are known
> -            to be boolean values.  Transform all TRUTH_*_EXPR into
> -             BIT_*_EXPR if both arguments are known to be boolean values.  */
> +          /* Transform EQ_EXPR, NE_EXPR into BIT_XOR_EXPR or identity
> +            if the RHS is zero or one, and the LHS are known to be boolean
> +            values.  */
>          if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1)))
>            return simplify_truth_ops_using_ranges (gsi, stmt);
>          break;
>

Reply via email to