commit 03a906c70a3836ad264de982a5c7fc0bfe9cf0ef
parent 7e3cb239304785b9a53e2e04709d34a7ad92815c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  4 Sep 2015 22:47:56 +0200
Fix algebraic identities about logical operators
If the right part of a logic operator is a constant (which comes from
the folding of some comparision), then the logic operator can be
changed to a comma operator.
Diffstat:
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/cc1/fold.c b/cc1/fold.c
@@ -377,10 +377,8 @@ ones(int n)
 }
 
 /*
- * i || 0 => i,0
- * i || 1 => i
- * i && 0 => i,0
- * i && 1 => i
+ * i || k => i,k
+ * i && k => i,k
  * i >> 0 => i
  * i << 0 => i
  * i + 0  => i
@@ -406,17 +404,10 @@ identity(int *op, Node *lp, Node *rp)
 	istrue = !iszero && rp->constant;
 
 	switch (*op) {
-	case OOR:
-		if (istrue)
-			goto change_to_comma;
-		if (iszero)
-			break;
-		return NULL;
 	case OAND:
-		if (iszero)
+	case OOR:
+		if (rp->constant)
 			goto change_to_comma;
-		if (istrue)
-			break;
 		return NULL;
 	case OSHL:
 	case OSHR: