This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Peg down -(-A) -> A transformation
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>
- Date: Tue, 11 Nov 2014 18:49:34 +0100
- Subject: Re: [PATCH] Peg down -(-A) -> A transformation
- Authentication-results: sourceware.org; auth=none
- References: <20141111174025 dot GI10852 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Nov 11, 2014 at 06:40:25PM +0100, Marek Polacek wrote:
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -7862,9 +7862,15 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
> return fold_view_convert_expr (type, op0);
>
> case NEGATE_EXPR:
> - tem = fold_negate_expr (loc, arg0);
> - if (tem)
> - return fold_convert_loc (loc, type, tem);
> + if (TREE_CODE (arg0) == INTEGER_CST
> + || TREE_CODE (arg0) == REAL_CST
> + || TYPE_OVERFLOW_WRAPS (type)
> + || (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0)
> + {
> + tem = fold_negate_expr (loc, arg0);
> + if (tem)
> + return fold_convert_loc (loc, type, tem);
> + }
a) if arg0 is INTEGER_CST, but e.g. INT_MIN, should we
really fold it for -fsanitize=signed-integer-overflow
(I'd say in that case we should fold only if it is not
the minimum value)
b) if the argument is not INTEGRAL_TYPE_P (type), shouldn't
we fold no matter what flag_sanitize says? Is the REAL_CST
case needed in that case?
Jakub