From 3a16ad71b760eecfbebd419fa0fcb78313148fea Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 14 Nov 2024 10:17:50 -0800 Subject: [PATCH] brw/copy: Commute immediates for MAD multiplicands This enables constant combining to do its job. v2: Restore accidentally deleted line from a comment. Noticed by Caio. shader-db: All Intel platforms had similar results. (Lunar Lake shown) total cycles in shared programs: 919668392 -> 919669310 (<.01%) cycles in affected programs: 10125264 -> 10126182 (<.01%) helped: 348 / HURT: 194 fossil-db: All Intel platforms had similar results. (Lunar Lake shown) Totals: Cycle count: 31610720660 -> 31610692748 (-0.00%); split: -0.00%, +0.00% Totals from 9066 (1.29% of 702433) affected shaders: Cycle count: 810411934 -> 810384022 (-0.00%); split: -0.01%, +0.00% Reviewed-by: Caio Oliveira Reviewed-by: Matt Turner Part-of: --- src/intel/compiler/brw_fs_copy_propagation.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/intel/compiler/brw_fs_copy_propagation.cpp b/src/intel/compiler/brw_fs_copy_propagation.cpp index be9ae9ee5d6..50e02dce4f7 100644 --- a/src/intel/compiler/brw_fs_copy_propagation.cpp +++ b/src/intel/compiler/brw_fs_copy_propagation.cpp @@ -1283,6 +1283,12 @@ commute_immediates(fs_inst *inst) } } + /* MAD can only have mutliplicand immediate in src2. */ + if (inst->opcode == BRW_OPCODE_MAD) { + if (inst->src[1].file == IMM && inst->src[2].file != IMM) + swap_srcs(inst, 1, 2); + } + /* 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.