diff --git a/.pick_status.json b/.pick_status.json index aa094f109a7..9a948d6f4cb 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -494,7 +494,7 @@ "description": "nir/lower_bool_to_bitsize: Make all bN_csel sources match", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/compiler/nir/nir_lower_bool_to_bitsize.c b/src/compiler/nir/nir_lower_bool_to_bitsize.c index 80879e67ce1..6ed71226324 100644 --- a/src/compiler/nir/nir_lower_bool_to_bitsize.c +++ b/src/compiler/nir/nir_lower_bool_to_bitsize.c @@ -57,6 +57,32 @@ get_bool_convert_opcode(uint32_t dst_bit_size) } } +static void +resize_bool_alu_source(nir_builder *b, nir_alu_instr *alu, + uint32_t src_idx, uint32_t bit_size) +{ + if (nir_src_bit_size(alu->src[src_idx].src) == bit_size) + return; + + b->cursor = nir_before_instr(&alu->instr); + nir_op convert_op = get_bool_convert_opcode(bit_size); + + /* Retain the number of components and swizzle of the original + * instruction so that we don’t unnecessarily create a vectorized + * instruction. + */ + nir_def *new_src = + nir_build_alu1(b, convert_op, nir_ssa_for_alu_src(b, alu, src_idx)); + + nir_src_rewrite(&alu->src[src_idx].src, new_src); + + /* The swizzle will have been handled by the conversion instruction + * so we can reset it back to the default + */ + for (unsigned j = 0; j < NIR_MAX_VEC_COMPONENTS; j++) + alu->src[src_idx].swizzle[j] = j; +} + static void make_sources_canonical(nir_builder *b, nir_alu_instr *alu, uint32_t start_idx) { @@ -65,25 +91,8 @@ make_sources_canonical(nir_builder *b, nir_alu_instr *alu, uint32_t start_idx) */ const nir_op_info *op_info = &nir_op_infos[alu->op]; uint32_t bit_size = nir_src_bit_size(alu->src[start_idx].src); - for (uint32_t i = start_idx + 1; i < op_info->num_inputs; i++) { - if (nir_src_bit_size(alu->src[i].src) != bit_size) { - b->cursor = nir_before_instr(&alu->instr); - nir_op convert_op = get_bool_convert_opcode(bit_size); - /* Retain the number of components and swizzle of the original - * instruction so that we don’t unnecessarily create a vectorized - * instruction. - */ - nir_def *new_src = - nir_build_alu1(b, convert_op, nir_ssa_for_alu_src(b, alu, i)); - - nir_src_rewrite(&alu->src[i].src, new_src); - /* The swizzle will have been handled by the conversion instruction - * so we can reset it back to the default - */ - for (unsigned j = 0; j < NIR_MAX_VEC_COMPONENTS; j++) - alu->src[i].swizzle[j] = j; - } - } + for (uint32_t i = start_idx + 1; i < op_info->num_inputs; i++) + resize_bool_alu_source(b, alu, i, bit_size); } static bool @@ -130,7 +139,9 @@ lower_alu_instr(nir_builder *b, nir_alu_instr *alu) case nir_op_bcsel: /* bcsel may be choosing between boolean sources too */ if (alu->def.bit_size == 1) - make_sources_canonical(b, alu, 1); + make_sources_canonical(b, alu, 0); + else + resize_bool_alu_source(b, alu, 0, alu->def.bit_size); break; default: