]> Cypherpunks repositories - gostls13.git/commitdiff
gc: elide dead code
authorRuss Cox <rsc@golang.org>
Thu, 7 Oct 2010 08:42:26 +0000 (04:42 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 7 Oct 2010 08:42:26 +0000 (04:42 -0400)
R=ken2
CC=golang-dev
https://golang.org/cl/2365044

src/cmd/gc/gen.c

index d2396aa09f0aa70732c71dbc390cd48f8ffd4b14..a8b2e1b8ed2a63460255240c9c0686b2ac147186 100644 (file)
@@ -257,6 +257,17 @@ gen(Node *n)
                break;
 
        case OIF:
+               if(n->ntest == N || n->ntest->op == OLITERAL) {
+                       // drop dead code in if true or if false.
+                       // the linker will do it for us in general,
+                       // but this avoids writnig to the object file
+                       // in a very common case.
+                       if(n->ntest == N || n->ntest->val.u.bval)
+                               genlist(n->nbody);
+                       else
+                               genlist(n->nelse);
+                       break;
+               }
                p1 = gjmp(P);                   //              goto test
                p2 = gjmp(P);                   // p2:          goto else
                patch(p1, pc);                          // test: