From: Roger Sayle Date: Mon, 26 Apr 2004 03:43:17 +0000 (+0000) Subject: fold-const.c (fold): Prefer fold_convert (negate_expr (...)) to fold (build1 (NEGATE_... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7c95f621b31f1366bd1276146783103e81b0eb7d;p=gcc.git fold-const.c (fold): Prefer fold_convert (negate_expr (...)) to fold (build1 (NEGATE_EXPR, ...)). * fold-const.c (fold): Prefer fold_convert (negate_expr (...)) to fold (build1 (NEGATE_EXPR, ...)). Optimize X / -1 as -X and X % -1 as 0. From-SVN: r81177 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f9f097fe242..6cb1567b24d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-04-25 Roger Sayle + + * fold-const.c (fold): Prefer fold_convert (negate_expr (...)) to + fold (build1 (NEGATE_EXPR, ...)). Optimize X / -1 as -X and + X % -1 as 0. + 2004-04-26 Hans-Peter Nilsson PR bootstrap/15141 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 86fd91065b0..57ae918392c 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6412,7 +6412,7 @@ fold (tree expr) /* Transform x * -1.0 into -x. */ if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) && real_minus_onep (arg1)) - return fold (build1 (NEGATE_EXPR, type, arg0)); + return fold_convert (type, negate_expr (arg0)); /* Convert (C1/X)*C2 into (C1*C2)/X. */ if (flag_unsafe_math_optimizations @@ -6768,9 +6768,9 @@ fold (tree expr) if (BUILTIN_EXPONENT_P (fcode)) { tree expfn = TREE_OPERAND (TREE_OPERAND (arg1, 0), 0); - tree arg = build1 (NEGATE_EXPR, type, - TREE_VALUE (TREE_OPERAND (arg1, 1))); - tree arglist = build_tree_list (NULL_TREE, fold (arg)); + tree arg = negate_expr (TREE_VALUE (TREE_OPERAND (arg1, 1))); + tree arglist = build_tree_list (NULL_TREE, + fold_convert (type, arg)); arg1 = build_function_call_expr (expfn, arglist); return fold (build (MULT_EXPR, type, arg0, arg1)); } @@ -6783,7 +6783,7 @@ fold (tree expr) tree powfn = TREE_OPERAND (TREE_OPERAND (arg1, 0), 0); tree arg10 = TREE_VALUE (TREE_OPERAND (arg1, 1)); tree arg11 = TREE_VALUE (TREE_CHAIN (TREE_OPERAND (arg1, 1))); - tree neg11 = fold (build1 (NEGATE_EXPR, type, arg11)); + tree neg11 = fold_convert (type, negate_expr (arg11)); tree arglist = tree_cons(NULL_TREE, arg10, build_tree_list (NULL_TREE, neg11)); arg1 = build_function_call_expr (powfn, arglist); @@ -6864,6 +6864,12 @@ fold (tree expr) return non_lvalue (fold_convert (type, arg0)); if (integer_zerop (arg1)) return t; + /* X / -1 is -X. */ + if (!TYPE_UNSIGNED (type) + && TREE_CODE (arg1) == INTEGER_CST + && TREE_INT_CST_LOW (arg1) == (unsigned HOST_WIDE_INT) -1 + && TREE_INT_CST_HIGH (arg1) == -1) + return fold_convert (type, negate_expr (arg0)); /* If arg0 is a multiple of arg1, then rewrite to the fastest div operation, EXACT_DIV_EXPR. @@ -6890,6 +6896,12 @@ fold (tree expr) return omit_one_operand (type, integer_zero_node, arg0); if (integer_zerop (arg1)) return t; + /* X % -1 is zero. */ + if (!TYPE_UNSIGNED (type) + && TREE_CODE (arg1) == INTEGER_CST + && TREE_INT_CST_LOW (arg1) == (unsigned HOST_WIDE_INT) -1 + && TREE_INT_CST_HIGH (arg1) == -1) + return omit_one_operand (type, integer_zero_node, arg0); if (TREE_CODE (arg1) == INTEGER_CST && 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,