From bab73f11b8eb01e137ac86ca232c3058175de877 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 3 Jul 2015 07:55:10 +0000 Subject: [PATCH] fold-const.c (fold_binary_loc): Move (T)ptr & CST folding... 2015-07-03 Richard Biener * fold-const.c (fold_binary_loc): Move (T)ptr & CST folding... * match.pd: ... here. From-SVN: r225368 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 19 ------------------- gcc/match.pd | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 64cff098ed1..c2fa47d8378 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-07-03 Richard Biener + + * fold-const.c (fold_binary_loc): Move (T)ptr & CST folding... + * match.pd: ... here. + 2015-07-03 Gerald Pfeifer PR target/37072 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index a02cfb7b1f0..69ac19dfae0 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -11069,25 +11069,6 @@ fold_binary_loc (location_t loc, fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); } - /* If arg0 is derived from the address of an object or function, we may - be able to fold this expression using the object or function's - alignment. */ - if (POINTER_TYPE_P (TREE_TYPE (arg0)) && TREE_CODE (arg1) == INTEGER_CST) - { - unsigned int align; - unsigned HOST_WIDE_INT bitpos; - - get_pointer_alignment_1 (arg0, &align, &bitpos); - - /* This works because modulus is a power of 2. If this weren't the - case, we'd have to replace it by its greatest power-of-2 - divisor: modulus & -modulus. */ - if (wi::ltu_p (arg1, align / BITS_PER_UNIT)) - return wide_int_to_tree (type, - wi::bit_and (arg1, - bitpos / BITS_PER_UNIT)); - } - goto associate; case RDIV_EXPR: diff --git a/gcc/match.pd b/gcc/match.pd index 6c138390aca..5ac573a68e5 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -668,6 +668,21 @@ along with GCC; see the file COPYING3. If not see (if (ptr_difference_const (@0, @1, &diff)) { build_int_cst_type (type, diff); })))) +/* If arg0 is derived from the address of an object or function, we may + be able to fold this expression using the object or function's + alignment. */ +(simplify + (bit_and (convert? @0) INTEGER_CST@1) + (if (POINTER_TYPE_P (TREE_TYPE (@0)) + && tree_nop_conversion_p (type, TREE_TYPE (@0))) + (with + { + unsigned int align; + unsigned HOST_WIDE_INT bitpos; + get_pointer_alignment_1 (@0, &align, &bitpos); + } + (if (wi::ltu_p (@1, align / BITS_PER_UNIT)) + { wide_int_to_tree (type, wi::bit_and (@1, bitpos / BITS_PER_UNIT)); })))) /* We can't reassociate at all for saturating types. */ -- 2.30.2