diff options
author | Richard Biener <rguenther@suse.de> | 2015-05-26 12:00:48 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2015-05-26 12:00:48 +0000 |
commit | 8f0c696a7b5079c5deea4b4301b16b41145e7986 (patch) | |
tree | 93308095f66ea23ff7e2686d0c3d93c9eb180d0c /gcc/fold-const.c | |
parent | 534bd33b61d08e0bf4d58efbeb3da5a368f8a247 (diff) | |
download | gcc-8f0c696a7b5079c5deea4b4301b16b41145e7986.zip gcc-8f0c696a7b5079c5deea4b4301b16b41145e7986.tar.gz gcc-8f0c696a7b5079c5deea4b4301b16b41145e7986.tar.bz2 |
fold-const.c (fold_binary_loc): Move X % -Y -> X % Y and X % C -> X & (C - 1) for C being a power-of two to ...
2015-05-26 Richard Biener <rguenther@suse.de>
* fold-const.c (fold_binary_loc): Move X % -Y -> X % Y and
X % C -> X & (C - 1) for C being a power-of two to ...
* match.pd: ... patterns.
From-SVN: r223690
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5545ecf..55196b5 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -11941,15 +11941,6 @@ fold_binary_loc (location_t loc, case FLOOR_MOD_EXPR: case ROUND_MOD_EXPR: case TRUNC_MOD_EXPR: - /* X % -Y is the same as X % Y. */ - if (code == TRUNC_MOD_EXPR - && !TYPE_UNSIGNED (type) - && TREE_CODE (arg1) == NEGATE_EXPR - && !TYPE_OVERFLOW_TRAPS (type)) - return fold_build2_loc (loc, code, type, fold_convert_loc (loc, type, arg0), - fold_convert_loc (loc, type, - TREE_OPERAND (arg1, 0))); - strict_overflow_p = false; if (TREE_CODE (arg1) == INTEGER_CST && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, @@ -11962,34 +11953,6 @@ fold_binary_loc (location_t loc, return fold_convert_loc (loc, type, tem); } - /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR, - i.e. "X % C" into "X & (C - 1)", if X and C are positive. */ - if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR) - && (TYPE_UNSIGNED (type) - || tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p))) - { - tree c = arg1; - /* Also optimize A % (C << N) where C is a power of 2, - to A & ((C << N) - 1). */ - if (TREE_CODE (arg1) == LSHIFT_EXPR) - c = TREE_OPERAND (arg1, 0); - - if (integer_pow2p (c) && tree_int_cst_sgn (c) > 0) - { - tree mask - = fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (arg1), arg1, - build_int_cst (TREE_TYPE (arg1), 1)); - if (strict_overflow_p) - fold_overflow_warning (("assuming signed overflow does not " - "occur when simplifying " - "X % (power of two)"), - WARN_STRICT_OVERFLOW_MISC); - return fold_build2_loc (loc, BIT_AND_EXPR, type, - fold_convert_loc (loc, type, arg0), - fold_convert_loc (loc, type, mask)); - } - } - return NULL_TREE; case LROTATE_EXPR: |