cmd/w6c/cgen+test: skip dead TRYPROP propret on same-shape ?
Per CLAUDE.md rule 10, align cstage down to wwstage — when every variant in a `?` propagation maps to itself, the remap loop emits zero JMPs and the propret label is dead. Lazy-allocate it so the label-counter ID is only consumed when at least one JMP fires. Smoke test selfhost/test/trypromote.ww exercises same-shape (i64|nomem)→(i64|nomem) propagation; cstage and wwstage now emit byte-identical asm for the TRYPROP region.
This commit is contained in:
@@ -5038,7 +5038,11 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
ins2(c, A_CMPQ, aimm(s_tag), areg(D_AX));
|
||||
ins1(c, A_JE, abranch(cont));
|
||||
if (u && r && r->kind == TY_TAGGED && u->params) {
|
||||
char *propret = mklabel(c, "tryprop_ret");
|
||||
/* Same-shape unions remap every variant to itself, so
|
||||
* the loop emits no JMPs. Skip propret entirely then —
|
||||
* wwstage doesn't emit a dead label either (CLAUDE.md
|
||||
* rule 10, task #18). */
|
||||
char *propret = NULL;
|
||||
int i = 0;
|
||||
for (Tparam *p = u->params; p; p = p->next, i++) {
|
||||
if (!cg_variant_is_error(u, i)) continue;
|
||||
@@ -5049,10 +5053,13 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
ins2(c, A_CMPQ, aimm(i), areg(D_AX));
|
||||
ins1(c, A_JNE, abranch(skip));
|
||||
ins2(c, A_MOVQ, aimm(j), areg(D_AX));
|
||||
if (propret == NULL)
|
||||
propret = mklabel(c, "tryprop_ret");
|
||||
ins1(c, A_JMP, abranch(propret));
|
||||
label(c, skip);
|
||||
}
|
||||
label(c, propret);
|
||||
if (propret != NULL)
|
||||
label(c, propret);
|
||||
}
|
||||
ins2(c, A_MOVQ, areg(D_BP), areg(D_SP));
|
||||
ins1(c, A_POPQ, areg(D_BP));
|
||||
|
||||
Reference in New Issue
Block a user