From: Roger Sayle Date: Tue, 28 Feb 2006 21:31:29 +0000 (+0000) Subject: re PR tree-optimization/14752 ([tree-ssa] "~a" should be changed to "a" if used in... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c457fcec8e54df75ee6c133a79cee1417523af59;p=gcc.git re PR tree-optimization/14752 ([tree-ssa] "~a" should be changed to "a" if used in the condition of an if statement) PR middle-end/14752 * c-common.c (c_common_truthvalue_conversion) : Delete. Let fold optimize these cases via the construction of "expr != 0". * gcc.dg/fold-eqandshift-2.c: New test case. From-SVN: r111575 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2b678abac8d..7b11e7be9c2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2006-02-28 Roger Sayle + + PR middle-end/14752 + * c-common.c (c_common_truthvalue_conversion) : Delete. Let fold optimize these + cases via the construction of "expr != 0". + 2006-02-28 Steven Bosscher * alias.c (alias_invariant, alias_invariant_size): Remove. diff --git a/gcc/c-common.c b/gcc/c-common.c index 4f8ab8e0d4b..1a11c3b189a 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -2537,37 +2537,6 @@ c_common_truthvalue_conversion (tree expr) return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)); break; - case MINUS_EXPR: - /* Perhaps reduce (x - y) != 0 to (x != y). The expressions - aren't guaranteed to the be same for modes that can represent - infinity, since if x and y are both +infinity, or both - -infinity, then x - y is not a number. - - Note that this transformation is safe when x or y is NaN. - (x - y) is then NaN, and both (x - y) != 0 and x != y will - be false. */ - if (HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (TREE_OPERAND (expr, 0))))) - break; - /* Fall through.... */ - case BIT_XOR_EXPR: - /* This and MINUS_EXPR can be changed into a comparison of the - two objects. */ - if (TREE_TYPE (TREE_OPERAND (expr, 0)) - == TREE_TYPE (TREE_OPERAND (expr, 1))) - return fold_build2 (NE_EXPR, truthvalue_type_node, - TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1)); - return fold_build2 (NE_EXPR, truthvalue_type_node, - TREE_OPERAND (expr, 0), - fold_convert (TREE_TYPE (TREE_OPERAND (expr, 0)), - TREE_OPERAND (expr, 1))); - - case BIT_AND_EXPR: - if (integer_onep (TREE_OPERAND (expr, 1)) - && TREE_TYPE (expr) != truthvalue_type_node) - /* Using convert here would cause infinite recursion. */ - return build1 (NOP_EXPR, truthvalue_type_node, expr); - break; - case MODIFY_EXPR: if (!TREE_NO_WARNING (expr)) warning (OPT_Wparentheses, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e0af45588a0..5b2507cf1c9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-02-28 Roger Sayle + + PR middle-end/14752 + * gcc.dg/fold-eqandshift-2.c: New test case. + 2006-02-28 Richard Guenther * gcc.dg/tree-ssa/pr26421.c: Fix testcase to force struct diff --git a/gcc/testsuite/gcc.dg/fold-eqandshift-2.c b/gcc/testsuite/gcc.dg/fold-eqandshift-2.c new file mode 100644 index 00000000000..14ffb852dd4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-eqandshift-2.c @@ -0,0 +1,22 @@ +/* PR middle-end/14752 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-original" } */ + +void bar (void); + +void foo (unsigned int a) +{ + if ((a >> 2) & 1) + bar (); +} + +void baz (unsigned int b) +{ + if ((~b >> 2) & 1) + bar (); +} + +/* { dg-final { scan-tree-dump-times "\\(a \& 4\\) != 0" 1 "original" } } */ +/* { dg-final { scan-tree-dump-times "\\(b \& 4\\) == 0" 1 "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */ +