intel/brw: Refactor code to commute immediates into legal positions
This will let us reuse this in a new pass shortly. Reviewed-by: Caio Oliveira <caio.oliveira@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29624>
This commit is contained in:
@@ -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 */
|
||||
|
Reference in New Issue
Block a user