aco: fix combine_constant_comparison_ordering() NaN check with 16/64-bit
No fossil-db changes. Signed-off-by: Rhys Perry <pendingchaos02@gmail.com> Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Cc: mesa-stable Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7045>
This commit is contained in:
@@ -1804,6 +1804,31 @@ bool combine_comparison_ordering(opt_ctx &ctx, aco_ptr<Instruction>& instr)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_operand_constant(opt_ctx &ctx, Operand op, unsigned bit_size, uint64_t *value)
|
||||
{
|
||||
if (op.isConstant()) {
|
||||
*value = op.constantValue64();
|
||||
return true;
|
||||
} else if (op.isTemp()) {
|
||||
unsigned id = original_temp_id(ctx, op.getTemp());
|
||||
if (!ctx.info[id].is_constant_or_literal(bit_size))
|
||||
return false;
|
||||
*value = get_constant_op(ctx, ctx.info[id], bit_size).constantValue64();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_constant_nan(uint64_t value, unsigned bit_size)
|
||||
{
|
||||
if (bit_size == 16)
|
||||
return ((value >> 10) & 0x1f) == 0x1f && (value & 0x3ff);
|
||||
else if (bit_size == 32)
|
||||
return ((value >> 23) & 0xff) == 0xff && (value & 0x7fffff);
|
||||
else
|
||||
return ((value >> 52) & 0x7ff) == 0x7ff && (value & 0xfffffffffffff);
|
||||
}
|
||||
|
||||
/* s_or_b64(v_cmp_neq_f32(a, a), cmp(a, #b)) and b is not NaN -> get_unordered(cmp)(a, b)
|
||||
* s_and_b64(v_cmp_eq_f32(a, a), cmp(a, #b)) and b is not NaN -> get_ordered(cmp)(a, b) */
|
||||
bool combine_constant_comparison_ordering(opt_ctx &ctx, aco_ptr<Instruction>& instr)
|
||||
@@ -1829,7 +1854,8 @@ bool combine_constant_comparison_ordering(opt_ctx &ctx, aco_ptr<Instruction>& in
|
||||
else if (get_f32_cmp(nan_test->opcode) != expected_nan_test)
|
||||
return false;
|
||||
|
||||
if (!is_cmp(cmp->opcode) || get_cmp_bitsize(cmp->opcode) != get_cmp_bitsize(nan_test->opcode))
|
||||
unsigned bit_size = get_cmp_bitsize(cmp->opcode);
|
||||
if (!is_cmp(cmp->opcode) || get_cmp_bitsize(nan_test->opcode) != bit_size)
|
||||
return false;
|
||||
|
||||
if (!nan_test->operands[0].isTemp() || !nan_test->operands[1].isTemp())
|
||||
@@ -1858,22 +1884,10 @@ bool combine_constant_comparison_ordering(opt_ctx &ctx, aco_ptr<Instruction>& in
|
||||
if (constant_operand == -1)
|
||||
return false;
|
||||
|
||||
uint32_t constant;
|
||||
if (cmp->operands[constant_operand].isConstant()) {
|
||||
constant = cmp->operands[constant_operand].constantValue();
|
||||
} else if (cmp->operands[constant_operand].isTemp()) {
|
||||
Temp tmp = cmp->operands[constant_operand].getTemp();
|
||||
unsigned id = original_temp_id(ctx, tmp);
|
||||
if (!ctx.info[id].is_constant_or_literal(32))
|
||||
return false;
|
||||
constant = ctx.info[id].val;
|
||||
} else {
|
||||
uint64_t constant_value;
|
||||
if (!is_operand_constant(ctx, cmp->operands[constant_operand], bit_size, &constant_value))
|
||||
return false;
|
||||
}
|
||||
|
||||
float constantf;
|
||||
memcpy(&constantf, &constant, 4);
|
||||
if (isnan(constantf))
|
||||
if (is_constant_nan(constant_value, bit_size))
|
||||
return false;
|
||||
|
||||
if (cmp->operands[0].isTemp())
|
||||
|
||||
Reference in New Issue
Block a user