tccgen: return: avoid jmp to retsym if possible

When 'return' is the last statement of the top-level block
(very common and often recommended case) jump is not needed.
This commit is contained in:
Pavlas, Zdenek 2016-08-11 04:59:08 -07:00
parent 0a402f6e91
commit 71b6220963

View File

@ -4922,7 +4922,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
skip(')'); skip(')');
a = gvtst(1, 0); a = gvtst(1, 0);
b = 0; b = 0;
++local_scope;
block(&a, &b, case_sym, def_sym, case_reg, 0); block(&a, &b, case_sym, def_sym, case_reg, 0);
--local_scope;
if(!nocode_wanted) if(!nocode_wanted)
gjmp_addr(d); gjmp_addr(d);
gsym(a); gsym(a);
@ -5060,7 +5062,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
vtop--; /* NOT vpop() because on x86 it would flush the fp stack */ vtop--; /* NOT vpop() because on x86 it would flush the fp stack */
} }
skip(';'); skip(';');
rsym = gjmp(rsym); /* jmp */ /* jump unless last stmt in top-level block */
if (tok != '}' || local_scope != 1)
rsym = gjmp(rsym);
} else if (tok == TOK_BREAK) { } else if (tok == TOK_BREAK) {
/* compute jump */ /* compute jump */
if (!bsym) if (!bsym)