From ae06e018fa7c6c76164408835c3620c11f9b8f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Ondra=C4=8Dka?= Date: Fri, 3 May 2024 10:37:07 +0200 Subject: [PATCH] r300: fix RC_OMOD_DIV_2 modifier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend only recognizes the MUL a*0.5 pattern if there is an immediate as one of the sources, however by then the source would we already coverted to RC_FILE_NONE with constant half swizzles. So teach peephole_omod to recognize this pattern as well. RV530: total instructions in shared programs: 128860 -> 128750 (-0.09%) instructions in affected programs: 11942 -> 11832 (-0.92%) helped: 106 HURT: 17 total presub in shared programs: 8739 -> 8736 (-0.03%) presub in affected programs: 32 -> 29 (-9.38%) helped: 3 HURT: 0 total omod in shared programs: 427 -> 1212 (183.84%) omod in affected programs: 38 -> 823 (2065.79%) helped: 0 HURT: 160 total temps in shared programs: 17544 -> 17554 (0.06%) temps in affected programs: 70 -> 80 (14.29%) helped: 0 HURT: 10 total lits in shared programs: 3153 -> 3159 (0.19%) lits in affected programs: 9 -> 15 (66.67%) helped: 0 HURT: 6 total cycles in shared programs: 191334 -> 191253 (-0.04%) cycles in affected programs: 21240 -> 21159 (-0.38%) helped: 101 HURT: 27 Signed-off-by: Pavel Ondračka Part-of: --- .../drivers/r300/compiler/radeon_optimize.c | 69 ++++++++++++------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/src/gallium/drivers/r300/compiler/radeon_optimize.c b/src/gallium/drivers/r300/compiler/radeon_optimize.c index ef73d5f5143..923799aecd7 100644 --- a/src/gallium/drivers/r300/compiler/radeon_optimize.c +++ b/src/gallium/drivers/r300/compiler/radeon_optimize.c @@ -707,9 +707,28 @@ static int peephole_mul_omod( for (i = 0; i < 2; i++) { unsigned int j; if (inst_mul->U.I.SrcReg[i].File != RC_FILE_CONSTANT - && inst_mul->U.I.SrcReg[i].File != RC_FILE_TEMPORARY) { + && inst_mul->U.I.SrcReg[i].File != RC_FILE_TEMPORARY + && inst_mul->U.I.SrcReg[i].File != RC_FILE_NONE) { return 0; } + + /* The only relevant case with constant swizzles we should check for + * is multiply by one half. + */ + if (inst_mul->U.I.SrcReg[i].File == RC_FILE_NONE) { + for (j = 0; j < 4; j++) { + swz = GET_SWZ(inst_mul->U.I.SrcReg[i].Swizzle, j); + if (swz == RC_SWIZZLE_UNUSED) { + continue; + } + if (swz != RC_SWIZZLE_HALF) { + return 0; + } else { + omod_op = RC_OMOD_DIV_2; + } + } + } + if (inst_mul->U.I.SrcReg[i].File == RC_FILE_TEMPORARY) { if (temp_index != -1) { /* The instruction has two temp sources */ @@ -748,30 +767,32 @@ static int peephole_mul_omod( } } - if (!rc_src_reg_is_immediate(c, inst_mul->U.I.SrcReg[const_index].File, - inst_mul->U.I.SrcReg[const_index].Index)) { - return 0; - } - const_value = rc_get_constant_value(c, - inst_mul->U.I.SrcReg[const_index].Index, - inst_mul->U.I.SrcReg[const_index].Swizzle, - inst_mul->U.I.SrcReg[const_index].Negate, - chan); + if (omod_op == RC_OMOD_DISABLE) { + if (!rc_src_reg_is_immediate(c, inst_mul->U.I.SrcReg[const_index].File, + inst_mul->U.I.SrcReg[const_index].Index)) { + return 0; + } + const_value = rc_get_constant_value(c, + inst_mul->U.I.SrcReg[const_index].Index, + inst_mul->U.I.SrcReg[const_index].Swizzle, + inst_mul->U.I.SrcReg[const_index].Negate, + chan); - if (const_value == 2.0f) { - omod_op = RC_OMOD_MUL_2; - } else if (const_value == 4.0f) { - omod_op = RC_OMOD_MUL_4; - } else if (const_value == 8.0f) { - omod_op = RC_OMOD_MUL_8; - } else if (const_value == (1.0f / 2.0f)) { - omod_op = RC_OMOD_DIV_2; - } else if (const_value == (1.0f / 4.0f)) { - omod_op = RC_OMOD_DIV_4; - } else if (const_value == (1.0f / 8.0f)) { - omod_op = RC_OMOD_DIV_8; - } else { - return 0; + if (const_value == 2.0f) { + omod_op = RC_OMOD_MUL_2; + } else if (const_value == 4.0f) { + omod_op = RC_OMOD_MUL_4; + } else if (const_value == 8.0f) { + omod_op = RC_OMOD_MUL_8; + } else if (const_value == (1.0f / 2.0f)) { + omod_op = RC_OMOD_DIV_2; + } else if (const_value == (1.0f / 4.0f)) { + omod_op = RC_OMOD_DIV_4; + } else if (const_value == (1.0f / 8.0f)) { + omod_op = RC_OMOD_DIV_8; + } else { + return 0; + } } writer_list = rc_variable_list_get_writers_one_reader(var_list,