diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c index 6ef6593b870..537bd1c96ea 100644 --- a/src/compiler/nir/nir_opt_large_constants.c +++ b/src/compiler/nir/nir_opt_large_constants.c @@ -533,6 +533,12 @@ nir_opt_large_constants(nir_shader *shader, nir_builder b = nir_builder_create(impl); + /* We must preserve signed zero and disallow e.g. fma fusion + * when we create new floating point instructions because it's not + * even clear the result is only used as float. + */ + b.fp_math_ctrl = nir_fp_exact | nir_fp_preserve_signed_zero; + nir_foreach_block(block, impl) { nir_foreach_instr_safe(instr, block) { if (instr->type == nir_instr_type_deref) { diff --git a/src/compiler/nir/tests/opt_large_constants_tests.cpp b/src/compiler/nir/tests/opt_large_constants_tests.cpp index f8e010c7330..4605a34c693 100644 --- a/src/compiler/nir/tests/opt_large_constants_tests.cpp +++ b/src/compiler/nir/tests/opt_large_constants_tests.cpp @@ -208,7 +208,7 @@ TEST_F(nir_large_constants_test, small_float_natural_numbers_including_zero_arra 32 %4 = ushr %1 (0x76543210), %3 32 %5 = load_const (0x0000000f = 15) 32 %6 = iand %4, %5 (0xf) - 32 %7 = u2f32 %6 + 32 %7 = u2f32 %6 // exact, preserve:sz @use (%7) // succs: b1 block b1: