ref: b5fe10c6fb6606d271bc75e2245a801286f91bb4
parent: 0e5ae348472d5ffb37f27761e190c6208554cb9c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Mar 18 03:02:14 EDT 2015
Convert additions to increments When the immediate value is small is better to use increments instead of an addition.
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -243,6 +243,7 @@
add(Node *np)
{
Node *lp = np->left, *rp = np->right;
+ uint8_t i;
if (rp->op == REG || lp->op == CONST) {
conmute(np);
@@ -300,7 +301,17 @@
abort();
}
add_A:
+ if (rp->op == CONST) {
+ if ((i = rp->sym->u.imm) == 0)
+ goto update_A;
+ if (i < 4) {
+ while (i--)
+ code(INC, lp, NULL);
+ goto update_A;
+ }
+ }
code(ADD, lp, rp);
+ update_A:
np->op = REG;
np->reg = A;
break;