continue;
nvi->def[0] = sti->def[0];
+ nvi->def[0]->insn = nvi;
nvi->fixed = sti->fixed;
nv_nvi_delete(sti);
if (j == 0 && ld->src[4]) /* can't load shared mem */
continue;
- /* fold it ! */ /* XXX: ref->insn */
+ /* fold it ! */
nv_reference(ctx->pc, &nvi->src[j], ld->src[0]->value);
if (ld->src[4])
nv_reference(ctx->pc, &nvi->src[4], ld->src[4]->value);
return 0;
}
+/* NOTE: Assumes loads have not yet been folded. */
static int
nv_pass_lower_mods(struct nv_pass *ctx, struct nv_basic_block *b)
{
nvi->src[1]->mod ^= NV_MOD_NEG;
}
- /* should not put any modifiers on NEG and ABS */
- assert(nvi->opcode != NV_MOD_NEG || !nvi->src[0]->mod);
- assert(nvi->opcode != NV_MOD_ABS || !nvi->src[0]->mod);
-
- for (j = 0; j < 4; ++j) {
- if (!nvi->src[j])
- break;
-
+ for (j = 0; j < 4 && nvi->src[j]; ++j) {
mi = nvi->src[j]->value->insn;
if (!mi)
continue;
if (mi->opcode == NV_OP_ABS) mod = NV_MOD_ABS;
else
continue;
+ assert(!(mod & mi->src[0]->mod & NV_MOD_NEG));
+
+ mod |= mi->src[0]->mod;
+
+ if (mi->flags_def || mi->flags_src)
+ continue;
- if (nvi->opcode == NV_OP_ABS)
+ if ((nvi->opcode == NV_OP_ABS) || (nvi->src[j]->mod & NV_MOD_ABS)) {
+ /* abs neg [abs] = abs */
mod &= ~(NV_MOD_NEG | NV_MOD_ABS);
- else
- if (nvi->opcode == NV_OP_NEG && mod == NV_MOD_NEG) {
- nvi->opcode = NV_OP_MOV;
+ } else
+ if ((nvi->opcode == NV_OP_NEG) && (mod & NV_MOD_NEG)) {
+ /* neg as opcode and modifier on same insn cannot occur */
+ /* neg neg abs = abs, neg neg = identity */
+ assert(j == 0);
+ if (mod & NV_MOD_ABS)
+ nvi->opcode = NV_OP_ABS;
+ else
+ if (nvi->flags_def)
+ nvi->opcode = NV_OP_CVT;
+ else
+ nvi->opcode = NV_OP_MOV;
mod = 0;
}
- if (!(nv50_supported_src_mods(nvi->opcode, j) & mod))
+ if ((nv50_supported_src_mods(nvi->opcode, j) & mod) != mod)
continue;
nv_reference(ctx->pc, &nvi->src[j], mi->src[0]->value);
if (nvi->opcode == NV_OP_SAT) {
mi = nvi->src[0]->value->insn;
- if ((mi->opcode == NV_OP_MAD) && !mi->flags_def) {
- mi->saturate = 1;
- mi->def[0] = nvi->def[0];
- nv_nvi_delete(nvi);
- }
+ if (mi->opcode != NV_OP_ADD || mi->opcode != NV_OP_MAD)
+ continue;
+ if (mi->flags_def || mi->def[0]->refc > 1)
+ continue;
+
+ mi->saturate = 1;
+ mi->def[0] = nvi->def[0];
+ mi->def[0]->insn = mi;
+ nv_nvi_delete(nvi);
}
}
DESCEND_ARBITRARY(j, nv_pass_lower_mods);
for (n1 = 0, nvi = b->out[1]->entry; nvi; nvi = nvi->next, ++n1)
if (!nv50_nvi_can_predicate(nvi))
break;
-#ifdef NV50_PC_DEBUG
+#ifdef NV50PC_DEBUG
if (nvi) {
debug_printf("cannot predicate: "); nv_print_instruction(nvi);
}
if (ret)
return ret;
+ pc->pass_seq++;
+ ret = nv_pass_lower_mods(&pass, root);
+ if (ret)
+ return ret;
+
pc->pass_seq++;
ret = nv_pass_fold_loads(&pass, root);
if (ret)
if (ret)
return ret;
- pc->pass_seq++;
- ret = nv_pass_lower_mods(&pass, root);
- if (ret)
- return ret;
-
dce.pc = pc;
do {
dce.removed = 0;