diff --git a/src/panfrost/bifrost/ISA.xml b/src/panfrost/bifrost/ISA.xml index 422ea2679fb..bda49a0f2df 100644 --- a/src/panfrost/bifrost/ISA.xml +++ b/src/panfrost/bifrost/ISA.xml @@ -8290,4 +8290,27 @@ + + + + + + none + h0 + h1 + + + + + + + + + h00 + h10 + h01 + h11 + + + diff --git a/src/panfrost/bifrost/bi_opt_mod_props.c b/src/panfrost/bifrost/bi_opt_mod_props.c index 8c5f62ca33b..004f6ed1876 100644 --- a/src/panfrost/bifrost/bi_opt_mod_props.c +++ b/src/panfrost/bifrost/bi_opt_mod_props.c @@ -66,11 +66,10 @@ bi_takes_fneg(unsigned arch, bi_instr *I, unsigned s) } static bool -bi_is_fabsneg(bi_instr *I) +bi_is_fabsneg(enum bi_opcode op, enum bi_size size) { - return (I->op == BI_OPCODE_FADD_F32 || I->op == BI_OPCODE_FADD_V2F16) && - (I->src[1].type == BI_INDEX_CONSTANT && I->src[1].value == 0) && - (I->clamp == BI_CLAMP_NONE); + return (size == BI_SIZE_32 && op == BI_OPCODE_FABSNEG_F32) || + (size == BI_SIZE_16 && op == BI_OPCODE_FABSNEG_V2F16); } static enum bi_swizzle @@ -124,10 +123,9 @@ bi_opt_mod_prop_forward(bi_context *ctx) if (!mod) continue; - if (bi_opcode_props[mod->op].size != bi_opcode_props[I->op].size) - continue; + unsigned size = bi_opcode_props[I->op].size; - if (bi_is_fabsneg(mod)) { + if (bi_is_fabsneg(mod->op, size)) { if (mod->src[0].abs && !bi_takes_fabs(ctx->arch, I, mod->src[0], s)) continue; @@ -253,3 +251,23 @@ bi_opt_mod_prop_backward(bi_context *ctx) free(uses); free(multiple); } + +/** Lower pseudo instructions that exist to simplify the optimizer */ + +void +bi_lower_opt_instruction(bi_instr *I) +{ + switch (I->op) { + case BI_OPCODE_FABSNEG_F32: + case BI_OPCODE_FABSNEG_V2F16: + I->op = (bi_opcode_props[I->op].size == BI_SIZE_32) ? + BI_OPCODE_FADD_F32 : BI_OPCODE_FADD_V2F16; + + I->round = BI_ROUND_NONE; + I->src[1] = bi_negzero(); + break; + + default: + break; + } +} diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index fbe59f64b07..0621ce8bcf9 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -1880,11 +1880,11 @@ bi_emit_alu(bi_builder *b, nir_alu_instr *instr) } case nir_op_fneg: - bi_fadd_to(b, sz, dst, bi_neg(s0), bi_negzero(), BI_ROUND_NONE); + bi_fabsneg_to(b, sz, dst, bi_neg(s0)); break; case nir_op_fabs: - bi_fadd_to(b, sz, dst, bi_abs(s0), bi_negzero(), BI_ROUND_NONE); + bi_fabsneg_to(b, sz, dst, bi_abs(s0)); break; case nir_op_fsin: @@ -3708,6 +3708,10 @@ bifrost_compile_shader_nir(nir_shader *nir, bi_validate(ctx, "Optimization passes"); } + bi_foreach_instr_global(ctx, I) { + bi_lower_opt_instruction(I); + } + bi_foreach_block(ctx, block) { bi_lower_branch(block); } diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 311c99a2730..72a878f13b8 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -902,6 +902,8 @@ void bi_lower_fau(bi_context *ctx); void bi_assign_scoreboard(bi_context *ctx); void bi_register_allocate(bi_context *ctx); +void bi_lower_opt_instruction(bi_instr *I); + void bi_schedule(bi_context *ctx); bool bi_can_fma(bi_instr *ins); bool bi_can_add(bi_instr *ins);