[Mesa-dev] [PATCH] glsl_to_tgsi: Skip useless comparison instructions.
Matt Turner
mattst88 at gmail.com
Tue Dec 1 17:19:33 PST 2015
On Tue, Dec 1, 2015 at 5:17 PM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> On Tue, Dec 1, 2015 at 8:12 PM, Matt Turner <mattst88 at gmail.com> wrote:
>> ---
>> src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 16 ++++++++++++++--
>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> index 7f58b44..89ad6cd 100644
>> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> @@ -1655,7 +1655,13 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
>> st_dst_reg temp_dst = st_dst_reg(temp);
>> st_src_reg temp1 = st_src_reg(temp), temp2 = st_src_reg(temp);
>>
>> - emit_asm(ir, TGSI_OPCODE_SEQ, st_dst_reg(temp), op[0], op[1]);
>> + if (ir->operands[0]->type->is_boolean() &&
>> + ir->operands[1]->as_constant() &&
>> + ir->operands[1]->as_constant()->is_one()) {
>> + emit_asm(ir, TGSI_OPCODE_MOV, st_dst_reg(temp), op[0]);
>> + } else {
>> + emit_asm(ir, TGSI_OPCODE_SEQ, st_dst_reg(temp), op[0], op[1]);
>> + }
>>
>> /* Emit 1-3 AND operations to combine the SEQ results. */
>> switch (ir->operands[0]->type->vector_elements) {
>> @@ -1708,7 +1714,13 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
>> st_src_reg temp = get_temp(native_integers ?
>> glsl_type::uvec4_type :
>> glsl_type::vec4_type);
>> - emit_asm(ir, TGSI_OPCODE_SNE, st_dst_reg(temp), op[0], op[1]);
>> + if (ir->operands[0]->type->is_boolean() &&
>> + ir->operands[1]->as_constant() &&
>> + ir->operands[1]->as_constant()->is_zero()) {
>> + emit_asm(ir, TGSI_OPCODE_MOV, st_dst_reg(temp), op[0]);
>> + } else {
>> + emit_asm(ir, TGSI_OPCODE_SNE, st_dst_reg(temp), op[0], op[1]);
>> + }
>>
>> if (native_integers) {
>> st_dst_reg temp_dst = st_dst_reg(temp);
>
> Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>
>
> I'd feel a little better if you double-checked that a shader_test that
> hits this continues to pass with llvmpipe or softpipe.
I tested vs-all-bvec4-using-if.shader_test and
vs-any-bvec4-using-if.shader_test on llvmpipe. They both pass and drop
an instruction.
More information about the mesa-dev
mailing list