commit 975dc3570759c0609e8532e9dce4127d9216ac7b
Author:     Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Mon Apr 25 22:29:16 2016 +0200
Commit:     Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Tue Apr 26 20:02:08 2016 +0200

    [cc2] Optimize jumps to jumps statements
    
    In this case of statements we are wasting time jumping
    to another jump. We can jump directly to the target jump.

diff --git a/cc2/optm.c b/cc2/optm.c
index ffc4afa..12cecb1 100644
--- a/cc2/optm.c
+++ b/cc2/optm.c
@@ -5,5 +5,15 @@
 Node *
 optm(Node *np)
 {
+       Node *dst;
+
+       switch (np->op) {
+       case OJMP:
+       case OBRANCH:
+               dst = np->u.sym->u.stmt;
+               if (dst->op == OJMP)
+                       np->u.sym = dst->u.sym;
+               break;
+       }
        return np;
 }
diff --git a/cc2/parser.c b/cc2/parser.c
index 2cfb49e..89a9e48 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -577,6 +577,7 @@ labeldcl(void)
        np->op = ONOP;
        sym = np->u.sym;
        sym->kind = SLABEL;
+       sym->u.stmt = np;
        np->label = sym;
        addstmt(np);
 }

Reply via email to