nir/opt_algebraic: fix fabs optimization
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

This fixes a regression found in blender's unit testing, which called
fabs(-0.0) and invoked an NIR optimization that is was not valid for
the parameter -0.0. IEEE 754 requires that abs clear the sign bit
for the value -0.0.

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41060>
This commit is contained in:
Brandon Jones 2026-04-17 09:07:43 -07:00 committed by Marge Bot
parent e5392e3d5f
commit d1dd65d425
2 changed files with 3 additions and 1 deletions

View file

@ -1943,7 +1943,8 @@ optimizations.extend([
# fract(x) = x - floor(x), so fract(NaN/Inf) = NaN
(('ffract(nnan)', 'a(is_integral)'), 0.0),
(('ffract', ('ffract', a)), ('ffract', a)),
(('fabs', 'a(is_not_negative)'), ('fcanonicalize', a)),
(('fabs(nsz)', 'a(is_not_negative)'), ('fcanonicalize', a)),
(('fabs', 'a(is_not_negative_or_negative_zero)'), ('fcanonicalize', a)),
(('fabs(nsz)', 'a(is_not_positive)'), ('fneg', a)),
(('fneu', 'a(is_not_zero)', 0.0), True),

View file

@ -891,6 +891,7 @@ RELATION_AND_NUM(lt_zero, FP_CLASS_ANY_POS | FP_CLASS_ANY_ZERO)
RELATION_AND_NUM(not_positive, FP_CLASS_ANY_POS)
RELATION_AND_NUM(gt_zero, FP_CLASS_ANY_NEG | FP_CLASS_ANY_ZERO)
RELATION_AND_NUM(not_negative, FP_CLASS_ANY_NEG)
RELATION_AND_NUM(not_negative_or_negative_zero, FP_CLASS_ANY_NEG | FP_CLASS_NEG_ZERO)
RELATION_AND_NUM(not_zero, FP_CLASS_ANY_ZERO)
RELATION_AND_NUM(zero_to_one, FP_CLASS_ANY_NEG | FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF)
RELATION_AND_NUM(le_pos_one, FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF)