From 1618c2495b592384edc02305a26c693458464803 Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Sun, 6 Apr 2025 16:06:11 +0200 Subject: [PATCH] ir3/cp: add option to disable immediate to const lowering This will allow it to be used after ir3_imm_const_to_preamble so that we don't have to do the propagation of immediates manually there. Signed-off-by: Job Noorman Part-of: --- src/freedreno/ir3/ir3.h | 3 ++- src/freedreno/ir3/ir3_compiler_nir.c | 2 +- src/freedreno/ir3/ir3_cp.c | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/freedreno/ir3/ir3.h b/src/freedreno/ir3/ir3.h index 1d79c1850c8..1f05a2ab276 100644 --- a/src/freedreno/ir3/ir3.h +++ b/src/freedreno/ir3/ir3.h @@ -2311,7 +2311,8 @@ bool ir3_cf(struct ir3 *ir); bool ir3_shared_fold(struct ir3 *ir); /* copy-propagate: */ -bool ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so); +bool ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so, + bool lower_imm_to_const); /* common subexpression elimination: */ bool ir3_cse(struct ir3 *ir); diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c index 3502b89655f..0746756d319 100644 --- a/src/freedreno/ir3/ir3_compiler_nir.c +++ b/src/freedreno/ir3/ir3_compiler_nir.c @@ -5805,7 +5805,7 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler, /* the folding doesn't seem to work reliably on a4xx */ if (ctx->compiler->gen != 4) progress |= IR3_PASS(ir, ir3_cf); - progress |= IR3_PASS(ir, ir3_cp, so); + progress |= IR3_PASS(ir, ir3_cp, so, true); progress |= IR3_PASS(ir, ir3_cse); progress |= IR3_PASS(ir, ir3_dce, so); progress |= IR3_PASS(ir, ir3_opt_predicates, so); diff --git a/src/freedreno/ir3/ir3_cp.c b/src/freedreno/ir3/ir3_cp.c index 5714daee0cf..96fc3833b88 100644 --- a/src/freedreno/ir3/ir3_cp.c +++ b/src/freedreno/ir3/ir3_cp.c @@ -29,6 +29,7 @@ struct ir3_cp_ctx { struct ir3 *shader; struct ir3_shader_variant *so; bool progress; + bool lower_imm_to_const; }; /* is it a type preserving mov, with ok flags? @@ -124,6 +125,9 @@ static bool lower_immed(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr, unsigned n, struct ir3_register *reg, unsigned new_flags) { + if (!ctx->lower_imm_to_const) + return false; + if (!(new_flags & IR3_REG_IMMED)) return false; @@ -591,11 +595,12 @@ instr_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr) } bool -ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so) +ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so, bool lower_imm_to_const) { struct ir3_cp_ctx ctx = { .shader = ir, .so = so, + .lower_imm_to_const = lower_imm_to_const, }; /* This is a bit annoying, and probably wouldn't be necessary if we