[hackers] [scc] Fix algebraic identities about logical operators || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 4 Sep 2015 22:51:03 +0200 (CEST)

commit 03a906c70a3836ad264de982a5c7fc0bfe9cf0ef
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Sep 4 22:47:56 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Sep 4 22:47:56 2015 +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.

diff --git a/cc1/fold.c b/cc1/fold.c
index 44608bf..09c3ed4 100644
--- a/cc1/fold.c
+++ b/cc1/fold.c
_AT_@ -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
_AT_@ -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:
Received on Fri Sep 04 2015 - 22:51:03 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 04 2015 - 23:00:13 CEST