From b24bee039721e7304575c4c0b93bb1601dd63463 Mon Sep 17 00:00:00 2001 From: sayle Date: Sat, 31 May 2003 13:23:32 +0000 Subject: * flags.h (flag_wrapv): New flag controlling overflow semantics. * toplev.c (flag_wrapv): Declare the variable with default false. (lang_independent_options): New option "-fwrapv" to set the above. * fold-const.c (extract_muldiv_1): Disable optimization of (2*x)/2 as x, when signed arithmetic overflow wraps around. (fold): Optimize "-A - B" as "-B - A" if overflow wraps around. * loop.c (basic_induction_var): Ignore BIVs that rely on undefined overflow when flag_wrapv is true. * java/lang.c (java_init_options): Prescribe wrap-around two's complement arithmetic overflow by setting flag_wrapv. * doc/invoke.texi: Document new -fwrapv command line option. * doc/c-tree.texi: Mention that the overflow semantics of NEGATE_EXPR, PLUS_EXPR, MINUS_EXPR and MULT_EXPR is dependent upon both flag_wrapv and flag_trapv. * gcc.dg/fwrapv-1.c: New test case. * gcc.dg/fwrapv-2.c: New test case. * libjava.lang/Overflow.java: New test. * libjava.lang/Overflow.out: New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@67270 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fold-const.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/fold-const.c') diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 381bc9cb959..e81e8090cf0 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4381,6 +4381,7 @@ extract_muldiv_1 (t, c, code, wide_type) overflowed. */ if ((! TREE_UNSIGNED (ctype) || (TREE_CODE (ctype) == INTEGER_TYPE && TYPE_IS_SIZETYPE (ctype))) + && ! flag_wrapv && ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR) || (tcode == MULT_EXPR && code != TRUNC_MOD_EXPR && code != CEIL_MOD_EXPR @@ -5765,7 +5766,8 @@ fold (expr) return fold (build (PLUS_EXPR, type, arg0, TREE_OPERAND (arg1, 0))); /* (-A) - B -> (-B) - A where B is easily negated and we can swap. */ if (TREE_CODE (arg0) == NEGATE_EXPR - && FLOAT_TYPE_P (type) + && (FLOAT_TYPE_P (type) + || (INTEGRAL_TYPE_P (type) && flag_wrapv && !flag_trapv)) && negate_expr_p (arg1) && (! TREE_SIDE_EFFECTS (arg0) || TREE_CONSTANT (arg1)) && (! TREE_SIDE_EFFECTS (arg1) || TREE_CONSTANT (arg0))) -- cgit v1.2.1