Create a backend_inst::is_commutative() method to replace two static functions that did the exact same thing.
Signed-off-by: Kenneth Graunke <kenn...@whitecape.org> --- src/mesa/drivers/dri/i965/brw_fs.cpp | 22 ++++++++++++++++++++++ src/mesa/drivers/dri/i965/brw_fs.h | 1 + src/mesa/drivers/dri/i965/brw_fs_cse.cpp | 24 +----------------------- src/mesa/drivers/dri/i965/brw_shader.cpp | 22 ++++++++++++++++++++++ src/mesa/drivers/dri/i965/brw_shader.h | 1 + src/mesa/drivers/dri/i965/brw_vec4_cse.cpp | 24 +----------------------- 6 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index 8702ea8..f53584a 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -2527,6 +2527,27 @@ fs_visitor::opt_algebraic() } bool +fs_visitor::opt_commute_immediates() +{ + bool progress = false; + + foreach_block_and_inst(block, fs_inst, inst, cfg) { + if (inst->is_commutative() && inst->src[0].file == IMM) { + if (inst->src[1].file != IMM) { + fs_reg temp = inst->src[1]; + inst->src[1] = inst->src[0]; + inst->src[0] = temp; + progress = true; + } else { + perf_debug("shader contains an instruction with two immediates"); + } + } + } + + return progress; +} + +bool fs_visitor::opt_register_renaming() { bool progress = false; @@ -3714,6 +3735,7 @@ fs_visitor::optimize() OPT(remove_duplicate_mrf_writes); OPT(opt_algebraic); + OPT(opt_commute_immediates); OPT(opt_cse); OPT(opt_copy_propagate); OPT(opt_peephole_predicated_break); diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h index 7716529..09df02b 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.h +++ b/src/mesa/drivers/dri/i965/brw_fs.h @@ -218,6 +218,7 @@ public: void calculate_live_intervals(); void calculate_register_pressure(); bool opt_algebraic(); + bool opt_commute_immediates(); bool opt_redundant_discard_jumps(); bool opt_cse(); bool opt_cse_local(bblock_t *block); diff --git a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp index ae069bb..ca5b32f 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp @@ -109,28 +109,6 @@ is_expression(const fs_inst *const inst) } static bool -is_expression_commutative(const fs_inst *inst) -{ - switch (inst->opcode) { - case BRW_OPCODE_AND: - case BRW_OPCODE_OR: - case BRW_OPCODE_XOR: - case BRW_OPCODE_ADD: - case BRW_OPCODE_MUL: - return true; - case BRW_OPCODE_SEL: - /* MIN and MAX are commutative. */ - if (inst->conditional_mod == BRW_CONDITIONAL_GE || - inst->conditional_mod == BRW_CONDITIONAL_L) { - return true; - } - /* fallthrough */ - default: - return false; - } -} - -static bool operands_match(const fs_inst *a, const fs_inst *b) { fs_reg *xs = a->src; @@ -140,7 +118,7 @@ operands_match(const fs_inst *a, const fs_inst *b) return xs[0].equals(ys[0]) && ((xs[1].equals(ys[1]) && xs[2].equals(ys[2])) || (xs[2].equals(ys[1]) && xs[1].equals(ys[2]))); - } else if (!is_expression_commutative(a)) { + } else if (!a->is_commutative()) { bool match = true; for (int i = 0; i < a->sources; i++) { if (!xs[i].equals(ys[i])) { diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp index ff0ef4b..51c965c 100644 --- a/src/mesa/drivers/dri/i965/brw_shader.cpp +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp @@ -769,6 +769,28 @@ backend_reg::is_accumulator() const } bool +backend_instruction::is_commutative() const +{ + switch (opcode) { + case BRW_OPCODE_AND: + case BRW_OPCODE_OR: + case BRW_OPCODE_XOR: + case BRW_OPCODE_ADD: + case BRW_OPCODE_MUL: + return true; + case BRW_OPCODE_SEL: + /* MIN and MAX are commutative. */ + if (conditional_mod == BRW_CONDITIONAL_GE || + conditional_mod == BRW_CONDITIONAL_L) { + return true; + } + /* fallthrough */ + default: + return false; + } +} + +bool backend_instruction::is_3src() const { return opcode < ARRAY_SIZE(opcode_descs) && opcode_descs[opcode].nsrc == 3; diff --git a/src/mesa/drivers/dri/i965/brw_shader.h b/src/mesa/drivers/dri/i965/brw_shader.h index 5c95355..f8cc98a 100644 --- a/src/mesa/drivers/dri/i965/brw_shader.h +++ b/src/mesa/drivers/dri/i965/brw_shader.h @@ -94,6 +94,7 @@ struct backend_instruction : public exec_node { bool is_tex() const; bool is_math() const; bool is_control_flow() const; + bool is_commutative() const; bool can_do_source_mods() const; bool can_do_saturate() const; bool can_do_cmod() const; diff --git a/src/mesa/drivers/dri/i965/brw_vec4_cse.cpp b/src/mesa/drivers/dri/i965/brw_vec4_cse.cpp index 5fb8f31..2c29d9f 100644 --- a/src/mesa/drivers/dri/i965/brw_vec4_cse.cpp +++ b/src/mesa/drivers/dri/i965/brw_vec4_cse.cpp @@ -89,28 +89,6 @@ is_expression(const vec4_instruction *const inst) } static bool -is_expression_commutative(const vec4_instruction *inst) -{ - switch (inst->opcode) { - case BRW_OPCODE_AND: - case BRW_OPCODE_OR: - case BRW_OPCODE_XOR: - case BRW_OPCODE_ADD: - case BRW_OPCODE_MUL: - return true; - case BRW_OPCODE_SEL: - /* MIN and MAX are commutative. */ - if (inst->conditional_mod == BRW_CONDITIONAL_GE || - inst->conditional_mod == BRW_CONDITIONAL_L) { - return true; - } - /* fallthrough */ - default: - return false; - } -} - -static bool operands_match(const vec4_instruction *a, const vec4_instruction *b) { const src_reg *xs = a->src; @@ -120,7 +98,7 @@ operands_match(const vec4_instruction *a, const vec4_instruction *b) return xs[0].equals(ys[0]) && ((xs[1].equals(ys[1]) && xs[2].equals(ys[2])) || (xs[2].equals(ys[1]) && xs[1].equals(ys[2]))); - } else if (!is_expression_commutative(a)) { + } else if (!a->is_commutative()) { return xs[0].equals(ys[0]) && xs[1].equals(ys[1]) && xs[2].equals(ys[2]); } else { return (xs[0].equals(ys[0]) && xs[1].equals(ys[1])) || -- 2.2.2 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev