diff --git a/src/intel/compiler/brw_fs_copy_propagation.cpp b/src/intel/compiler/brw_fs_copy_propagation.cpp index ce851843bb8..225dee2cc2a 100644 --- a/src/intel/compiler/brw_fs_copy_propagation.cpp +++ b/src/intel/compiler/brw_fs_copy_propagation.cpp @@ -1281,6 +1281,30 @@ can_propagate_from(fs_inst *inst) is_identity_payload(FIXED_GRF, inst); } +static void +commute_immediates(fs_inst *inst) +{ + /* ADD3 can only have the immediate as src0. */ + if (inst->opcode == BRW_OPCODE_ADD3) { + if (inst->src[2].file == IMM) { + const auto src0 = inst->src[0]; + inst->src[0] = inst->src[2]; + inst->src[2] = src0; + } + } + + /* If only one of the sources of a 2-source, commutative instruction (e.g., + * AND) is immediate, it must be src1. If both are immediate, opt_algebraic + * should fold it away. + */ + if (inst->sources == 2 && inst->is_commutative() && + inst->src[0].file == IMM && inst->src[1].file != IMM) { + const auto src1 = inst->src[1]; + inst->src[1] = inst->src[0]; + inst->src[0] = src1; + } +} + /* Walks a basic block and does copy propagation on it using the acp * list. */ @@ -1319,26 +1343,7 @@ opt_copy_propagation_local(const brw_compiler *compiler, linear_ctx *lin_ctx, if (instruction_progress) { progress = true; - - /* ADD3 can only have the immediate as src0. */ - if (inst->opcode == BRW_OPCODE_ADD3) { - if (inst->src[2].file == IMM) { - const auto src0 = inst->src[0]; - inst->src[0] = inst->src[2]; - inst->src[2] = src0; - } - } - - /* If only one of the sources of a 2-source, commutative instruction (e.g., - * AND) is immediate, it must be src1. If both are immediate, opt_algebraic - * should fold it away. - */ - if (inst->sources == 2 && inst->is_commutative() && - inst->src[0].file == IMM && inst->src[1].file != IMM) { - const auto src1 = inst->src[1]; - inst->src[1] = inst->src[0]; - inst->src[0] = src1; - } + commute_immediates(inst); } /* kill the destination from the ACP */