nir_range_analysis: Use fmin/fmax to fix NAN handling

The following probable MSVC bug clued us in to some probably-unexpected behavior:
https://developercommunity.visualstudio.com/t/Incorrect-SSE-code-for-minmax-with-NaNs/10687862

Change the logic here so that we're always starting with NANs and use
fmin/fmax, which have more-deterministic handling of NANs. If one argument
is NAN, the non-NAN argument is returned. The previous code would've returned
the second argument if one was NAN.

Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29822>
This commit is contained in:
Jesse Natalie 2024-06-20 10:55:56 -07:00 committed by Marge Bot
parent 0ad1c80250
commit d9eacb05c9

View file

@ -175,8 +175,8 @@ analyze_constant(const struct nir_alu_instr *instr, unsigned src,
switch (nir_alu_type_get_base_type(use_type)) {
case nir_type_float: {
double min_value = DBL_MAX;
double max_value = -DBL_MAX;
double min_value = NAN;
double max_value = NAN;
bool any_zero = false;
bool all_zero = true;
@ -199,8 +199,8 @@ analyze_constant(const struct nir_alu_instr *instr, unsigned src,
any_zero = any_zero || (v == 0.0);
all_zero = all_zero && (v == 0.0);
min_value = MIN2(min_value, v);
max_value = MAX2(max_value, v);
min_value = fmin(min_value, v);
max_value = fmax(max_value, v);
}
assert(any_zero >= all_zero);