From 5d0160a87f060053249951c27fe0a3e749c2122d Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Tue, 19 Aug 2025 12:35:38 -0700 Subject: [PATCH] brw: Pass brw_shader in fold_instruction Will be used later for the general instruction transforming function. Reviewed-by: Lionel Landwerlin Reviewed-by: Kenneth Graunke Part-of: --- src/intel/compiler/brw_opt_algebraic.cpp | 13 +++++++------ src/intel/compiler/brw_opt_copy_propagation.cpp | 4 ++-- src/intel/compiler/brw_shader.h | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/intel/compiler/brw_opt_algebraic.cpp b/src/intel/compiler/brw_opt_algebraic.cpp index 3d1931daef8..298a4a2dadc 100644 --- a/src/intel/compiler/brw_opt_algebraic.cpp +++ b/src/intel/compiler/brw_opt_algebraic.cpp @@ -87,7 +87,7 @@ brw_imm_for_type(uint64_t value, enum brw_reg_type type) * Converts a MAD to an ADD by folding the multiplicand sources. */ static void -fold_multiplicands_of_MAD(brw_inst *inst) +fold_multiplicands_of_MAD(brw_shader &s, brw_inst *inst) { assert(inst->opcode == BRW_OPCODE_MAD); assert (inst->src[1].file == IMM && @@ -133,8 +133,9 @@ fold_multiplicands_of_MAD(brw_inst *inst) } bool -brw_opt_constant_fold_instruction(const intel_device_info *devinfo, brw_inst *inst) +brw_opt_constant_fold_instruction(brw_shader &s, brw_inst *inst) { + const intel_device_info *devinfo = s.devinfo; brw_reg result; result.file = BAD_FILE; @@ -187,10 +188,10 @@ brw_opt_constant_fold_instruction(const intel_device_info *devinfo, brw_inst *in !brw_type_is_vector_imm(inst->src[0].type) && !brw_type_is_vector_imm(inst->src[1].type) && !brw_type_is_vector_imm(inst->src[2].type)) { - fold_multiplicands_of_MAD(inst); + fold_multiplicands_of_MAD(s, inst); assert(inst->opcode == BRW_OPCODE_ADD); - ASSERTED bool folded = brw_opt_constant_fold_instruction(devinfo, inst); + ASSERTED bool folded = brw_opt_constant_fold_instruction(s, inst); assert(folded); return true; @@ -331,7 +332,7 @@ brw_opt_algebraic(brw_shader &s) bool progress = false; foreach_block_and_inst_safe(block, brw_inst, inst, s.cfg) { - if (brw_opt_constant_fold_instruction(devinfo, inst)) { + if (brw_opt_constant_fold_instruction(s, inst)) { progress = true; continue; } @@ -680,7 +681,7 @@ brw_opt_algebraic(brw_shader &s) inst->src[2].file == IMM && !brw_type_is_vector_imm(inst->src[1].type) && !brw_type_is_vector_imm(inst->src[2].type)) { - fold_multiplicands_of_MAD(inst); + fold_multiplicands_of_MAD(s, inst); /* This could result in (x + 0). For floats, we want to leave this * as an ADD so that a subnormal x will get flushed to zero. diff --git a/src/intel/compiler/brw_opt_copy_propagation.cpp b/src/intel/compiler/brw_opt_copy_propagation.cpp index 8f54dff483f..cf4451e9c46 100644 --- a/src/intel/compiler/brw_opt_copy_propagation.cpp +++ b/src/intel/compiler/brw_opt_copy_propagation.cpp @@ -1440,7 +1440,7 @@ opt_copy_propagation_local(brw_shader &s, linear_ctx *lin_ctx, if (constant_progress) { commute_immediates(inst); - brw_opt_constant_fold_instruction(devinfo, inst); + brw_opt_constant_fold_instruction(s, inst); progress = true; } @@ -1992,7 +1992,7 @@ brw_opt_copy_propagation_defs(brw_shader &s) if (constant_progress) { commute_immediates(inst); - brw_opt_constant_fold_instruction(s.compiler->devinfo, inst); + brw_opt_constant_fold_instruction(s, inst); } } diff --git a/src/intel/compiler/brw_shader.h b/src/intel/compiler/brw_shader.h index 9ba4a385aec..69269c0a854 100644 --- a/src/intel/compiler/brw_shader.h +++ b/src/intel/compiler/brw_shader.h @@ -340,7 +340,7 @@ bool brw_opt_cmod_propagation(brw_shader &s); bool brw_opt_combine_constants(brw_shader &s); bool brw_opt_combine_convergent_txf(brw_shader &s); bool brw_opt_compact_virtual_grfs(brw_shader &s); -bool brw_opt_constant_fold_instruction(const intel_device_info *devinfo, brw_inst *inst); +bool brw_opt_constant_fold_instruction(brw_shader &s, brw_inst *inst); bool brw_opt_copy_propagation(brw_shader &s); bool brw_opt_copy_propagation_defs(brw_shader &s); bool brw_opt_cse_defs(brw_shader &s);