re PR rtl-optimization/4046 (redundant conditional branch)

PR opt/4046
	* fold-const.c (fold) [COND_EXPR]: Simplify A ? 0 : 1 to !A,
	A ? B : 0 to A && B and A ? B : 1 into !A || B if both A and
	B are truth values.

From-SVN: r55153
This commit is contained in:
Roger Sayle 2002-07-01 20:59:00 +00:00 committed by Roger Sayle
parent 9a5c1b9db1
commit 6bfa5aac87
2 changed files with 34 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2002-07-01 Roger Sayle <roger@eyesopen.com>
PR opt/4046
* fold-const.c (fold) [COND_EXPR]: Simplify A ? 0 : 1 to !A,
A ? B : 0 to A && B and A ? B : 1 into !A || B if both A and
B are truth values.
2002-07-01 Nathanael Nerode <neroden@gcc.gnu.org>
* config/mmix/t-mmix: Eliminate last reference to LIBGCC1_TEST.

View File

@ -7036,6 +7036,14 @@ fold (expr)
&& type == TREE_TYPE (arg0))
return pedantic_non_lvalue (arg0);
/* Convert A ? 0 : 1 to !A. This prefers the use of NOT_EXPR
over COND_EXPR in cases such as floating point comparisons. */
if (integer_zerop (TREE_OPERAND (t, 1))
&& integer_onep (TREE_OPERAND (t, 2))
&& truth_value_p (TREE_CODE (arg0)))
return pedantic_non_lvalue (convert (type,
invert_truthvalue (arg0)));
/* Look for expressions of the form A & 2 ? 2 : 0. The result of this
operation is simply A & 2. */
@ -7048,6 +7056,25 @@ fold (expr)
arg1, 1))
return pedantic_non_lvalue (convert (type, TREE_OPERAND (arg0, 0)));
/* Convert A ? B : 0 into A && B if A and B are truth values. */
if (integer_zerop (TREE_OPERAND (t, 2))
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (arg1)))
return pedantic_non_lvalue (fold (build (TRUTH_ANDIF_EXPR, type,
arg0, arg1)));
/* Convert A ? B : 1 into !A || B if A and B are truth values. */
if (integer_onep (TREE_OPERAND (t, 2))
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (arg1)))
{
/* Only perform transformation if ARG0 is easily inverted. */
tem = invert_truthvalue (arg0);
if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
return pedantic_non_lvalue (fold (build (TRUTH_ORIF_EXPR, type,
tem, arg1)));
}
return t;
case COMPOUND_EXPR: