nir/lower_to_source_mods: Stop turning add, sat, and neg into mov
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
This commit is contained in:
parent
2a39788d03
commit
cd73b6174b
|
@ -78,13 +78,13 @@ nir_lower_to_source_mods_block(nir_block *block,
|
||||||
case nir_type_float:
|
case nir_type_float:
|
||||||
if (!(options & nir_lower_float_source_mods))
|
if (!(options & nir_lower_float_source_mods))
|
||||||
continue;
|
continue;
|
||||||
if (parent->op != nir_op_fmov)
|
if (parent->op != nir_op_fabs && parent->op != nir_op_fneg)
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
case nir_type_int:
|
case nir_type_int:
|
||||||
if (!(options & nir_lower_int_source_mods))
|
if (!(options & nir_lower_int_source_mods))
|
||||||
continue;
|
continue;
|
||||||
if (parent->op != nir_op_imov)
|
if (parent->op != nir_op_iabs && parent->op != nir_op_ineg)
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -98,10 +98,19 @@ nir_lower_to_source_mods_block(nir_block *block,
|
||||||
if (!parent->src[0].src.is_ssa)
|
if (!parent->src[0].src.is_ssa)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!lower_abs && parent->src[0].abs)
|
if (!lower_abs && (parent->op == nir_op_fabs &&
|
||||||
|
parent->op == nir_op_iabs))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
nir_instr_rewrite_src(instr, &alu->src[i].src, parent->src[0].src);
|
nir_instr_rewrite_src(instr, &alu->src[i].src, parent->src[0].src);
|
||||||
|
|
||||||
|
/* Apply any modifiers that come from the parent opcode */
|
||||||
|
if (parent->op == nir_op_fneg || parent->op == nir_op_ineg)
|
||||||
|
alu_src_consume_negate(&alu->src[i]);
|
||||||
|
if (parent->op == nir_op_fabs || parent->op == nir_op_iabs)
|
||||||
|
alu_src_consume_abs(&alu->src[i]);
|
||||||
|
|
||||||
|
/* Apply modifiers from the parent source */
|
||||||
if (parent->src[0].negate)
|
if (parent->src[0].negate)
|
||||||
alu_src_consume_negate(&alu->src[i]);
|
alu_src_consume_negate(&alu->src[i]);
|
||||||
if (parent->src[0].abs)
|
if (parent->src[0].abs)
|
||||||
|
@ -120,41 +129,6 @@ nir_lower_to_source_mods_block(nir_block *block,
|
||||||
progress = true;
|
progress = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options & nir_lower_float_source_mods) {
|
|
||||||
switch (alu->op) {
|
|
||||||
case nir_op_fsat:
|
|
||||||
alu->op = nir_op_fmov;
|
|
||||||
alu->dest.saturate = true;
|
|
||||||
break;
|
|
||||||
case nir_op_fneg:
|
|
||||||
alu->op = nir_op_fmov;
|
|
||||||
alu->src[0].negate = !alu->src[0].negate;
|
|
||||||
break;
|
|
||||||
case nir_op_fabs:
|
|
||||||
alu->op = nir_op_fmov;
|
|
||||||
alu->src[0].abs = true;
|
|
||||||
alu->src[0].negate = false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options & nir_lower_int_source_mods) {
|
|
||||||
switch (alu->op) {
|
|
||||||
case nir_op_ineg:
|
|
||||||
alu->op = nir_op_imov;
|
|
||||||
alu->src[0].negate = !alu->src[0].negate;
|
|
||||||
break;
|
|
||||||
case nir_op_iabs:
|
|
||||||
alu->op = nir_op_imov;
|
|
||||||
alu->src[0].abs = true;
|
|
||||||
alu->src[0].negate = false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* We've covered sources. Now we're going to try and saturate the
|
/* We've covered sources. Now we're going to try and saturate the
|
||||||
* destination if we can.
|
* destination if we can.
|
||||||
*/
|
*/
|
||||||
|
@ -188,8 +162,7 @@ nir_lower_to_source_mods_block(nir_block *block,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child_alu->op != nir_op_fsat &&
|
if (child_alu->op != nir_op_fsat) {
|
||||||
!(child_alu->op == nir_op_fmov && child_alu->dest.saturate)) {
|
|
||||||
all_children_are_sat = false;
|
all_children_are_sat = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,6 +217,9 @@ validate_alu_src(nir_alu_instr *instr, unsigned index, validate_state *state)
|
||||||
{
|
{
|
||||||
nir_alu_src *src = &instr->src[index];
|
nir_alu_src *src = &instr->src[index];
|
||||||
|
|
||||||
|
if (instr->op == nir_op_fmov || instr->op == nir_op_imov)
|
||||||
|
assert(!src->abs && !src->negate);
|
||||||
|
|
||||||
unsigned num_components = nir_src_num_components(src->src);
|
unsigned num_components = nir_src_num_components(src->src);
|
||||||
for (unsigned i = 0; i < NIR_MAX_VEC_COMPONENTS; i++) {
|
for (unsigned i = 0; i < NIR_MAX_VEC_COMPONENTS; i++) {
|
||||||
validate_assert(state, src->swizzle[i] < NIR_MAX_VEC_COMPONENTS);
|
validate_assert(state, src->swizzle[i] < NIR_MAX_VEC_COMPONENTS);
|
||||||
|
@ -319,6 +322,9 @@ validate_alu_dest(nir_alu_instr *instr, validate_state *state)
|
||||||
{
|
{
|
||||||
nir_alu_dest *dest = &instr->dest;
|
nir_alu_dest *dest = &instr->dest;
|
||||||
|
|
||||||
|
if (instr->op == nir_op_fmov || instr->op == nir_op_imov)
|
||||||
|
assert(!dest->saturate);
|
||||||
|
|
||||||
unsigned dest_size = nir_dest_num_components(dest->dest);
|
unsigned dest_size = nir_dest_num_components(dest->dest);
|
||||||
/*
|
/*
|
||||||
* validate that the instruction doesn't write to components not in the
|
* validate that the instruction doesn't write to components not in the
|
||||||
|
|
Loading…
Reference in New Issue