Commit 772447c5 by Richard Kenner

(invert_truthvalue, case TRUTH_XOR_EXPR): New case.

(fold, case TRUTH_XOR_EXPR): New case.
(fold, case TRUTH_OR_EXPR, TRUTH_AND_EXPR): Check for second operand
of appropriate value to determine result whether or not first operand
is a constant.

From-SVN: r2997
parent f7c8fb3f
...@@ -2034,6 +2034,20 @@ invert_truthvalue (arg) ...@@ -2034,6 +2034,20 @@ invert_truthvalue (arg)
invert_truthvalue (TREE_OPERAND (arg, 0)), invert_truthvalue (TREE_OPERAND (arg, 0)),
invert_truthvalue (TREE_OPERAND (arg, 1))); invert_truthvalue (TREE_OPERAND (arg, 1)));
case TRUTH_XOR_EXPR:
/* Here we can invert either operand. We invert the first operand
unless the second operand is a TRUTH_NOT_EXPR in which case our
result is the XOR of the first operand with the inside of the
negation of the second operand. */
if (TREE_CODE (TREE_OPERAND (arg, 1)) == TRUTH_NOT_EXPR)
return build (TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0),
TREE_OPERAND (TREE_OPERAND (arg, 1), 0));
else
return build (TRUTH_XOR_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)),
TREE_OPERAND (arg, 1));
case TRUTH_ANDIF_EXPR: case TRUTH_ANDIF_EXPR:
return build (TRUTH_ORIF_EXPR, type, return build (TRUTH_ORIF_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)), invert_truthvalue (TREE_OPERAND (arg, 0)),
...@@ -3697,7 +3711,7 @@ fold (expr) ...@@ -3697,7 +3711,7 @@ fold (expr)
and their values must be 0 or 1. and their values must be 0 or 1.
("true" is a fixed value perhaps depending on the language.) */ ("true" is a fixed value perhaps depending on the language.) */
/* If first arg is constant zero, return it. */ /* If first arg is constant zero, return it. */
if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0)) if (integer_zerop (arg0))
return arg0; return arg0;
case TRUTH_AND_EXPR: case TRUTH_AND_EXPR:
/* If either arg is constant true, drop it. */ /* If either arg is constant true, drop it. */
...@@ -3705,9 +3719,10 @@ fold (expr) ...@@ -3705,9 +3719,10 @@ fold (expr)
return non_lvalue (arg1); return non_lvalue (arg1);
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1)) if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
return non_lvalue (arg0); return non_lvalue (arg0);
/* Both known to be zero => return zero. */ /* If second arg is constant zero, result is zero, but first arg
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) must be evaluated. */
return arg0; if (integer_zerop (arg1))
return omit_one_operand (type, arg1, arg0);
truth_andor: truth_andor:
/* Check for the possibility of merging component references. If our /* Check for the possibility of merging component references. If our
...@@ -3742,11 +3757,25 @@ fold (expr) ...@@ -3742,11 +3757,25 @@ fold (expr)
return non_lvalue (arg1); return non_lvalue (arg1);
if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1)) if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1))
return non_lvalue (arg0); return non_lvalue (arg0);
/* Both known to be true => return true. */ /* If second arg is constant true, result is true, but we must
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) evaluate first arg. */
return arg0; if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
return omit_one_operand (type, arg1, arg0);
goto truth_andor; goto truth_andor;
case TRUTH_XOR_EXPR:
/* If either arg is constant zero, drop it. */
if (integer_zerop (arg0))
return non_lvalue (arg1);
if (integer_zerop (arg1))
return non_lvalue (arg0);
/* If either arg is constant true, this is a logical inversion. */
if (integer_onep (arg0))
return non_lvalue (invert_truthvalue (arg1));
if (integer_onep (arg1))
return non_lvalue (invert_truthvalue (arg0));
break;
case EQ_EXPR: case EQ_EXPR:
case NE_EXPR: case NE_EXPR:
case LT_EXPR: case LT_EXPR:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment