ref: 3e0c85ff63fcc55aa3874a9d64e0c6a2c45e943a
parent: e1715607a4c65b30729c43c736eb67b957f35073
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Jul 1 14:45:00 EDT 2017
[cc1] Optimize simplify() Simplify is called for every tree, and it was following the same logic for unary and binary operators, causing unaries waste a big amount of time when it could be easily avoid
--- a/cc1/fold.c
+++ b/cc1/fold.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
static char sccsid[] = "@(#) ./cc1/fold.c";
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -428,10 +429,7 @@
Node *p, *lp = np->left, *rp = np->right;
Type *tp = np->type;
- if (!lp && !rp)
- return np;
- if (!rp && (p = foldunary(np, lp)) != NULL)
- return p;
+ assert(lp && rp);
if ((op == ODIV || op == OMOD) && cmpnode(rp, 0)) {
warn("division by 0");
return NULL;
@@ -657,6 +655,21 @@
return foldternary(np, l, r);
case OCALL:
case OPAR:
+ case OSYM:
+ return np;
+ case OSNEG:
+ case OCPL:
+ case OADDR:
+ case OPTR:
+ case INC:
+ case DEC:
+ case OASSIGN:
+ case OA_ADD:
+ case OA_SUB:
+ case OCAST:
+ assert(!r);
+ if ((p = foldunary(np, l)) != NULL)
+ return p;
return np;
default:
commutative(np, l, r);