From 9a0ee7b0286f1de2f05a5e4e41f8c3436053c975 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Mon, 6 May 2013 23:14:59 +0200 Subject: [PATCH] tree.c (integer_all_onesp): Test that both components are all 1s. 2013-05-06 Marc Glisse * tree.c (integer_all_onesp) : Test that both components are all 1s. (integer_minus_onep): New function. * tree.h (integer_minus_onep): Declare it. * fold-const.c (fold_binary_loc) : Test integer_minus_onep instead of integer_all_onesp. From-SVN: r198649 --- gcc/ChangeLog | 9 +++++++++ gcc/fold-const.c | 2 +- gcc/tree.c | 18 ++++++++++++++++-- gcc/tree.h | 5 +++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 09108c32ab2..d813433e124 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2013-05-06 Marc Glisse + + * tree.c (integer_all_onesp) : Test that both + components are all 1s. + (integer_minus_onep): New function. + * tree.h (integer_minus_onep): Declare it. + * fold-const.c (fold_binary_loc) : Test + integer_minus_onep instead of integer_all_onesp. + 2013-05-06 Oleg Endo PR target/52933 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f93ce8a7e26..74b451e470a 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10870,7 +10870,7 @@ fold_binary_loc (location_t loc, /* Transform x * -1 into -x. Make sure to do the negation on the original operand with conversions not stripped because we can only strip non-sign-changing conversions. */ - if (integer_all_onesp (arg1)) + if (integer_minus_onep (arg1)) return fold_convert_loc (loc, type, negate_expr (op0)); /* Transform x * -C into -x * C if x is easily negatable. */ if (TREE_CODE (arg1) == INTEGER_CST diff --git a/gcc/tree.c b/gcc/tree.c index d8f2424a1ef..444c87673d7 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -1781,7 +1781,7 @@ integer_onep (const_tree expr) } /* Return 1 if EXPR is an integer containing all 1's in as much precision as - it contains. Likewise for the corresponding complex constant. */ + it contains, or a complex or vector whose subparts are such integers. */ int integer_all_onesp (const_tree expr) @@ -1793,7 +1793,7 @@ integer_all_onesp (const_tree expr) if (TREE_CODE (expr) == COMPLEX_CST && integer_all_onesp (TREE_REALPART (expr)) - && integer_zerop (TREE_IMAGPART (expr))) + && integer_all_onesp (TREE_IMAGPART (expr))) return 1; else if (TREE_CODE (expr) == VECTOR_CST) @@ -1839,6 +1839,20 @@ integer_all_onesp (const_tree expr) return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1; } +/* Return 1 if EXPR is the integer constant minus one. */ + +int +integer_minus_onep (const_tree expr) +{ + STRIP_NOPS (expr); + + if (TREE_CODE (expr) == COMPLEX_CST) + return (integer_all_onesp (TREE_REALPART (expr)) + && integer_zerop (TREE_IMAGPART (expr))); + else + return integer_all_onesp (expr); +} + /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only one bit on). */ diff --git a/gcc/tree.h b/gcc/tree.h index be43440783d..2b6f13b8f12 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -5310,6 +5310,11 @@ extern int integer_onep (const_tree); extern int integer_all_onesp (const_tree); +/* integer_minus_onep (tree x) is nonzero if X is an integer constant of + value -1. */ + +extern int integer_minus_onep (const_tree); + /* integer_pow2p (tree x) is nonzero is X is an integer constant with exactly one bit 1. */ -- 2.11.4.GIT