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,