mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-03-11 11:20:41 +01:00
nir/algebraic: move float control conditions to be per instruction
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27281>
This commit is contained in:
parent
8c4cd3e74e
commit
7f97fa6df0
1 changed files with 21 additions and 34 deletions
|
|
@ -37,15 +37,6 @@ d = 'd'
|
|||
e = 'e'
|
||||
NAN = math.nan
|
||||
|
||||
signed_zero_preserve_16 = 'nir_is_float_control_signed_zero_preserve(info->float_controls_execution_mode, 16)'
|
||||
signed_zero_preserve_32 = 'nir_is_float_control_signed_zero_preserve(info->float_controls_execution_mode, 32)'
|
||||
signed_zero_nan_preserve_16 = ('(nir_is_float_control_signed_zero_preserve(info->float_controls_execution_mode, 16) ||'
|
||||
' nir_is_float_control_nan_preserve(info->float_controls_execution_mode, 16))')
|
||||
signed_zero_nan_preserve_32 = ('(nir_is_float_control_signed_zero_preserve(info->float_controls_execution_mode, 32) ||'
|
||||
' nir_is_float_control_nan_preserve(info->float_controls_execution_mode, 32))')
|
||||
signed_zero_inf_nan_preserve_16 = 'nir_is_float_control_signed_zero_inf_nan_preserve(info->float_controls_execution_mode, 16)'
|
||||
signed_zero_inf_nan_preserve_32 = 'nir_is_float_control_signed_zero_inf_nan_preserve(info->float_controls_execution_mode, 32)'
|
||||
|
||||
has_fmulz = '(options->has_fmulz || \
|
||||
(options->has_fmulz_no_denorms && \
|
||||
!nir_is_denorm_preserve(info->float_controls_execution_mode, 32)))'
|
||||
|
|
@ -159,8 +150,7 @@ optimizations = [
|
|||
# a+0.0 is 'a' unless 'a' is denormal or -0.0. If it's only used by a
|
||||
# floating point instruction, they should flush any input denormals and we
|
||||
# can replace -0.0 with 0.0 if the float execution mode allows it.
|
||||
(('fadd(is_only_used_as_float)', 'a@16', 0.0), a, '!'+signed_zero_preserve_16),
|
||||
(('fadd(is_only_used_as_float)', 'a@32', 0.0), a, '!'+signed_zero_preserve_32),
|
||||
(('fadd(is_only_used_as_float,nsz)', 'a', 0.0), a),
|
||||
(('iadd', a, 0), a),
|
||||
(('iadd_sat', a, 0), a),
|
||||
(('isub_sat', a, 0), a),
|
||||
|
|
@ -195,13 +185,12 @@ optimizations = [
|
|||
(('fadd', ('fsat', a), ('fsat', ('fneg', a))), ('fsat', ('fabs', a))),
|
||||
(('~fmul', a, 0.0), 0.0),
|
||||
# The only effect a*0.0 should have is when 'a' is infinity, -0.0 or NaN
|
||||
(('fmul', 'a@16', 0.0), 0.0, '!'+signed_zero_nan_preserve_16),
|
||||
(('fmul', 'a@32', 0.0), 0.0, '!'+signed_zero_nan_preserve_32),
|
||||
(('fmul(nsz,nnan)', 'a', 0.0), 0.0),
|
||||
(('fmulz', a, 0.0), 0.0),
|
||||
(('fmulz', a, 'b(is_finite_not_zero)'), ('fmul', a, b), '!'+signed_zero_preserve_32),
|
||||
(('fmulz(nsz)', a, 'b(is_finite_not_zero)'), ('fmul', a, b)),
|
||||
(('fmulz', 'a(is_finite)', 'b(is_finite)'), ('fmul', a, b)),
|
||||
(('fmulz', a, a), ('fmul', a, a)),
|
||||
(('ffmaz', a, 'b(is_finite_not_zero)', c), ('ffma', a, b, c), '!'+signed_zero_preserve_32),
|
||||
(('ffmaz(nsz)', a, 'b(is_finite_not_zero)', c), ('ffma', a, b, c)),
|
||||
(('ffmaz', 'a(is_finite)', 'b(is_finite)', c), ('ffma', a, b, c)),
|
||||
(('ffmaz', a, a, b), ('ffma', a, a, b)),
|
||||
(('imul', a, 0), 0),
|
||||
|
|
@ -223,17 +212,15 @@ optimizations = [
|
|||
(('fmul', ('fsign', a), ('fmul', a, a)), ('fmul', ('fabs', a), a)),
|
||||
(('fmul', ('fmul', ('fsign', a), a), a), ('fmul', ('fabs', a), a)),
|
||||
(('~ffma', 0.0, a, b), b),
|
||||
(('ffma@16(is_only_used_as_float)', 0.0, a, b), b, '!'+signed_zero_inf_nan_preserve_16),
|
||||
(('ffma@32(is_only_used_as_float)', 0.0, a, b), b, '!'+signed_zero_inf_nan_preserve_32),
|
||||
(('ffma(is_only_used_as_float,nsz,nnan,ninf)', 0.0, a, b), b),
|
||||
(('ffmaz', 0.0, a, b), ('fadd', 0.0, b)),
|
||||
(('~ffma', a, b, 0.0), ('fmul', a, b)),
|
||||
(('ffma@16', a, b, 0.0), ('fmul', a, b), '!'+signed_zero_preserve_16),
|
||||
(('ffma@32', a, b, 0.0), ('fmul', a, b), '!'+signed_zero_preserve_32),
|
||||
(('ffmaz', a, b, 0.0), ('fmulz', a, b), '!'+signed_zero_preserve_32),
|
||||
(('ffma(nsz)', a, b, 0.0), ('fmul', a, b)),
|
||||
(('ffmaz(nsz)', a, b, 0.0), ('fmulz', a, b)),
|
||||
(('ffma', 1.0, a, b), ('fadd', a, b)),
|
||||
(('ffmaz', 1.0, a, b), ('fadd', a, b), '!'+signed_zero_preserve_32),
|
||||
(('ffmaz(nsz)', 1.0, a, b), ('fadd', a, b)),
|
||||
(('ffma', -1.0, a, b), ('fadd', ('fneg', a), b)),
|
||||
(('ffmaz', -1.0, a, b), ('fadd', ('fneg', a), b), '!'+signed_zero_preserve_32),
|
||||
(('ffmaz(nsz)', -1.0, a, b), ('fadd', ('fneg', a), b)),
|
||||
(('~ffma', '#a', '#b', c), ('fadd', ('fmul', a, b), c)),
|
||||
(('~ffmaz', '#a', '#b', c), ('fadd', ('fmulz', a, b), c)),
|
||||
(('~flrp', a, b, 0.0), a),
|
||||
|
|
@ -287,21 +274,21 @@ optimizations = [
|
|||
|
||||
# Optimize open-coded fmulz.
|
||||
# (b==0.0 ? 0.0 : a) * (a==0.0 ? 0.0 : b) -> fmulz(a, b)
|
||||
(('fmul@32', ('bcsel', ignore_exact('feq', b, 0.0), 0.0, a), ('bcsel', ignore_exact('feq', a, 0.0), 0.0, b)),
|
||||
('fmulz', a, b), has_fmulz+' && !'+signed_zero_preserve_32),
|
||||
(('fmul@32', a, ('bcsel', ignore_exact('feq', a, 0.0), 0.0, '#b(is_not_const_zero)')),
|
||||
('fmulz', a, b), has_fmulz+' && !'+signed_zero_preserve_32),
|
||||
(('fmul@32(nsz)', ('bcsel', ignore_exact('feq', b, 0.0), 0.0, a), ('bcsel', ignore_exact('feq', a, 0.0), 0.0, b)),
|
||||
('fmulz', a, b), has_fmulz),
|
||||
(('fmul@32(nsz)', a, ('bcsel', ignore_exact('feq', a, 0.0), 0.0, '#b(is_not_const_zero)')),
|
||||
('fmulz', a, b), has_fmulz),
|
||||
|
||||
# ffma(b==0.0 ? 0.0 : a, a==0.0 ? 0.0 : b, c) -> ffmaz(a, b, c)
|
||||
(('ffma@32', ('bcsel', ignore_exact('feq', b, 0.0), 0.0, a), ('bcsel', ignore_exact('feq', a, 0.0), 0.0, b), c),
|
||||
('ffmaz', a, b, c), has_fmulz+' && !'+signed_zero_preserve_32),
|
||||
(('ffma@32', a, ('bcsel', ignore_exact('feq', a, 0.0), 0.0, '#b(is_not_const_zero)'), c),
|
||||
('ffmaz', a, b, c), has_fmulz+' && !'+signed_zero_preserve_32),
|
||||
(('ffma@32(nsz)', ('bcsel', ignore_exact('feq', b, 0.0), 0.0, a), ('bcsel', ignore_exact('feq', a, 0.0), 0.0, b), c),
|
||||
('ffmaz', a, b, c), has_fmulz),
|
||||
(('ffma@32(nsz)', a, ('bcsel', ignore_exact('feq', a, 0.0), 0.0, '#b(is_not_const_zero)'), c),
|
||||
('ffmaz', a, b, c), has_fmulz),
|
||||
|
||||
# b == 0.0 ? 1.0 : fexp2(fmul(a, b)) -> fexp2(fmulz(a, b))
|
||||
(('bcsel', ignore_exact('feq', b, 0.0), 1.0, ('fexp2', ('fmul@32', a, b))),
|
||||
(('bcsel(nsz,nnan,ninf)', ignore_exact('feq', b, 0.0), 1.0, ('fexp2', ('fmul@32', a, b))),
|
||||
('fexp2', ('fmulz', a, b)),
|
||||
has_fmulz+' && !'+signed_zero_inf_nan_preserve_32),
|
||||
has_fmulz),
|
||||
]
|
||||
|
||||
# Shorthand for the expansion of just the dot product part of the [iu]dp4a
|
||||
|
|
@ -845,7 +832,7 @@ optimizations.extend([
|
|||
(('fsat', ('fsat', a)), ('fsat', a)),
|
||||
(('fsat', ('fneg(is_used_once)', ('fadd(is_used_once)', a, b))), ('fsat', ('fadd', ('fneg', a), ('fneg', b))), '!options->lower_fsat'),
|
||||
(('fsat', ('fneg(is_used_once)', ('fmul(is_used_once)', a, b))), ('fsat', ('fmul', ('fneg', a), b)), '!options->lower_fsat'),
|
||||
(('fsat', ('fneg(is_used_once)', ('fmulz(is_used_once)', a, b))), ('fsat', ('fmulz', ('fneg', a), b)), '!options->lower_fsat && !'+signed_zero_preserve_32),
|
||||
(('fsat(nsz)', ('fneg(is_used_once)', ('fmulz(is_used_once)', a, b))), ('fsat', ('fmulz', ('fneg', a), b)), '!options->lower_fsat'),
|
||||
(('fsat', ('fabs(is_used_once)', ('fmul(is_used_once)', a, b))), ('fsat', ('fmul', ('fabs', a), ('fabs', b))), '!options->lower_fsat'),
|
||||
(('fmin', ('fmax', ('fmin', ('fmax', a, b), c), b), c), ('fmin', ('fmax', a, b), c)),
|
||||
(('imin', ('imax', ('imin', ('imax', a, b), c), b), c), ('imin', ('imax', a, b), c)),
|
||||
|
|
@ -1858,7 +1845,7 @@ optimizations.extend([
|
|||
|
||||
# Propagate negation up multiplication chains
|
||||
(('fmul(is_used_by_non_fsat)', ('fneg', a), b), ('fneg', ('fmul', a, b))),
|
||||
(('fmulz(is_used_by_non_fsat)', ('fneg', a), b), ('fneg', ('fmulz', a, b)), '!'+signed_zero_preserve_32),
|
||||
(('fmulz(is_used_by_non_fsat,nsz)', ('fneg', a), b), ('fneg', ('fmulz', a, b))),
|
||||
(('ffma', ('fneg', a), ('fneg', b), c), ('ffma', a, b, c)),
|
||||
(('ffmaz', ('fneg', a), ('fneg', b), c), ('ffmaz', a, b, c)),
|
||||
(('imul', ('ineg', a), b), ('ineg', ('imul', a, b))),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue