aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2015-06-30 11:58:48 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2015-06-30 11:58:48 +0000
commitb14a9c57cff644851084c4f602437c7fa353c5d0 (patch)
treef7cd6a66425a4813b96dd9a091c09540c5b92b2e /gcc/fold-const.c
parentebc30bf9fd86dc00dcb902780079cf895f4b16b5 (diff)
downloadgcc-b14a9c57cff644851084c4f602437c7fa353c5d0.zip
gcc-b14a9c57cff644851084c4f602437c7fa353c5d0.tar.gz
gcc-b14a9c57cff644851084c4f602437c7fa353c5d0.tar.bz2
fold-const.c (fold_unary_loc): Move abs(abs(x)) -> abs(x)...
2015-06-30 Richard Biener <rguenther@suse.de> * fold-const.c (fold_unary_loc): Move abs(abs(x)) -> abs(x), ~ (-A) to A - 1, ~ (A - 1) or ~ (A + -1) to -A and some cases of ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify to ... * match.pd: ... here. Add a few cases of A - B -> A + (-B) when B "easily" negates. Move (x & y) | x -> x and friends before (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2). From-SVN: r225178
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c34
1 files changed, 6 insertions, 28 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index f330d78..67115d2 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8125,9 +8125,6 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
TREE_TYPE (targ0),
targ0));
}
- /* ABS_EXPR<ABS_EXPR<x>> = ABS_EXPR<x> even if flag_wrapv is on. */
- else if (TREE_CODE (arg0) == ABS_EXPR)
- return arg0;
/* Strip sign ops from argument. */
if (TREE_CODE (type) == REAL_TYPE)
@@ -8155,33 +8152,14 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
return NULL_TREE;
case BIT_NOT_EXPR:
- /* Convert ~ (-A) to A - 1. */
- if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == NEGATE_EXPR)
- return fold_build2_loc (loc, MINUS_EXPR, type,
- fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)),
- build_int_cst (type, 1));
- /* Convert ~ (A - 1) or ~ (A + -1) to -A. */
- else if (INTEGRAL_TYPE_P (type)
- && ((TREE_CODE (arg0) == MINUS_EXPR
- && integer_onep (TREE_OPERAND (arg0, 1)))
- || (TREE_CODE (arg0) == PLUS_EXPR
- && integer_all_onesp (TREE_OPERAND (arg0, 1)))))
- {
- /* Perform the negation in ARG0's type and only then convert
- to TYPE as to avoid introducing undefined behavior. */
- tree t = fold_build1_loc (loc, NEGATE_EXPR,
- TREE_TYPE (TREE_OPERAND (arg0, 0)),
- TREE_OPERAND (arg0, 0));
- return fold_convert_loc (loc, type, t);
- }
/* Convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */
- else if (TREE_CODE (arg0) == BIT_XOR_EXPR
- && (tem = fold_unary_loc (loc, BIT_NOT_EXPR, type,
- fold_convert_loc (loc, type,
- TREE_OPERAND (arg0, 0)))))
+ if (TREE_CODE (arg0) == BIT_XOR_EXPR
+ && (tem = fold_unary_loc (loc, BIT_NOT_EXPR, type,
+ fold_convert_loc (loc, type,
+ TREE_OPERAND (arg0, 0)))))
return fold_build2_loc (loc, BIT_XOR_EXPR, type, tem,
- fold_convert_loc (loc, type,
- TREE_OPERAND (arg0, 1)));
+ fold_convert_loc (loc, type,
+ TREE_OPERAND (arg0, 1)));
else if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& (tem = fold_unary_loc (loc, BIT_NOT_EXPR, type,
fold_convert_loc (loc, type,