2020-02-18 20:52:42 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-12-12 19:13:10 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2014 Intel Corporation
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
# copy of this software and associated documentation files (the "Software"),
|
|
|
|
# to deal in the Software without restriction, including without limitation
|
|
|
|
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
# and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
# Software is furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice (including the next
|
|
|
|
# paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
# Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
# IN THE SOFTWARE.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Jason Ekstrand (jason@jlekstrand.net)
|
|
|
|
|
2018-06-27 11:37:38 +01:00
|
|
|
from collections import OrderedDict
|
2014-12-12 19:13:10 +00:00
|
|
|
import nir_algebraic
|
2018-12-06 18:56:33 +00:00
|
|
|
from nir_opcodes import type_sizes
|
2018-02-07 01:27:53 +00:00
|
|
|
import itertools
|
2019-11-02 02:53:06 +00:00
|
|
|
import struct
|
2019-05-08 15:26:49 +01:00
|
|
|
from math import pi
|
2014-12-12 19:13:10 +00:00
|
|
|
|
|
|
|
# Convenience variables
|
|
|
|
a = 'a'
|
|
|
|
b = 'b'
|
|
|
|
c = 'c'
|
|
|
|
d = 'd'
|
2018-09-06 04:45:19 +01:00
|
|
|
e = 'e'
|
2014-12-12 19:13:10 +00:00
|
|
|
|
2020-07-15 11:16:33 +01:00
|
|
|
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)'
|
|
|
|
|
2014-12-12 19:13:10 +00:00
|
|
|
# Written in the form (<search>, <replace>) where <search> is an expression
|
|
|
|
# and <replace> is either an expression or a value. An expression is
|
2016-03-17 18:04:49 +00:00
|
|
|
# defined as a tuple of the form ([~]<op>, <src0>, <src1>, <src2>, <src3>)
|
2014-12-12 19:13:10 +00:00
|
|
|
# where each source is either an expression or a value. A value can be
|
2015-01-29 00:42:20 +00:00
|
|
|
# either a numeric constant or a string representing a variable name.
|
|
|
|
#
|
2016-03-17 18:04:49 +00:00
|
|
|
# If the opcode in a search expression is prefixed by a '~' character, this
|
|
|
|
# indicates that the operation is inexact. Such operations will only get
|
|
|
|
# applied to SSA values that do not have the exact bit set. This should be
|
|
|
|
# used by by any optimizations that are not bit-for-bit exact. It should not,
|
|
|
|
# however, be used for backend-requested lowering operations as those need to
|
|
|
|
# happen regardless of precision.
|
|
|
|
#
|
2019-06-21 02:23:53 +01:00
|
|
|
# Variable names are specified as "[#]name[@type][(cond)][.swiz]" where:
|
|
|
|
# "#" indicates that the given variable will only match constants,
|
|
|
|
# type indicates that the given variable will only match values from ALU
|
|
|
|
# instructions with the given output type,
|
|
|
|
# (cond) specifies an additional condition function (see nir_search_helpers.h),
|
|
|
|
# swiz is a swizzle applied to the variable (only in the <replace> expression)
|
2015-01-29 00:42:20 +00:00
|
|
|
#
|
|
|
|
# For constants, you have to be careful to make sure that it is the right
|
|
|
|
# type because python is unaware of the source and destination types of the
|
2014-12-12 19:13:10 +00:00
|
|
|
# opcodes.
|
2016-04-25 20:23:38 +01:00
|
|
|
#
|
|
|
|
# All expression types can have a bit-size specified. For opcodes, this
|
|
|
|
# looks like "op@32", for variables it is "a@32" or "a@uint32" to specify a
|
2018-12-18 21:28:22 +00:00
|
|
|
# type and size. In the search half of the expression this indicates that it
|
|
|
|
# should only match that particular bit-size. In the replace half of the
|
|
|
|
# expression this indicates that the constructed value should have that
|
|
|
|
# bit-size.
|
2019-06-24 23:12:56 +01:00
|
|
|
#
|
2019-10-24 21:41:59 +01:00
|
|
|
# If the opcode in a replacement expression is prefixed by a '!' character,
|
|
|
|
# this indicated that the new expression will be marked exact.
|
|
|
|
#
|
2019-06-24 23:12:56 +01:00
|
|
|
# A special condition "many-comm-expr" can be used with expressions to note
|
|
|
|
# that the expression and its subexpressions have more commutative expressions
|
|
|
|
# than nir_replace_instr can handle. If this special condition is needed with
|
|
|
|
# another condition, the two can be separated by a comma (e.g.,
|
|
|
|
# "(many-comm-expr,is_used_once)").
|
2014-12-12 19:13:10 +00:00
|
|
|
|
2019-05-08 15:26:49 +01:00
|
|
|
# based on https://web.archive.org/web/20180105155939/http://forum.devmaster.net/t/fast-and-accurate-sine-cosine/9648
|
|
|
|
def lowered_sincos(c):
|
|
|
|
x = ('fsub', ('fmul', 2.0, ('ffract', ('fadd', ('fmul', 0.5 / pi, a), c))), 1.0)
|
|
|
|
x = ('fmul', ('fsub', x, ('fmul', x, ('fabs', x))), 4.0)
|
|
|
|
return ('ffma', ('ffma', x, ('fabs', x), ('fneg', x)), 0.225, x)
|
|
|
|
|
2019-11-02 02:53:06 +00:00
|
|
|
def intBitsToFloat(i):
|
|
|
|
return struct.unpack('!f', struct.pack('!I', i))[0]
|
|
|
|
|
2014-12-12 19:13:10 +00:00
|
|
|
optimizations = [
|
2016-05-07 18:01:24 +01:00
|
|
|
|
2020-08-11 23:49:37 +01:00
|
|
|
(('imul', a, '#b(is_pos_power_of_two)'), ('ishl', a, ('find_lsb', b)), '!options->lower_bitops'),
|
2021-07-21 17:03:01 +01:00
|
|
|
(('imul', 'a@8', 0x80), ('ishl', a, 7), '!options->lower_bitops'),
|
|
|
|
(('imul', 'a@16', 0x8000), ('ishl', a, 15), '!options->lower_bitops'),
|
|
|
|
(('imul', 'a@32', 0x80000000), ('ishl', a, 31), '!options->lower_bitops'),
|
|
|
|
(('imul', 'a@64', 0x8000000000000000), ('ishl', a, 63), '!options->lower_bitops'),
|
2020-08-11 23:49:37 +01:00
|
|
|
(('imul', a, '#b(is_neg_power_of_two)'), ('ineg', ('ishl', a, ('find_lsb', ('iabs', b)))), '!options->lower_bitops'),
|
|
|
|
(('ishl', a, '#b'), ('imul', a, ('ishl', 1, b)), 'options->lower_bitops'),
|
2019-05-31 18:54:12 +01:00
|
|
|
|
2019-02-25 19:43:53 +00:00
|
|
|
(('unpack_64_2x32_split_x', ('imul_2x32_64(is_used_once)', a, b)), ('imul', a, b)),
|
|
|
|
(('unpack_64_2x32_split_x', ('umul_2x32_64(is_used_once)', a, b)), ('imul', a, b)),
|
2019-02-15 07:08:39 +00:00
|
|
|
(('imul_2x32_64', a, b), ('pack_64_2x32_split', ('imul', a, b), ('imul_high', a, b)), 'options->lower_mul_2x32_64'),
|
|
|
|
(('umul_2x32_64', a, b), ('pack_64_2x32_split', ('imul', a, b), ('umul_high', a, b)), 'options->lower_mul_2x32_64'),
|
2016-10-19 16:53:10 +01:00
|
|
|
(('udiv', a, 1), a),
|
|
|
|
(('idiv', a, 1), a),
|
|
|
|
(('umod', a, 1), 0),
|
|
|
|
(('imod', a, 1), 0),
|
2019-01-30 10:04:55 +00:00
|
|
|
(('imod', a, -1), 0),
|
|
|
|
(('irem', a, 1), 0),
|
|
|
|
(('irem', a, -1), 0),
|
2020-08-11 23:49:37 +01:00
|
|
|
(('udiv', a, '#b(is_pos_power_of_two)'), ('ushr', a, ('find_lsb', b)), '!options->lower_bitops'),
|
2020-10-01 16:32:45 +01:00
|
|
|
(('idiv', a, '#b(is_pos_power_of_two)'), ('imul', ('isign', a), ('ushr', ('iabs', a), ('find_lsb', b))), '!options->lower_bitops'),
|
|
|
|
(('idiv', a, '#b(is_neg_power_of_two)'), ('ineg', ('imul', ('isign', a), ('ushr', ('iabs', a), ('find_lsb', ('iabs', b))))), '!options->lower_bitops'),
|
2021-07-21 17:10:39 +01:00
|
|
|
(('umod', a, '#b(is_pos_power_of_two)'), ('iand', a, ('isub', b, 1)), '!options->lower_bitops'),
|
|
|
|
(('imod', a, '#b(is_pos_power_of_two)'), ('iand', a, ('isub', b, 1)), '!options->lower_bitops'),
|
|
|
|
(('imod', a, '#b(is_neg_power_of_two)'), ('bcsel', ('ieq', ('ior', a, b), b), 0, ('ior', a, b)), '!options->lower_bitops'),
|
|
|
|
# 'irem(a, b)' -> 'a - ((a < 0 ? (a + b - 1) : a) & -b)'
|
|
|
|
(('irem', a, '#b(is_pos_power_of_two)'),
|
|
|
|
('isub', a, ('iand', ('bcsel', ('ilt', a, 0), ('iadd', a, ('isub', b, 1)), a), ('ineg', b))),
|
|
|
|
'!options->lower_bitops'),
|
|
|
|
(('irem', a, '#b(is_neg_power_of_two)'), ('irem', a, ('iabs', b)), '!options->lower_bitops'),
|
2016-05-07 18:01:24 +01:00
|
|
|
|
2019-04-23 14:54:24 +01:00
|
|
|
(('~fneg', ('fneg', a)), a),
|
2014-12-12 19:13:10 +00:00
|
|
|
(('ineg', ('ineg', a)), a),
|
|
|
|
(('fabs', ('fneg', a)), ('fabs', a)),
|
2018-11-07 23:32:32 +00:00
|
|
|
(('fabs', ('u2f', a)), ('u2f', a)),
|
2014-12-12 19:13:10 +00:00
|
|
|
(('iabs', ('iabs', a)), ('iabs', a)),
|
|
|
|
(('iabs', ('ineg', a)), ('iabs', a)),
|
2018-12-06 19:02:01 +00:00
|
|
|
(('f2b', ('fneg', a)), ('f2b', a)),
|
|
|
|
(('i2b', ('ineg', a)), ('i2b', a)),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fadd', a, 0.0), a),
|
2020-07-15 11:16:33 +01:00
|
|
|
# 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_inf_nan_preserve_16),
|
|
|
|
(('fadd(is_only_used_as_float)', 'a@32', 0.0), a, '!'+signed_zero_inf_nan_preserve_32),
|
2014-12-12 19:13:10 +00:00
|
|
|
(('iadd', a, 0), a),
|
2021-06-18 15:28:59 +01:00
|
|
|
(('usadd_4x8_vc4', a, 0), a),
|
|
|
|
(('usadd_4x8_vc4', a, ~0), ~0),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fadd', ('fmul', a, b), ('fmul', a, c)), ('fmul', a, ('fadd', b, c))),
|
2015-02-28 19:32:31 +00:00
|
|
|
(('iadd', ('imul', a, b), ('imul', a, c)), ('imul', a, ('iadd', b, c))),
|
2020-07-15 18:23:54 +01:00
|
|
|
(('iand', ('ior', a, b), ('ior', a, c)), ('ior', a, ('iand', b, c))),
|
|
|
|
(('ior', ('iand', a, b), ('iand', a, c)), ('iand', a, ('ior', b, c))),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fadd', ('fneg', a), a), 0.0),
|
2015-02-28 19:32:32 +00:00
|
|
|
(('iadd', ('ineg', a), a), 0),
|
2015-12-15 01:44:23 +00:00
|
|
|
(('iadd', ('ineg', a), ('iadd', a, b)), b),
|
|
|
|
(('iadd', a, ('iadd', ('ineg', a), b)), b),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fadd', ('fneg', a), ('fadd', a, b)), b),
|
|
|
|
(('~fadd', a, ('fadd', ('fneg', a), b)), b),
|
2019-03-05 20:46:11 +00:00
|
|
|
(('fadd', ('fsat', a), ('fsat', ('fneg', a))), ('fsat', ('fabs', a))),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fmul', a, 0.0), 0.0),
|
2020-07-15 11:19:56 +01:00
|
|
|
# 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_inf_nan_preserve_16),
|
|
|
|
(('fmul', 'a@32', 0.0), 0.0, '!'+signed_zero_inf_nan_preserve_32),
|
2014-12-12 19:13:10 +00:00
|
|
|
(('imul', a, 0), 0),
|
2021-06-18 15:28:59 +01:00
|
|
|
(('umul_unorm_4x8_vc4', a, 0), 0),
|
|
|
|
(('umul_unorm_4x8_vc4', a, ~0), a),
|
2019-04-23 14:54:24 +01:00
|
|
|
(('~fmul', a, 1.0), a),
|
2020-06-17 14:46:55 +01:00
|
|
|
# The only effect a*1.0 can have is flushing denormals. If it's only used by
|
|
|
|
# a floating point instruction, they should flush any input denormals and
|
|
|
|
# this multiplication isn't needed.
|
|
|
|
(('fmul(is_only_used_as_float)', a, 1.0), a),
|
2014-12-12 19:13:10 +00:00
|
|
|
(('imul', a, 1), a),
|
|
|
|
(('fmul', a, -1.0), ('fneg', a)),
|
|
|
|
(('imul', a, -1), ('ineg', a)),
|
2018-09-10 18:39:42 +01:00
|
|
|
# If a < 0: fsign(a)*a*a => -1*a*a => -a*a => abs(a)*a
|
|
|
|
# If a > 0: fsign(a)*a*a => 1*a*a => a*a => abs(a)*a
|
|
|
|
# If a == 0: fsign(a)*a*a => 0*0*0 => abs(0)*0
|
nir: Make some notes about fsign versus NaN
This commit only documents the current behavior, even if that behavior
is not the behavior preferred by the relevant specs.
In SPIR-V, there are two flavors of the sign instruction, and each lives
in an extended instruction set. The GLSL.std.450 FSign instruction is
defined as:
Result is 1.0 if x > 0, 0.0 if x = 0, or -1.0 if x < 0.
This also matches the GLSL 4.60 definition.
However, the OpenCL.ExtendedInstructionSet.100 sign instruction is
defined as:
Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if
x < 0. Returns 0.0 if x is a NaN.
There are two differences. Each treats -0.0 differently, and each also
treats NaN differently. Specifically, GLSL.std.450 FSign does not
define any specific behavior for NaN.
There has been some discussion in Khronos about the NaN behavior of
GLSL.std.450 FSign. As part of that discussion, I did some research
into how we treat NaN for nir_op_fsign, and this commit just captures
some of those notes.
v2: Document the expected behavior of nir_op_fsign more thoroughly.
Suggested by Rhys. Note that the current implementation of constant
folding does not produce the expected result for NaN. Suggested by
Caio.
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> [v1]
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6358>
2020-02-18 18:18:57 +00:00
|
|
|
# If a != a: fsign(a)*a*a => 0*NaN*NaN => abs(NaN)*NaN
|
2018-09-10 18:39:42 +01:00
|
|
|
(('fmul', ('fsign', a), ('fmul', a, a)), ('fmul', ('fabs', a), a)),
|
|
|
|
(('fmul', ('fmul', ('fsign', a), a), a), ('fmul', ('fabs', a), a)),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~ffma', 0.0, a, b), b),
|
2020-07-15 11:19:56 +01:00
|
|
|
(('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),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~ffma', a, b, 0.0), ('fmul', a, b)),
|
2020-07-15 11:16:33 +01:00
|
|
|
(('ffma@16', a, b, 0.0), ('fmul', a, b), '!'+signed_zero_inf_nan_preserve_16),
|
|
|
|
(('ffma@32', a, b, 0.0), ('fmul', a, b), '!'+signed_zero_inf_nan_preserve_32),
|
2014-12-12 19:13:10 +00:00
|
|
|
(('ffma', 1.0, a, b), ('fadd', a, b)),
|
2019-05-10 18:20:02 +01:00
|
|
|
(('ffma', -1.0, a, b), ('fadd', ('fneg', a), b)),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~flrp', a, b, 0.0), a),
|
|
|
|
(('~flrp', a, b, 1.0), b),
|
|
|
|
(('~flrp', a, a, b), a),
|
|
|
|
(('~flrp', 0.0, a, b), ('fmul', a, b)),
|
2018-08-23 03:15:15 +01:00
|
|
|
|
|
|
|
# flrp(a, a + b, c) => a + flrp(0, b, c) => a + (b * c)
|
|
|
|
(('~flrp', a, ('fadd(is_used_once)', a, b), c), ('fadd', ('fmul', b, c), a)),
|
2020-09-01 05:12:08 +01:00
|
|
|
]
|
2018-08-23 03:15:15 +01:00
|
|
|
|
2020-09-01 05:12:08 +01:00
|
|
|
# Float sizes
|
|
|
|
for s in [16, 32, 64]:
|
|
|
|
optimizations.extend([
|
2020-06-16 22:29:58 +01:00
|
|
|
(('~flrp@{}'.format(s), a, b, ('b2f', 'c@1')), ('bcsel', c, b, a), 'options->lower_flrp{}'.format(s)),
|
|
|
|
|
2020-09-01 05:12:08 +01:00
|
|
|
(('~flrp@{}'.format(s), a, ('fadd', a, b), c), ('fadd', ('fmul', b, c), a), 'options->lower_flrp{}'.format(s)),
|
|
|
|
(('~flrp@{}'.format(s), ('fadd', a, b), ('fadd', a, c), d), ('fadd', ('flrp', b, c, d), a), 'options->lower_flrp{}'.format(s)),
|
|
|
|
(('~flrp@{}'.format(s), a, ('fmul(is_used_once)', a, b), c), ('fmul', ('flrp', 1.0, b, c), a), 'options->lower_flrp{}'.format(s)),
|
|
|
|
|
|
|
|
(('~fadd@{}'.format(s), ('fmul', a, ('fadd', 1.0, ('fneg', c))), ('fmul', b, c)), ('flrp', a, b, c), '!options->lower_flrp{}'.format(s)),
|
|
|
|
# These are the same as the previous three rules, but it depends on
|
|
|
|
# 1-fsat(x) <=> fsat(1-x). See below.
|
|
|
|
(('~fadd@{}'.format(s), ('fmul', a, ('fsat', ('fadd', 1.0, ('fneg', c)))), ('fmul', b, ('fsat', c))), ('flrp', a, b, ('fsat', c)), '!options->lower_flrp{}'.format(s)),
|
|
|
|
(('~fadd@{}'.format(s), a, ('fmul', c, ('fadd', b, ('fneg', a)))), ('flrp', a, b, c), '!options->lower_flrp{}'.format(s)),
|
|
|
|
|
|
|
|
(('~fadd@{}'.format(s), ('fmul', a, ('fadd', 1.0, ('fneg', ('b2f', 'c@1')))), ('fmul', b, ('b2f', c))), ('bcsel', c, b, a), 'options->lower_flrp{}'.format(s)),
|
|
|
|
(('~fadd@{}'.format(s), a, ('fmul', ('b2f', 'c@1'), ('fadd', b, ('fneg', a)))), ('bcsel', c, b, a), 'options->lower_flrp{}'.format(s)),
|
|
|
|
|
|
|
|
# 1 - ((1 - a) * (1 - b))
|
|
|
|
# 1 - (1 - a - b + a*b)
|
|
|
|
# 1 - 1 + a + b - a*b
|
|
|
|
# a + b - a*b
|
|
|
|
# a + b*(1 - a)
|
|
|
|
# b*(1 - a) + 1*a
|
|
|
|
# flrp(b, 1, a)
|
|
|
|
(('~fadd@{}'.format(s), 1.0, ('fneg', ('fmul', ('fadd', 1.0, ('fneg', a)), ('fadd', 1.0, ('fneg', b))))), ('flrp', b, 1.0, a), '!options->lower_flrp{}'.format(s)),
|
|
|
|
])
|
2018-08-23 05:55:55 +01:00
|
|
|
|
2020-09-01 05:12:08 +01:00
|
|
|
optimizations.extend([
|
2018-08-23 05:55:55 +01:00
|
|
|
(('~flrp', ('fmul(is_used_once)', a, b), ('fmul(is_used_once)', a, c), d), ('fmul', ('flrp', b, c, d), a)),
|
|
|
|
|
2017-01-03 10:10:33 +00:00
|
|
|
(('~flrp', a, 0.0, c), ('fadd', ('fmul', ('fneg', a), c), a)),
|
2019-04-12 09:12:27 +01:00
|
|
|
(('ftrunc', a), ('bcsel', ('flt', a, 0.0), ('fneg', ('ffloor', ('fabs', a))), ('ffloor', ('fabs', a))), 'options->lower_ftrunc'),
|
2018-09-01 20:15:27 +01:00
|
|
|
(('ffloor', a), ('fsub', a, ('ffract', a)), 'options->lower_ffloor'),
|
nir/algebraic: Replace a-fract(a) with floor(a)
I noticed this while looking at a shader that was affected by Tim's
"more loop unrolling" series.
In review, Tim Arceri asked:
> Why the hurt on Gen6+ is this something that should be in the late
> optimisations pass?
As far as I can tell, it's just because our scheduler is terrible. In
all the fragment shaders that I looked at (some hurt shaders were from
other stages), only one of the SIMD8 or SIMD16 version would be hurt.
In many of those case, the other SIMD width is improved (e.g.,
shaders/closed/steam/brutal-legend/3990.shader_test).
Often it looks like the scheduler decides to differently schedule a SEND
the occurs somewhere early in the shader. Once that happens, everything
is different.
I looked at one vertex shader that was hurt (from Goat Simulator). In
that case, both the floor and fract are used. The optimization
eliminates the add, and it should allow better scheduling. In the area
of the FRC and RNDD instructions, the scheduler does the right thing.
However, later in the shader a MAD and and ADD get scheduled
differently, and that makes it slightly worse.
In light of this, I tried adding some "is_used_once" mark-up, and that
did not fix all the cycles regressions. It also did a lot more harm
than good on SKL (helped 82 vs. hurt 241).
All Gen6+ platforms had similar results. (Skylake shown)
total instructions in shared programs: 15437001 -> 15435259 (-0.01%)
instructions in affected programs: 213651 -> 211909 (-0.82%)
helped: 988
HURT: 0
helped stats (abs) min: 1 max: 27 x̄: 1.76 x̃: 1
helped stats (rel) min: 0.15% max: 11.54% x̄: 1.14% x̃: 0.59%
95% mean confidence interval for instructions value: -1.89 -1.63
95% mean confidence interval for instructions %-change: -1.23% -1.05%
Instructions are helped.
total cycles in shared programs: 383007378 -> 382997063 (<.01%)
cycles in affected programs: 1650825 -> 1640510 (-0.62%)
helped: 679
HURT: 302
helped stats (abs) min: 1 max: 348 x̄: 23.39 x̃: 14
helped stats (rel) min: 0.04% max: 28.77% x̄: 1.61% x̃: 0.98%
HURT stats (abs) min: 1 max: 250 x̄: 18.43 x̃: 7
HURT stats (rel) min: 0.04% max: 25.86% x̄: 1.41% x̃: 0.53%
95% mean confidence interval for cycles value: -13.05 -7.98
95% mean confidence interval for cycles %-change: -0.86% -0.50%
Cycles are helped.
Iron Lake and GM45 had similar results. (GM45 shown)
total instructions in shared programs: 5043616 -> 5043010 (-0.01%)
instructions in affected programs: 119691 -> 119085 (-0.51%)
helped: 432
HURT: 0
helped stats (abs) min: 1 max: 27 x̄: 1.40 x̃: 1
helped stats (rel) min: 0.10% max: 8.11% x̄: 0.66% x̃: 0.39%
95% mean confidence interval for instructions value: -1.58 -1.23
95% mean confidence interval for instructions %-change: -0.72% -0.59%
Instructions are helped.
total cycles in shared programs: 128139812 -> 128135762 (<.01%)
cycles in affected programs: 3829724 -> 3825674 (-0.11%)
helped: 602
HURT: 0
helped stats (abs) min: 2 max: 486 x̄: 6.73 x̃: 6
helped stats (rel) min: 0.02% max: 4.85% x̄: 0.19% x̃: 0.10%
95% mean confidence interval for cycles value: -8.40 -5.05
95% mean confidence interval for cycles %-change: -0.22% -0.16%
Cycles are helped.
Reviewed-by: Elie Tournier <tournier.elie@gmail.com>
2019-02-23 00:47:06 +00:00
|
|
|
(('fadd', a, ('fneg', ('ffract', a))), ('ffloor', a), '!options->lower_ffloor'),
|
2015-09-14 16:13:19 +01:00
|
|
|
(('ffract', a), ('fsub', a, ('ffloor', a)), 'options->lower_ffract'),
|
2018-11-12 17:49:32 +00:00
|
|
|
(('fceil', a), ('fneg', ('ffloor', ('fneg', a))), 'options->lower_fceil'),
|
2020-09-24 16:46:31 +01:00
|
|
|
(('ffma@16', a, b, c), ('fadd', ('fmul', a, b), c), 'options->lower_ffma16'),
|
|
|
|
(('ffma@32', a, b, c), ('fadd', ('fmul', a, b), c), 'options->lower_ffma32'),
|
|
|
|
(('ffma@64', a, b, c), ('fadd', ('fmul', a, b), c), 'options->lower_ffma64'),
|
2020-09-04 10:55:25 +01:00
|
|
|
# Always lower inexact ffma, because it will be fused back by late optimizations (nir_opt_algebraic_late).
|
2020-09-24 16:46:31 +01:00
|
|
|
(('~ffma@16', a, b, c), ('fadd', ('fmul', a, b), c), 'options->fuse_ffma16'),
|
|
|
|
(('~ffma@32', a, b, c), ('fadd', ('fmul', a, b), c), 'options->fuse_ffma32'),
|
|
|
|
(('~ffma@64', a, b, c), ('fadd', ('fmul', a, b), c), 'options->fuse_ffma64'),
|
nir/algebraic: Optimize common array indexing sequence
Some shaders include code that looks like:
uniform int i;
uniform vec4 bones[...];
foo(bones[i * 3], bones[i * 3 + 1], bones[i * 3 + 2]);
CSE would do some work on this:
x = i * 3
foo(bones[x], bones[x + 1], bones[x + 2]);
The compiler may then add '<< 4 + base' to the index calculations.
This results in expressions like
x = i * 3
foo(bones[x << 4], bones[(x + 1) << 4], bones[(x + 2) << 4]);
Just rearranging the math to produce (i * 48) + 16 saves an
instruction, and it allows CSE to do more work.
x = i * 48;
foo(bones[x], bones[x + 16], bones[x + 32]);
So, ~6 instructions becomes ~3.
Some individual shader-db results look pretty bad. However, I have a
really, really hard time believing the change in estimated cycles in,
for example, 3dmmes-taiji/51.shader_test after looking that change in
the generated code.
G45
total instructions in shared programs: 4020840 -> 4010070 (-0.27%)
instructions in affected programs: 177460 -> 166690 (-6.07%)
helped: 894
HURT: 0
total cycles in shared programs: 98829000 -> 98784990 (-0.04%)
cycles in affected programs: 3936648 -> 3892638 (-1.12%)
helped: 894
HURT: 0
Ironlake
total instructions in shared programs: 6418887 -> 6408117 (-0.17%)
instructions in affected programs: 177460 -> 166690 (-6.07%)
helped: 894
HURT: 0
total cycles in shared programs: 143504542 -> 143460532 (-0.03%)
cycles in affected programs: 3936648 -> 3892638 (-1.12%)
helped: 894
HURT: 0
Sandy Bridge
total instructions in shared programs: 8357887 -> 8339251 (-0.22%)
instructions in affected programs: 432715 -> 414079 (-4.31%)
helped: 2795
HURT: 0
total cycles in shared programs: 118284184 -> 118207412 (-0.06%)
cycles in affected programs: 6114626 -> 6037854 (-1.26%)
helped: 2478
HURT: 317
Ivy Bridge
total instructions in shared programs: 7669390 -> 7653822 (-0.20%)
instructions in affected programs: 388234 -> 372666 (-4.01%)
helped: 2795
HURT: 0
total cycles in shared programs: 68381982 -> 68263684 (-0.17%)
cycles in affected programs: 1972658 -> 1854360 (-6.00%)
helped: 2458
HURT: 307
Haswell
total instructions in shared programs: 7082636 -> 7067068 (-0.22%)
instructions in affected programs: 388234 -> 372666 (-4.01%)
helped: 2795
HURT: 0
total cycles in shared programs: 68282020 -> 68164158 (-0.17%)
cycles in affected programs: 1891820 -> 1773958 (-6.23%)
helped: 2459
HURT: 261
Broadwell
total instructions in shared programs: 9002466 -> 8985875 (-0.18%)
instructions in affected programs: 658784 -> 642193 (-2.52%)
helped: 2795
HURT: 5
total cycles in shared programs: 78503092 -> 78450404 (-0.07%)
cycles in affected programs: 2873304 -> 2820616 (-1.83%)
helped: 2275
HURT: 415
Skylake
total instructions in shared programs: 9156978 -> 9140387 (-0.18%)
instructions in affected programs: 682625 -> 666034 (-2.43%)
helped: 2795
HURT: 5
total cycles in shared programs: 75591392 -> 75550574 (-0.05%)
cycles in affected programs: 3192120 -> 3151302 (-1.28%)
helped: 2271
HURT: 425
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-07-20 01:47:38 +01:00
|
|
|
|
2020-08-11 23:49:37 +01:00
|
|
|
(('~fmul', ('fadd', ('iand', ('ineg', ('b2i', 'a@bool')), ('fmul', b, c)), '#d'), '#e'),
|
2018-09-06 04:45:19 +01:00
|
|
|
('bcsel', a, ('fmul', ('fadd', ('fmul', b, c), d), e), ('fmul', d, e))),
|
|
|
|
|
2019-06-21 02:47:16 +01:00
|
|
|
(('fdph', a, b), ('fdot4', ('vec4', 'a.x', 'a.y', 'a.z', 1.0), b), 'options->lower_fdph'),
|
|
|
|
|
|
|
|
(('fdot4', ('vec4', a, b, c, 1.0), d), ('fdph', ('vec3', a, b, c), d), '!options->lower_fdph'),
|
2018-02-15 22:49:55 +00:00
|
|
|
(('fdot4', ('vec4', a, 0.0, 0.0, 0.0), b), ('fmul', a, b)),
|
|
|
|
(('fdot4', ('vec4', a, b, 0.0, 0.0), c), ('fdot2', ('vec2', a, b), c)),
|
|
|
|
(('fdot4', ('vec4', a, b, c, 0.0), d), ('fdot3', ('vec3', a, b, c), d)),
|
|
|
|
|
|
|
|
(('fdot3', ('vec3', a, 0.0, 0.0), b), ('fmul', a, b)),
|
|
|
|
(('fdot3', ('vec3', a, b, 0.0), c), ('fdot2', ('vec2', a, b), c)),
|
|
|
|
|
2019-06-21 02:56:29 +01:00
|
|
|
(('fdot2', ('vec2', a, 0.0), b), ('fmul', a, b)),
|
|
|
|
(('fdot2', a, 1.0), ('fadd', 'a.x', 'a.y')),
|
|
|
|
|
2019-07-27 16:58:53 +01:00
|
|
|
# Lower fdot to fsum when it is available
|
|
|
|
(('fdot2', a, b), ('fsum2', ('fmul', a, b)), 'options->lower_fdot'),
|
|
|
|
(('fdot3', a, b), ('fsum3', ('fmul', a, b)), 'options->lower_fdot'),
|
|
|
|
(('fdot4', a, b), ('fsum4', ('fmul', a, b)), 'options->lower_fdot'),
|
|
|
|
(('fsum2', a), ('fadd', 'a.x', 'a.y'), 'options->lower_fdot'),
|
|
|
|
|
2018-03-28 06:57:07 +01:00
|
|
|
# If x >= 0 and x <= 1: fsat(1 - x) == 1 - fsat(x) trivially
|
|
|
|
# If x < 0: 1 - fsat(x) => 1 - 0 => 1 and fsat(1 - x) => fsat(> 1) => 1
|
|
|
|
# If x > 1: 1 - fsat(x) => 1 - 1 => 0 and fsat(1 - x) => fsat(< 0) => 0
|
|
|
|
(('~fadd', ('fneg(is_used_once)', ('fsat(is_used_once)', 'a(is_not_fmul)')), 1.0), ('fsat', ('fadd', 1.0, ('fneg', a)))),
|
|
|
|
|
nir/algebraic: Optimize common array indexing sequence
Some shaders include code that looks like:
uniform int i;
uniform vec4 bones[...];
foo(bones[i * 3], bones[i * 3 + 1], bones[i * 3 + 2]);
CSE would do some work on this:
x = i * 3
foo(bones[x], bones[x + 1], bones[x + 2]);
The compiler may then add '<< 4 + base' to the index calculations.
This results in expressions like
x = i * 3
foo(bones[x << 4], bones[(x + 1) << 4], bones[(x + 2) << 4]);
Just rearranging the math to produce (i * 48) + 16 saves an
instruction, and it allows CSE to do more work.
x = i * 48;
foo(bones[x], bones[x + 16], bones[x + 32]);
So, ~6 instructions becomes ~3.
Some individual shader-db results look pretty bad. However, I have a
really, really hard time believing the change in estimated cycles in,
for example, 3dmmes-taiji/51.shader_test after looking that change in
the generated code.
G45
total instructions in shared programs: 4020840 -> 4010070 (-0.27%)
instructions in affected programs: 177460 -> 166690 (-6.07%)
helped: 894
HURT: 0
total cycles in shared programs: 98829000 -> 98784990 (-0.04%)
cycles in affected programs: 3936648 -> 3892638 (-1.12%)
helped: 894
HURT: 0
Ironlake
total instructions in shared programs: 6418887 -> 6408117 (-0.17%)
instructions in affected programs: 177460 -> 166690 (-6.07%)
helped: 894
HURT: 0
total cycles in shared programs: 143504542 -> 143460532 (-0.03%)
cycles in affected programs: 3936648 -> 3892638 (-1.12%)
helped: 894
HURT: 0
Sandy Bridge
total instructions in shared programs: 8357887 -> 8339251 (-0.22%)
instructions in affected programs: 432715 -> 414079 (-4.31%)
helped: 2795
HURT: 0
total cycles in shared programs: 118284184 -> 118207412 (-0.06%)
cycles in affected programs: 6114626 -> 6037854 (-1.26%)
helped: 2478
HURT: 317
Ivy Bridge
total instructions in shared programs: 7669390 -> 7653822 (-0.20%)
instructions in affected programs: 388234 -> 372666 (-4.01%)
helped: 2795
HURT: 0
total cycles in shared programs: 68381982 -> 68263684 (-0.17%)
cycles in affected programs: 1972658 -> 1854360 (-6.00%)
helped: 2458
HURT: 307
Haswell
total instructions in shared programs: 7082636 -> 7067068 (-0.22%)
instructions in affected programs: 388234 -> 372666 (-4.01%)
helped: 2795
HURT: 0
total cycles in shared programs: 68282020 -> 68164158 (-0.17%)
cycles in affected programs: 1891820 -> 1773958 (-6.23%)
helped: 2459
HURT: 261
Broadwell
total instructions in shared programs: 9002466 -> 8985875 (-0.18%)
instructions in affected programs: 658784 -> 642193 (-2.52%)
helped: 2795
HURT: 5
total cycles in shared programs: 78503092 -> 78450404 (-0.07%)
cycles in affected programs: 2873304 -> 2820616 (-1.83%)
helped: 2275
HURT: 415
Skylake
total instructions in shared programs: 9156978 -> 9140387 (-0.18%)
instructions in affected programs: 682625 -> 666034 (-2.43%)
helped: 2795
HURT: 5
total cycles in shared programs: 75591392 -> 75550574 (-0.05%)
cycles in affected programs: 3192120 -> 3151302 (-1.28%)
helped: 2271
HURT: 425
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-07-20 01:47:38 +01:00
|
|
|
# (a * #b + #c) << #d
|
|
|
|
# ((a * #b) << #d) + (#c << #d)
|
|
|
|
# (a * (#b << #d)) + (#c << #d)
|
|
|
|
(('ishl', ('iadd', ('imul', a, '#b'), '#c'), '#d'),
|
|
|
|
('iadd', ('imul', a, ('ishl', b, d)), ('ishl', c, d))),
|
|
|
|
|
|
|
|
# (a * #b) << #c
|
|
|
|
# a * (#b << #c)
|
|
|
|
(('ishl', ('imul', a, '#b'), '#c'), ('imul', a, ('ishl', b, c))),
|
2020-09-01 05:12:08 +01:00
|
|
|
])
|
2019-08-06 21:11:56 +01:00
|
|
|
|
|
|
|
# Care must be taken here. Shifts in NIR uses only the lower log2(bitsize)
|
|
|
|
# bits of the second source. These replacements must correctly handle the
|
|
|
|
# case where (b % bitsize) + (c % bitsize) >= bitsize.
|
|
|
|
for s in [8, 16, 32, 64]:
|
|
|
|
mask = (1 << s) - 1
|
|
|
|
|
|
|
|
ishl = "ishl@{}".format(s)
|
|
|
|
ishr = "ishr@{}".format(s)
|
|
|
|
ushr = "ushr@{}".format(s)
|
|
|
|
|
|
|
|
in_bounds = ('ult', ('iadd', ('iand', b, mask), ('iand', c, mask)), s)
|
nir/algebraic: Optimize common array indexing sequence
Some shaders include code that looks like:
uniform int i;
uniform vec4 bones[...];
foo(bones[i * 3], bones[i * 3 + 1], bones[i * 3 + 2]);
CSE would do some work on this:
x = i * 3
foo(bones[x], bones[x + 1], bones[x + 2]);
The compiler may then add '<< 4 + base' to the index calculations.
This results in expressions like
x = i * 3
foo(bones[x << 4], bones[(x + 1) << 4], bones[(x + 2) << 4]);
Just rearranging the math to produce (i * 48) + 16 saves an
instruction, and it allows CSE to do more work.
x = i * 48;
foo(bones[x], bones[x + 16], bones[x + 32]);
So, ~6 instructions becomes ~3.
Some individual shader-db results look pretty bad. However, I have a
really, really hard time believing the change in estimated cycles in,
for example, 3dmmes-taiji/51.shader_test after looking that change in
the generated code.
G45
total instructions in shared programs: 4020840 -> 4010070 (-0.27%)
instructions in affected programs: 177460 -> 166690 (-6.07%)
helped: 894
HURT: 0
total cycles in shared programs: 98829000 -> 98784990 (-0.04%)
cycles in affected programs: 3936648 -> 3892638 (-1.12%)
helped: 894
HURT: 0
Ironlake
total instructions in shared programs: 6418887 -> 6408117 (-0.17%)
instructions in affected programs: 177460 -> 166690 (-6.07%)
helped: 894
HURT: 0
total cycles in shared programs: 143504542 -> 143460532 (-0.03%)
cycles in affected programs: 3936648 -> 3892638 (-1.12%)
helped: 894
HURT: 0
Sandy Bridge
total instructions in shared programs: 8357887 -> 8339251 (-0.22%)
instructions in affected programs: 432715 -> 414079 (-4.31%)
helped: 2795
HURT: 0
total cycles in shared programs: 118284184 -> 118207412 (-0.06%)
cycles in affected programs: 6114626 -> 6037854 (-1.26%)
helped: 2478
HURT: 317
Ivy Bridge
total instructions in shared programs: 7669390 -> 7653822 (-0.20%)
instructions in affected programs: 388234 -> 372666 (-4.01%)
helped: 2795
HURT: 0
total cycles in shared programs: 68381982 -> 68263684 (-0.17%)
cycles in affected programs: 1972658 -> 1854360 (-6.00%)
helped: 2458
HURT: 307
Haswell
total instructions in shared programs: 7082636 -> 7067068 (-0.22%)
instructions in affected programs: 388234 -> 372666 (-4.01%)
helped: 2795
HURT: 0
total cycles in shared programs: 68282020 -> 68164158 (-0.17%)
cycles in affected programs: 1891820 -> 1773958 (-6.23%)
helped: 2459
HURT: 261
Broadwell
total instructions in shared programs: 9002466 -> 8985875 (-0.18%)
instructions in affected programs: 658784 -> 642193 (-2.52%)
helped: 2795
HURT: 5
total cycles in shared programs: 78503092 -> 78450404 (-0.07%)
cycles in affected programs: 2873304 -> 2820616 (-1.83%)
helped: 2275
HURT: 415
Skylake
total instructions in shared programs: 9156978 -> 9140387 (-0.18%)
instructions in affected programs: 682625 -> 666034 (-2.43%)
helped: 2795
HURT: 5
total cycles in shared programs: 75591392 -> 75550574 (-0.05%)
cycles in affected programs: 3192120 -> 3151302 (-1.28%)
helped: 2271
HURT: 425
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-07-20 01:47:38 +01:00
|
|
|
|
2019-08-06 21:11:56 +01:00
|
|
|
optimizations.extend([
|
|
|
|
((ishl, (ishl, a, '#b'), '#c'), ('bcsel', in_bounds, (ishl, a, ('iadd', b, c)), 0)),
|
|
|
|
((ushr, (ushr, a, '#b'), '#c'), ('bcsel', in_bounds, (ushr, a, ('iadd', b, c)), 0)),
|
|
|
|
|
|
|
|
# To get get -1 for large shifts of negative values, ishr must instead
|
|
|
|
# clamp the shift count to the maximum value.
|
|
|
|
((ishr, (ishr, a, '#b'), '#c'),
|
|
|
|
(ishr, a, ('imin', ('iadd', ('iand', b, mask), ('iand', c, mask)), s - 1))),
|
|
|
|
])
|
|
|
|
|
2019-10-09 15:03:45 +01:00
|
|
|
# Optimize a pattern of address calculation created by DXVK where the offset is
|
|
|
|
# divided by 4 and then multipled by 4. This can be turned into an iand and the
|
|
|
|
# additions before can be reassociated to CSE the iand instruction.
|
2021-02-03 00:04:57 +00:00
|
|
|
|
|
|
|
for size, mask in ((8, 0xff), (16, 0xffff), (32, 0xffffffff), (64, 0xffffffffffffffff)):
|
|
|
|
a_sz = 'a@{}'.format(size)
|
|
|
|
|
|
|
|
optimizations.extend([
|
|
|
|
# 'a >> #b << #b' -> 'a & ~((1 << #b) - 1)'
|
|
|
|
(('ishl', ('ushr', a_sz, '#b'), b), ('iand', a, ('ishl', mask, b))),
|
nir/algebraic: add patterns for a >> #b << #b and a << #b >> #b
Commit 5476d181830 ("nir/algebraic: add patterns for a >> #b << #b")
added the ushr version, but it missed the ishr. A bunch of compute
shaders with stores to shared storage generate the ishr pattern.
Enabling this optimization also enables the iadd/iand reassociation
(right after this hunk), and that enables merging of stores to shared
storage. A couple shaders have spills and fills hurt on some
platforms. These all occur in shaders that also have SENDs helped.
On Gen9 and Gen11, the helped SENDs more than makes up for the extra
spills and fills.
On Gen7 and Gen8, it's not as clear. All of the shaders affected are
compute shaders in DiRT Rally 2 or Bioshock Inifinite. The most
affected Bioshock shader on Broadwell looks like:
Before: CS SIMD8 shader: 1335 inst, 0 loops, 22411 cycles, 42:36 spills:fills, 159 sends, scheduled with mode lifo, Promoted 2 constants, compacted 21360 to 16528 bytes.
After: CS SIMD8 shader: 1175 inst, 0 loops, 25916 cycles, 96:135 spills:fills, 72 sends, scheduled with mode lifo, Promoted 2 constants, compacted 18800 to 13648 bytes.
The results on Haswell and Ivy Bridge are similar. Given that there
are only 2 promoted constants, MR !7698 won't have any effect.
There were no statistically significant changes on Gen9+ in Bioshock in
our performance CI. Gen8 isn't in that CI, and DiRT Showdown 2 is also
not included in that CI. It is possible that these shaders aren't used
in the settings or demos used in the CI.
The other pattern, which switches the order of the shifts, only helps a
couple shaders. If I wasn't already adding another pattern, I
definitely wouldn't bother with that one.
v2: s/ishr/ushr/ in the replacement for the ushr pattern. Noticed by
Rhys.
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Tiger Lake
total instructions in shared programs: 21052760 -> 21049269 (-0.02%)
instructions in affected programs: 59497 -> 56006 (-5.87%)
helped: 46
HURT: 0
helped stats (abs) min: 2 max: 552 x̄: 75.89 x̃: 53
helped stats (rel) min: 0.28% max: 43.43% x̄: 5.87% x̃: 4.10%
95% mean confidence interval for instructions value: -108.96 -42.82
95% mean confidence interval for instructions %-change: -8.38% -3.35%
Instructions are helped.
total cycles in shared programs: 855229761 -> 855148518 (<.01%)
cycles in affected programs: 8491373 -> 8410130 (-0.96%)
helped: 33
HURT: 15
helped stats (abs) min: 42 max: 26940 x̄: 6200.70 x̃: 4329
helped stats (rel) min: 0.09% max: 38.78% x̄: 7.97% x̃: 4.29%
HURT stats (abs) min: 2 max: 18132 x̄: 8225.33 x̃: 7288
HURT stats (rel) min: <.01% max: 13.37% x̄: 5.72% x̃: 4.53%
95% mean confidence interval for cycles value: -4331.52 946.40
95% mean confidence interval for cycles %-change: -6.78% -0.61%
Inconclusive result (value mean confidence interval includes 0).
total sends in shared programs: 989947 -> 989694 (-0.03%)
sends in affected programs: 523 -> 270 (-48.37%)
helped: 5
HURT: 0
helped stats (abs) min: 9 max: 87 x̄: 50.60 x̃: 37
helped stats (rel) min: 25.71% max: 54.72% x̄: 43.49% x̃: 42.53%
95% mean confidence interval for sends value: -93.95 -7.25
95% mean confidence interval for sends %-change: -58.48% -28.50%
Sends are helped.
Ice Lake and Skylake had similar results. (Ice Lake shown)
total instructions in shared programs: 20033498 -> 20030552 (-0.01%)
instructions in affected programs: 59220 -> 56274 (-4.97%)
helped: 48
HURT: 0
helped stats (abs) min: 1 max: 465 x̄: 61.38 x̃: 39
helped stats (rel) min: 0.03% max: 42.27% x̄: 5.19% x̃: 3.90%
95% mean confidence interval for instructions value: -89.57 -33.18
95% mean confidence interval for instructions %-change: -7.49% -2.89%
Instructions are helped.
total cycles in shared programs: 979993675 -> 979840773 (-0.02%)
cycles in affected programs: 6738454 -> 6585552 (-2.27%)
helped: 46
HURT: 0
helped stats (abs) min: 42 max: 6265 x̄: 3323.96 x̃: 3579
helped stats (rel) min: 0.09% max: 37.38% x̄: 4.34% x̃: 2.39%
95% mean confidence interval for cycles value: -3664.70 -2983.21
95% mean confidence interval for cycles %-change: -6.63% -2.06%
Cycles are helped.
total spills in shared programs: 10659 -> 10661 (0.02%)
spills in affected programs: 36 -> 38 (5.56%)
helped: 1
HURT: 1
total fills in shared programs: 11551 -> 11551 (0.00%)
fills in affected programs: 70 -> 70 (0.00%)
helped: 1
HURT: 1
total sends in shared programs: 1032117 -> 1031785 (-0.03%)
sends in affected programs: 711 -> 379 (-46.69%)
helped: 5
HURT: 0
helped stats (abs) min: 18 max: 87 x̄: 66.40 x̃: 74
helped stats (rel) min: 27.69% max: 54.72% x̄: 44.49% x̃: 44.31%
95% mean confidence interval for sends value: -101.79 -31.01
95% mean confidence interval for sends %-change: -58.42% -30.55%
Sends are helped.
Broadwell
total instructions in shared programs: 17865005 -> 17862757 (-0.01%)
instructions in affected programs: 66438 -> 64190 (-3.38%)
helped: 49
HURT: 0
helped stats (abs) min: 1 max: 266 x̄: 45.88 x̃: 39
helped stats (rel) min: 0.03% max: 11.99% x̄: 3.73% x̃: 3.92%
95% mean confidence interval for instructions value: -59.15 -32.61
95% mean confidence interval for instructions %-change: -4.35% -3.12%
Instructions are helped.
total cycles in shared programs: 1031298803 -> 1031219023 (<.01%)
cycles in affected programs: 7253602 -> 7173822 (-1.10%)
helped: 45
HURT: 2
helped stats (abs) min: 18 max: 7828 x̄: 1928.33 x̃: 1918
helped stats (rel) min: <.01% max: 10.51% x̄: 1.58% x̃: 1.31%
HURT stats (abs) min: 3490 max: 3505 x̄: 3497.50 x̃: 3497
HURT stats (rel) min: 15.56% max: 15.64% x̄: 15.60% x̃: 15.60%
95% mean confidence interval for cycles value: -2174.88 -1220.01
95% mean confidence interval for cycles %-change: -2.00% 0.30%
Inconclusive result (%-change mean confidence interval includes 0).
total spills in shared programs: 20799 -> 20924 (0.60%)
spills in affected programs: 843 -> 968 (14.83%)
helped: 0
HURT: 4
total fills in shared programs: 27110 -> 27334 (0.83%)
fills in affected programs: 1824 -> 2048 (12.28%)
helped: 1
HURT: 4
total sends in shared programs: 1017935 -> 1017603 (-0.03%)
sends in affected programs: 711 -> 379 (-46.69%)
helped: 5
HURT: 0
helped stats (abs) min: 18 max: 87 x̄: 66.40 x̃: 74
helped stats (rel) min: 27.69% max: 54.72% x̄: 44.49% x̃: 44.31%
95% mean confidence interval for sends value: -101.79 -31.01
95% mean confidence interval for sends %-change: -58.42% -30.55%
Sends are helped.
Haswell and Ivy Bridge had similar results. (Haswell shown)
total instructions in shared programs: 16397496 -> 16395411 (-0.01%)
instructions in affected programs: 59384 -> 57299 (-3.51%)
helped: 49
HURT: 0
helped stats (abs) min: 1 max: 208 x̄: 42.55 x̃: 39
helped stats (rel) min: 0.03% max: 8.18% x̄: 3.74% x̃: 3.91%
95% mean confidence interval for instructions value: -53.59 -31.51
95% mean confidence interval for instructions %-change: -4.24% -3.23%
Instructions are helped.
total cycles in shared programs: 1035483504 -> 1035397592 (<.01%)
cycles in affected programs: 9379739 -> 9293827 (-0.92%)
helped: 45
HURT: 4
helped stats (abs) min: 10 max: 5600 x̄: 2164.51 x̃: 2350
helped stats (rel) min: <.01% max: 11.61% x̄: 1.93% x̃: 1.56%
HURT stats (abs) min: 2 max: 5756 x̄: 2872.75 x̃: 2866
HURT stats (rel) min: <.01% max: 24.65% x̄: 12.29% x̃: 12.26%
95% mean confidence interval for cycles value: -2293.06 -1213.56
95% mean confidence interval for cycles %-change: -2.42% 0.88%
Inconclusive result (%-change mean confidence interval includes 0).
total spills in shared programs: 17672 -> 17803 (0.74%)
spills in affected programs: 364 -> 495 (35.99%)
helped: 2
HURT: 2
total fills in shared programs: 20752 -> 20937 (0.89%)
fills in affected programs: 656 -> 841 (28.20%)
helped: 2
HURT: 2
total sends in shared programs: 1044703 -> 1044450 (-0.02%)
sends in affected programs: 523 -> 270 (-48.37%)
helped: 5
HURT: 0
helped stats (abs) min: 9 max: 87 x̄: 50.60 x̃: 37
helped stats (rel) min: 25.71% max: 54.72% x̄: 43.49% x̃: 42.53%
95% mean confidence interval for sends value: -93.95 -7.25
95% mean confidence interval for sends %-change: -58.48% -28.50%
Sends are helped.
No changes on Gen6 or earlier GPUs.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8852>
2020-01-10 01:13:37 +00:00
|
|
|
(('ishl', ('ishr', a_sz, '#b'), b), ('iand', a, ('ishl', mask, b))),
|
|
|
|
|
|
|
|
# This does not trivially work with ishr.
|
|
|
|
(('ushr', ('ishl', a_sz, '#b'), b), ('iand', a, ('ushr', mask, b))),
|
2021-02-03 00:04:57 +00:00
|
|
|
])
|
|
|
|
|
2019-10-09 15:03:45 +01:00
|
|
|
for log2 in range(1, 7): # powers of two from 2 to 64
|
|
|
|
v = 1 << log2
|
|
|
|
mask = 0xffffffff & ~(v - 1)
|
|
|
|
b_is_multiple = '#b(is_unsigned_multiple_of_{})'.format(v)
|
|
|
|
|
|
|
|
optimizations.extend([
|
|
|
|
# Reassociate for improved CSE
|
2021-02-03 00:04:57 +00:00
|
|
|
(('iand@32', ('iadd@32', a, b_is_multiple), mask), ('iadd', ('iand', a, mask), b)),
|
2019-10-09 15:03:45 +01:00
|
|
|
])
|
|
|
|
|
2020-03-07 00:23:29 +00:00
|
|
|
# To save space in the state tables, reduce to the set that is known to help.
|
|
|
|
# Previously, this was range(1, 32). In addition, a couple rules inside the
|
|
|
|
# loop are commented out. Revisit someday, probably after mesa/#2635 has some
|
|
|
|
# resolution.
|
|
|
|
for i in [1, 2, 16, 24]:
|
|
|
|
lo_mask = 0xffffffff >> i
|
|
|
|
hi_mask = (0xffffffff << i) & 0xffffffff
|
|
|
|
|
|
|
|
optimizations.extend([
|
|
|
|
# This pattern seems to only help in the soft-fp64 code.
|
|
|
|
(('ishl@32', ('iand', 'a@32', lo_mask), i), ('ishl', a, i)),
|
|
|
|
# (('ushr@32', ('iand', 'a@32', hi_mask), i), ('ushr', a, i)),
|
|
|
|
# (('ishr@32', ('iand', 'a@32', hi_mask), i), ('ishr', a, i)),
|
|
|
|
|
|
|
|
(('iand', ('ishl', 'a@32', i), hi_mask), ('ishl', a, i)),
|
|
|
|
(('iand', ('ushr', 'a@32', i), lo_mask), ('ushr', a, i)),
|
|
|
|
# (('iand', ('ishr', 'a@32', i), lo_mask), ('ushr', a, i)), # Yes, ushr is correct
|
|
|
|
])
|
|
|
|
|
2019-08-06 21:11:56 +01:00
|
|
|
optimizations.extend([
|
nir/algebraic: Reassociate add-and-shift to be shift-and-add
A common thing in many shaders:
uniform vs { vec4 bones[...]; };
...
x = some_calculation(bones[i + 0]);
y = some_calculation(bones[i + 1]);
z = some_calculation(bones[i + 2]);
This turns into stuff like
vec1 32 ssa_12 = iadd ssa_11, ssa_0
vec1 32 ssa_13 = ishl ssa_12, ssa_3
vec1 32 ssa_14 = intrinsic load_ssbo (ssa_7, ssa_13) (16, 4, 0)
vec1 32 ssa_15 = iadd ssa_11, ssa_1
vec1 32 ssa_16 = ishl ssa_15, ssa_3
vec1 32 ssa_17 = intrinsic load_ssbo (ssa_7, ssa_16) (16, 4, 0)
vec1 32 ssa_18 = iadd ssa_11, ssa_2
vec1 32 ssa_19 = ishl ssa_18, ssa_3
vec1 32 ssa_20 = intrinsic load_ssbo (ssa_7, ssa_19) (16, 4, 0)
By reassociating the shift and the add, we can reduce this to
vec1 32 ssa_12 = ishl ssa_11, ssa_3
vec1 32 ssa_13 = iadd ssa_12, ssa_0
vec1 32 ssa_14 = intrinsic load_ssbo (ssa_7, ssa_13) (16, 4, 0)
vec1 32 ssa_16 = iadd ssa_12, ssa_1
vec1 32 ssa_17 = intrinsic load_ssbo (ssa_7, ssa_16) (16, 4, 0)
vec1 32 ssa_19 = iadd ssa_12, ssa_2
vec1 32 ssa_20 = intrinsic load_ssbo (ssa_7, ssa_19) (16, 4, 0)
v2: Add some commentary from Rhys Perry's nearly identical patch.
All Intel platforms had similar results. (Ice Lake shown)
total instructions in shared programs: 16277758 -> 16250704 (-0.17%)
instructions in affected programs: 1440284 -> 1413230 (-1.88%)
helped: 4920
HURT: 6
helped stats (abs) min: 1 max: 69 x̄: 5.50 x̃: 4
helped stats (rel) min: 0.10% max: 18.33% x̄: 2.21% x̃: 1.79%
HURT stats (abs) min: 1 max: 12 x̄: 4.50 x̃: 3
HURT stats (rel) min: 0.18% max: 3.23% x̄: 1.91% x̃: 2.55%
95% mean confidence interval for instructions value: -5.67 -5.31
95% mean confidence interval for instructions %-change: -2.26% -2.16%
Instructions are helped.
total cycles in shared programs: 367118526 -> 365895358 (-0.33%)
cycles in affected programs: 93504145 -> 92280977 (-1.31%)
helped: 2754
HURT: 1269
helped stats (abs) min: 1 max: 47039 x̄: 460.66 x̃: 16
helped stats (rel) min: <.01% max: 34.93% x̄: 3.77% x̃: 1.12%
HURT stats (abs) min: 1 max: 1500 x̄: 35.85 x̃: 9
HURT stats (rel) min: 0.01% max: 17.35% x̄: 2.18% x̃: 0.75%
95% mean confidence interval for cycles value: -387.31 -220.78
95% mean confidence interval for cycles %-change: -2.11% -1.68%
Cycles are helped.
LOST: 1
GAINED: 1
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2019-07-11 00:28:38 +01:00
|
|
|
# This is common for address calculations. Reassociating may enable the
|
|
|
|
# 'a<<c' to be CSE'd. It also helps architectures that have an ISHLADD
|
|
|
|
# instruction or a constant offset field for in load / store instructions.
|
|
|
|
(('ishl', ('iadd', a, '#b'), '#c'), ('iadd', ('ishl', a, c), ('ishl', b, c))),
|
|
|
|
|
2021-02-26 18:05:25 +00:00
|
|
|
# (a + #b) * #c => (a * #c) + (#b * #c)
|
nir/algebraic: distribute imul(iadd(a, b), c) when b and c are constants
This distributes imul(iadd(a, b), c) to iadd(imul(a, c), b * c)
when both b and c are constants. This might allow some compiler
backends to create more MADs.
For ACO, this allows to combine more DS additions.
fossilds-db (Vega10):
Totals from 673 (0.49% of 136546) affected shaders:
VGPRs: 44548 -> 44516 (-0.07%); split: -0.11%, +0.04%
CodeSize: 8301552 -> 8286220 (-0.18%); split: -0.19%, +0.01%
MaxWaves: 2731 -> 2735 (+0.15%); split: +0.26%, -0.11%
Instrs: 1642684 -> 1638725 (-0.24%); split: -0.24%, +0.00%
Cycles: 20846156 -> 20793444 (-0.25%); split: -0.25%, +0.00%
VMEM: 108870 -> 108106 (-0.70%); split: +0.03%, -0.73%
SMEM: 35718 -> 35674 (-0.12%); split: +0.22%, -0.34%
VClause: 20603 -> 20622 (+0.09%); split: -0.01%, +0.10%
SClause: 48527 -> 48539 (+0.02%)
Copies: 156735 -> 156742 (+0.00%); split: -0.05%, +0.05%
PreSGPRs: 43169 -> 43166 (-0.01%); split: -0.02%, +0.02%
PreVGPRs: 41369 -> 41330 (-0.09%)
shader-db results on Intel:
Ice Lake
total instructions in shared programs: 20027588 -> 20027446 (<.01%)
instructions in affected programs: 71766 -> 71624 (-0.20%)
helped: 70
HURT: 0
helped stats (abs) min: 1 max: 7 x̄: 2.03 x̃: 1
helped stats (rel) min: 0.10% max: 2.50% x̄: 0.29% x̃: 0.15%
95% mean confidence interval for instructions value: -2.42 -1.64
95% mean confidence interval for instructions %-change: -0.38% -0.20%
Instructions are helped.
total cycles in shared programs: 977525222 -> 977494323 (<.01%)
cycles in affected programs: 8884593 -> 8853694 (-0.35%)
helped: 56
HURT: 16
helped stats (abs) min: 2 max: 7852 x̄: 681.29 x̃: 400
helped stats (rel) min: <.01% max: 19.84% x̄: 2.79% x̃: 0.41%
HURT stats (abs) min: 2 max: 1212 x̄: 453.31 x̃: 120
HURT stats (rel) min: 0.05% max: 1.09% x̄: 0.32% x̃: 0.11%
95% mean confidence interval for cycles value: -802.75 -55.56
95% mean confidence interval for cycles %-change: -3.19% -1.01%
Cycles are helped.
total sends in shared programs: 1032273 -> 1032272 (<.01%)
sends in affected programs: 41 -> 40 (-2.44%)
helped: 1
HURT: 0
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7445>
2020-11-04 12:56:41 +00:00
|
|
|
(('imul', ('iadd(is_used_once)', a, '#b'), '#c'), ('iadd', ('imul', a, c), ('imul', b, c))),
|
|
|
|
|
2021-02-26 18:05:25 +00:00
|
|
|
# ((a + #b) + c) * #d => ((a + c) * #d) + (#b * #d)
|
|
|
|
(('imul', ('iadd(is_used_once)', ('iadd(is_used_once)', a, '#b'), c), '#d'),
|
|
|
|
('iadd', ('imul', ('iadd', a, c), d), ('imul', b, d))),
|
|
|
|
(('ishl', ('iadd(is_used_once)', ('iadd(is_used_once)', a, '#b'), c), '#d'),
|
|
|
|
('iadd', ('ishl', ('iadd', a, c), d), ('ishl', b, d))),
|
|
|
|
|
2015-01-22 07:36:01 +00:00
|
|
|
# Comparison simplifications
|
2020-02-25 23:24:10 +00:00
|
|
|
(('inot', ('flt(is_used_once)', 'a(is_a_number)', 'b(is_a_number)')), ('fge', a, b)),
|
|
|
|
(('inot', ('fge(is_used_once)', 'a(is_a_number)', 'b(is_a_number)')), ('flt', a, b)),
|
nir/algebraic: Invert comparisons less often
This fixes the piglit test range_analysis_fsat_of_nan.shader_test. That
test contains some code like
o = saturate(X) > 0 ? vec4(1.0, 0.0, 0.0, 1.0)
: vec4(0.0, 1.0, 0.0, 1.0);
A clever optimizer will convert this to
o = vec4(float(saturate(X) > 0),
float(!(saturate(X) > 0)),
0, 1);
Due to the ordering of optimizations in the compiler, the `saturate`
operations are removed. This is safe even in the presense of NaN.
o = vec4(float(X > 0), float(!(X > 0)), 0, 1);
Since the calculations are not marked precise, an overzealous
optimizer may reduce this to
o = vec4(float(X > 0), float(X <= 0), 0, 1);
This will result in black being output. The GLSL spec gives quite a bit
of leeway with respect to NaN, but that seems too far. The shader
author asked for a result of red or green. A result of black is still
"undefined behavior," but it's also a little mean.
This also enables CSE to do its job better.
v2: Update A530 expected image checksum for minetest.trace.
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4531
Fixes: 0dbda153aae ("nir/algebraic: Flag inexact optimizations")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Tiger Lake
total instructions in shared programs: 21041563 -> 21041789 (<.01%)
instructions in affected programs: 992066 -> 992292 (0.02%)
helped: 526
HURT: 548
helped stats (abs) min: 1 max: 16 x̄: 2.48 x̃: 2
helped stats (rel) min: 0.04% max: 5.56% x̄: 0.74% x̃: 0.49%
HURT stats (abs) min: 1 max: 27 x̄: 2.80 x̃: 2
HURT stats (rel) min: 0.04% max: 4.55% x̄: 0.59% x̃: 0.38%
95% mean confidence interval for instructions value: -0.00 0.42
95% mean confidence interval for instructions %-change: -0.12% <.01%
Inconclusive result (value mean confidence interval includes 0).
total cycles in shared programs: 855885569 -> 856118189 (0.03%)
cycles in affected programs: 343637248 -> 343869868 (0.07%)
helped: 907
HURT: 541
helped stats (abs) min: 1 max: 7724 x̄: 206.45 x̃: 36
helped stats (rel) min: <.01% max: 29.97% x̄: 1.01% x̃: 0.37%
HURT stats (abs) min: 1 max: 14177 x̄: 776.09 x̃: 31
HURT stats (rel) min: <.01% max: 29.94% x̄: 1.24% x̃: 0.35%
95% mean confidence interval for cycles value: 84.30 237.00
95% mean confidence interval for cycles %-change: -0.32% -0.01%
Inconclusive result (value mean confidence interval and %-change mean confidence interval disagree).
LOST: 3
GAINED: 5
Ice Lake
total instructions in shared programs: 20027107 -> 20025352 (<.01%)
instructions in affected programs: 1068856 -> 1067101 (-0.16%)
helped: 1153
HURT: 273
helped stats (abs) min: 1 max: 14 x̄: 1.83 x̃: 1
helped stats (rel) min: 0.03% max: 5.66% x̄: 0.61% x̃: 0.35%
HURT stats (abs) min: 1 max: 15 x̄: 1.29 x̃: 1
HURT stats (rel) min: 0.16% max: 1.30% x̄: 0.58% x̃: 0.60%
95% mean confidence interval for instructions value: -1.33 -1.13
95% mean confidence interval for instructions %-change: -0.43% -0.34%
Instructions are helped.
total cycles in shared programs: 979499227 -> 979448725 (<.01%)
cycles in affected programs: 344261539 -> 344211037 (-0.01%)
helped: 1079
HURT: 441
helped stats (abs) min: 1 max: 9384 x̄: 147.78 x̃: 48
helped stats (rel) min: <.01% max: 31.83% x̄: 0.90% x̃: 0.33%
HURT stats (abs) min: 1 max: 7220 x̄: 247.07 x̃: 32
HURT stats (rel) min: <.01% max: 31.30% x̄: 1.52% x̃: 0.53%
95% mean confidence interval for cycles value: -70.01 3.56
95% mean confidence interval for cycles %-change: -0.35% -0.05%
Inconclusive result (value mean confidence interval includes 0).
total spills in shared programs: 10564 -> 10568 (0.04%)
spills in affected programs: 143 -> 147 (2.80%)
helped: 0
HURT: 1
total fills in shared programs: 11343 -> 11347 (0.04%)
fills in affected programs: 287 -> 291 (1.39%)
helped: 0
HURT: 1
LOST: 3
GAINED: 2
Skylake
total instructions in shared programs: 18192274 -> 18190128 (-0.01%)
instructions in affected programs: 1000188 -> 998042 (-0.21%)
helped: 1149
HURT: 55
helped stats (abs) min: 1 max: 14 x̄: 1.92 x̃: 1
helped stats (rel) min: 0.04% max: 6.67% x̄: 0.67% x̃: 0.42%
HURT stats (abs) min: 1 max: 2 x̄: 1.05 x̃: 1
HURT stats (rel) min: 0.16% max: 0.55% x̄: 0.27% x̃: 0.26%
95% mean confidence interval for instructions value: -1.87 -1.69
95% mean confidence interval for instructions %-change: -0.67% -0.58%
Instructions are helped.
total cycles in shared programs: 960856054 -> 960728040 (-0.01%)
cycles in affected programs: 340840968 -> 340712954 (-0.04%)
helped: 1079
HURT: 233
helped stats (abs) min: 1 max: 7640 x̄: 170.95 x̃: 46
helped stats (rel) min: <.01% max: 30.20% x̄: 0.96% x̃: 0.28%
HURT stats (abs) min: 1 max: 6864 x̄: 242.23 x̃: 26
HURT stats (rel) min: <.01% max: 34.64% x̄: 2.10% x̃: 0.22%
95% mean confidence interval for cycles value: -135.62 -59.53
95% mean confidence interval for cycles %-change: -0.59% -0.25%
Cycles are helped.
LOST: 15
GAINED: 1
Broadwell
total instructions in shared programs: 17855624 -> 17853580 (-0.01%)
instructions in affected programs: 1012209 -> 1010165 (-0.20%)
helped: 1105
HURT: 52
helped stats (abs) min: 1 max: 13 x̄: 1.90 x̃: 1
helped stats (rel) min: 0.03% max: 6.67% x̄: 0.67% x̃: 0.36%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.13% max: 0.52% x̄: 0.26% x̃: 0.25%
95% mean confidence interval for instructions value: -1.86 -1.67
95% mean confidence interval for instructions %-change: -0.68% -0.58%
Instructions are helped.
total cycles in shared programs: 1029905447 -> 1029840699 (<.01%)
cycles in affected programs: 347102680 -> 347037932 (-0.02%)
helped: 1007
HURT: 211
helped stats (abs) min: 1 max: 1360 x̄: 89.76 x̃: 48
helped stats (rel) min: <.01% max: 16.26% x̄: 0.69% x̃: 0.25%
HURT stats (abs) min: 1 max: 1297 x̄: 121.51 x̃: 20
HURT stats (rel) min: <.01% max: 31.31% x̄: 1.21% x̃: 0.20%
95% mean confidence interval for cycles value: -62.39 -43.92
95% mean confidence interval for cycles %-change: -0.47% -0.25%
Cycles are helped.
total spills in shared programs: 20335 -> 20333 (<.01%)
spills in affected programs: 19 -> 17 (-10.53%)
helped: 2
HURT: 0
total fills in shared programs: 25905 -> 25899 (-0.02%)
fills in affected programs: 23 -> 17 (-26.09%)
helped: 2
HURT: 0
LOST: 9
GAINED: 0
Haswell
total instructions in shared programs: 16418516 -> 16417293 (<.01%)
instructions in affected programs: 223785 -> 222562 (-0.55%)
helped: 590
HURT: 67
helped stats (abs) min: 1 max: 15 x̄: 2.19 x̃: 1
helped stats (rel) min: 0.03% max: 6.52% x̄: 0.87% x̃: 0.60%
HURT stats (abs) min: 1 max: 2 x̄: 1.04 x̃: 1
HURT stats (rel) min: 0.04% max: 1.85% x̄: 0.44% x̃: 0.25%
95% mean confidence interval for instructions value: -2.01 -1.71
95% mean confidence interval for instructions %-change: -0.80% -0.67%
Instructions are helped.
total cycles in shared programs: 1037179754 -> 1037084874 (<.01%)
cycles in affected programs: 352541071 -> 352446191 (-0.03%)
helped: 1093
HURT: 182
helped stats (abs) min: 1 max: 888 x̄: 111.03 x̃: 64
helped stats (rel) min: <.01% max: 27.30% x̄: 0.84% x̃: 0.20%
HURT stats (abs) min: 1 max: 6777 x̄: 145.49 x̃: 21
HURT stats (rel) min: <.01% max: 24.10% x̄: 1.99% x̃: 0.29%
95% mean confidence interval for cycles value: -88.10 -60.73
95% mean confidence interval for cycles %-change: -0.58% -0.29%
Cycles are helped.
total spills in shared programs: 17457 -> 17456 (<.01%)
spills in affected programs: 12 -> 11 (-8.33%)
helped: 1
HURT: 0
total fills in shared programs: 20387 -> 20385 (<.01%)
fills in affected programs: 15 -> 13 (-13.33%)
helped: 1
HURT: 0
LOST: 6
GAINED: 1
Ivy Bridge and earlier platforms had similar results. (Ivy Bridge shown)
total instructions in shared programs: 15515482 -> 15513998 (<.01%)
instructions in affected programs: 239739 -> 238255 (-0.62%)
helped: 573
HURT: 57
helped stats (abs) min: 1 max: 20 x̄: 2.73 x̃: 2
helped stats (rel) min: 0.03% max: 9.84% x̄: 0.94% x̃: 0.55%
HURT stats (abs) min: 1 max: 2 x̄: 1.39 x̃: 1
HURT stats (rel) min: 0.09% max: 1.85% x̄: 0.52% x̃: 0.35%
95% mean confidence interval for instructions value: -2.57 -2.14
95% mean confidence interval for instructions %-change: -0.89% -0.73%
Instructions are helped.
total cycles in shared programs: 584509880 -> 584463152 (<.01%)
cycles in affected programs: 11765280 -> 11718552 (-0.40%)
helped: 661
HURT: 152
helped stats (abs) min: 1 max: 3073 x̄: 101.99 x̃: 32
helped stats (rel) min: <.01% max: 34.38% x̄: 1.46% x̃: 0.50%
HURT stats (abs) min: 1 max: 6637 x̄: 136.10 x̃: 15
HURT stats (rel) min: <.01% max: 24.19% x̄: 1.75% x̃: 0.25%
95% mean confidence interval for cycles value: -82.79 -32.16
95% mean confidence interval for cycles %-change: -1.11% -0.61%
Cycles are helped.
LOST: 9
GAINED: 0
Tiger Lake
Instructions in all programs: 160905127 -> 160900949 (-0.0%)
SENDs in all programs: 6812418 -> 6812085 (-0.0%)
Loops in all programs: 38225 -> 38225 (+0.0%)
Cycles in all programs: 7431911114 -> 7433914697 (+0.0%)
Spills in all programs: 192582 -> 192582 (+0.0%)
Fills in all programs: 304539 -> 304537 (-0.0%)
Ice Lake
Instructions in all programs: 145296733 -> 145292370 (-0.0%)
SENDs in all programs: 6863818 -> 6863485 (-0.0%)
Loops in all programs: 38219 -> 38219 (+0.0%)
Cycles in all programs: 8798257570 -> 8800204360 (+0.0%)
Spills in all programs: 216880 -> 216880 (+0.0%)
Fills in all programs: 334250 -> 334248 (-0.0%)
Skylake
Instructions in all programs: 135891485 -> 135887357 (-0.0%)
SENDs in all programs: 6803031 -> 6802698 (-0.0%)
Loops in all programs: 38216 -> 38216 (+0.0%)
Cycles in all programs: 8442221881 -> 8444201959 (+0.0%)
Spills in all programs: 194839 -> 194839 (+0.0%)
Fills in all programs: 301116 -> 301114 (-0.0%)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-02-25 18:36:23 +00:00
|
|
|
(('inot', ('feq(is_used_once)', a, b)), ('fneu', a, b)),
|
|
|
|
(('inot', ('fneu(is_used_once)', a, b)), ('feq', a, b)),
|
|
|
|
(('inot', ('ilt(is_used_once)', a, b)), ('ige', a, b)),
|
|
|
|
(('inot', ('ult(is_used_once)', a, b)), ('uge', a, b)),
|
|
|
|
(('inot', ('ige(is_used_once)', a, b)), ('ilt', a, b)),
|
|
|
|
(('inot', ('uge(is_used_once)', a, b)), ('ult', a, b)),
|
|
|
|
(('inot', ('ieq(is_used_once)', a, b)), ('ine', a, b)),
|
|
|
|
(('inot', ('ine(is_used_once)', a, b)), ('ieq', a, b)),
|
2016-03-02 23:18:34 +00:00
|
|
|
|
2020-08-18 18:51:57 +01:00
|
|
|
(('iand', ('feq', a, b), ('fneu', a, b)), False),
|
2019-06-28 16:13:04 +01:00
|
|
|
(('iand', ('flt', a, b), ('flt', b, a)), False),
|
|
|
|
(('iand', ('ieq', a, b), ('ine', a, b)), False),
|
|
|
|
(('iand', ('ilt', a, b), ('ilt', b, a)), False),
|
|
|
|
(('iand', ('ult', a, b), ('ult', b, a)), False),
|
|
|
|
|
2019-03-06 22:07:18 +00:00
|
|
|
# This helps some shaders because, after some optimizations, they end up
|
|
|
|
# with patterns like (-a < -b) || (b < a). In an ideal world, this sort of
|
|
|
|
# matching would be handled by CSE.
|
|
|
|
(('flt', ('fneg', a), ('fneg', b)), ('flt', b, a)),
|
|
|
|
(('fge', ('fneg', a), ('fneg', b)), ('fge', b, a)),
|
|
|
|
(('feq', ('fneg', a), ('fneg', b)), ('feq', b, a)),
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('fneg', a), ('fneg', b)), ('fneu', b, a)),
|
2019-03-06 22:07:18 +00:00
|
|
|
(('flt', ('fneg', a), -1.0), ('flt', 1.0, a)),
|
|
|
|
(('flt', -1.0, ('fneg', a)), ('flt', a, 1.0)),
|
|
|
|
(('fge', ('fneg', a), -1.0), ('fge', 1.0, a)),
|
|
|
|
(('fge', -1.0, ('fneg', a)), ('fge', a, 1.0)),
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('fneg', a), -1.0), ('fneu', 1.0, a)),
|
2019-03-06 22:07:18 +00:00
|
|
|
(('feq', -1.0, ('fneg', a)), ('feq', a, 1.0)),
|
|
|
|
|
nir/algebraic: Remove some optimizations of comparisons with fsat
When most of these patterns were created, we believed, incorrectly, that
fsat(NaN) was NaN. We have since realized that fsat(NaN) is zero.
Originally, this changed the patterns to use is_a_number. This didn't
help any shaders, so it's easier to just drop the optimizations.
This commit crossed paths with 4c3ad4d0658 ("nir/algebraic: mark more
optimization with fsat(NaN) as inexact") and bc123c396a9
("nir/algebraic: mark some optimizations with fsat(NaN) as inexact").
Given that these don't impact very many shaders, it seems safer to just
remove them.
As discussed in
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8716, I tried
modifying these patterns to use !(b cmp a). Unfortunately, on Intel
GPUs, the results were much worse than just removing the patterns
altogether.
Some other related patterns will be addressed in later commits.
There are still a number of patterns that use the identity fsat(1-X) ==
1 - fsat(X). If X is NaN, the former is zero while the latter is 1.0.
I haven't evaluted these patterns yet. If changes are needed in these
patterns, it should be a separate commit anyway.
v2: Replace arrow `=>` with `->` in comments because the `=>` looks a
lot like `<=` comparison. Suggested by Rhys.
Fixes: 92b75c126bb ("nir/algebraic: Replace checks that a value is between (or not) [0, 1]")
Fixes: a7f0c57673d ("nir/algebraic: Eliminate useless fsat() on operand of comparison w/value in (0, 1)")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel hardware had similar results. (Ice Lake shown)
total instructions in shared programs: 20029060 -> 20029670 (<.01%)
instructions in affected programs: 69236 -> 69846 (0.88%)
helped: 0
HURT: 263
HURT stats (abs) min: 1 max: 20 x̄: 2.32 x̃: 1
HURT stats (rel) min: 0.30% max: 11.11% x̄: 1.35% x̃: 0.98%
95% mean confidence interval for instructions value: 1.86 2.78
95% mean confidence interval for instructions %-change: 1.18% 1.52%
Instructions are HURT.
total cycles in shared programs: 979821278 -> 979834425 (<.01%)
cycles in affected programs: 1476848 -> 1489995 (0.89%)
helped: 49
HURT: 204
helped stats (abs) min: 1 max: 812 x̄: 102.31 x̃: 20
helped stats (rel) min: 0.01% max: 21.43% x̄: 2.23% x̃: 0.52%
HURT stats (abs) min: 2 max: 2600 x̄: 89.02 x̃: 16
HURT stats (rel) min: 0.04% max: 27.27% x̄: 1.49% x̃: 0.72%
95% mean confidence interval for cycles value: 13.18 90.75
95% mean confidence interval for cycles %-change: 0.29% 1.25%
Cycles are HURT.
No fossil-db changes.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-05 18:38:52 +01:00
|
|
|
# b < fsat(NaN) -> b < 0 -> false, and b < Nan -> false.
|
2019-03-05 22:54:35 +00:00
|
|
|
(('flt', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('flt', b, a)),
|
nir/algebraic: Remove some optimizations of comparisons with fsat
When most of these patterns were created, we believed, incorrectly, that
fsat(NaN) was NaN. We have since realized that fsat(NaN) is zero.
Originally, this changed the patterns to use is_a_number. This didn't
help any shaders, so it's easier to just drop the optimizations.
This commit crossed paths with 4c3ad4d0658 ("nir/algebraic: mark more
optimization with fsat(NaN) as inexact") and bc123c396a9
("nir/algebraic: mark some optimizations with fsat(NaN) as inexact").
Given that these don't impact very many shaders, it seems safer to just
remove them.
As discussed in
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8716, I tried
modifying these patterns to use !(b cmp a). Unfortunately, on Intel
GPUs, the results were much worse than just removing the patterns
altogether.
Some other related patterns will be addressed in later commits.
There are still a number of patterns that use the identity fsat(1-X) ==
1 - fsat(X). If X is NaN, the former is zero while the latter is 1.0.
I haven't evaluted these patterns yet. If changes are needed in these
patterns, it should be a separate commit anyway.
v2: Replace arrow `=>` with `->` in comments because the `=>` looks a
lot like `<=` comparison. Suggested by Rhys.
Fixes: 92b75c126bb ("nir/algebraic: Replace checks that a value is between (or not) [0, 1]")
Fixes: a7f0c57673d ("nir/algebraic: Eliminate useless fsat() on operand of comparison w/value in (0, 1)")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel hardware had similar results. (Ice Lake shown)
total instructions in shared programs: 20029060 -> 20029670 (<.01%)
instructions in affected programs: 69236 -> 69846 (0.88%)
helped: 0
HURT: 263
HURT stats (abs) min: 1 max: 20 x̄: 2.32 x̃: 1
HURT stats (rel) min: 0.30% max: 11.11% x̄: 1.35% x̃: 0.98%
95% mean confidence interval for instructions value: 1.86 2.78
95% mean confidence interval for instructions %-change: 1.18% 1.52%
Instructions are HURT.
total cycles in shared programs: 979821278 -> 979834425 (<.01%)
cycles in affected programs: 1476848 -> 1489995 (0.89%)
helped: 49
HURT: 204
helped stats (abs) min: 1 max: 812 x̄: 102.31 x̃: 20
helped stats (rel) min: 0.01% max: 21.43% x̄: 2.23% x̃: 0.52%
HURT stats (abs) min: 2 max: 2600 x̄: 89.02 x̃: 16
HURT stats (rel) min: 0.04% max: 27.27% x̄: 1.49% x̃: 0.72%
95% mean confidence interval for cycles value: 13.18 90.75
95% mean confidence interval for cycles %-change: 0.29% 1.25%
Cycles are HURT.
No fossil-db changes.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-05 18:38:52 +01:00
|
|
|
|
|
|
|
# fsat(NaN) >= b -> 0 >= b -> false, and NaN >= b -> false.
|
2019-03-05 22:54:35 +00:00
|
|
|
(('fge', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fge', a, b)),
|
nir/algebraic: Remove some optimizations of comparisons with fsat
When most of these patterns were created, we believed, incorrectly, that
fsat(NaN) was NaN. We have since realized that fsat(NaN) is zero.
Originally, this changed the patterns to use is_a_number. This didn't
help any shaders, so it's easier to just drop the optimizations.
This commit crossed paths with 4c3ad4d0658 ("nir/algebraic: mark more
optimization with fsat(NaN) as inexact") and bc123c396a9
("nir/algebraic: mark some optimizations with fsat(NaN) as inexact").
Given that these don't impact very many shaders, it seems safer to just
remove them.
As discussed in
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8716, I tried
modifying these patterns to use !(b cmp a). Unfortunately, on Intel
GPUs, the results were much worse than just removing the patterns
altogether.
Some other related patterns will be addressed in later commits.
There are still a number of patterns that use the identity fsat(1-X) ==
1 - fsat(X). If X is NaN, the former is zero while the latter is 1.0.
I haven't evaluted these patterns yet. If changes are needed in these
patterns, it should be a separate commit anyway.
v2: Replace arrow `=>` with `->` in comments because the `=>` looks a
lot like `<=` comparison. Suggested by Rhys.
Fixes: 92b75c126bb ("nir/algebraic: Replace checks that a value is between (or not) [0, 1]")
Fixes: a7f0c57673d ("nir/algebraic: Eliminate useless fsat() on operand of comparison w/value in (0, 1)")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel hardware had similar results. (Ice Lake shown)
total instructions in shared programs: 20029060 -> 20029670 (<.01%)
instructions in affected programs: 69236 -> 69846 (0.88%)
helped: 0
HURT: 263
HURT stats (abs) min: 1 max: 20 x̄: 2.32 x̃: 1
HURT stats (rel) min: 0.30% max: 11.11% x̄: 1.35% x̃: 0.98%
95% mean confidence interval for instructions value: 1.86 2.78
95% mean confidence interval for instructions %-change: 1.18% 1.52%
Instructions are HURT.
total cycles in shared programs: 979821278 -> 979834425 (<.01%)
cycles in affected programs: 1476848 -> 1489995 (0.89%)
helped: 49
HURT: 204
helped stats (abs) min: 1 max: 812 x̄: 102.31 x̃: 20
helped stats (rel) min: 0.01% max: 21.43% x̄: 2.23% x̃: 0.52%
HURT stats (abs) min: 2 max: 2600 x̄: 89.02 x̃: 16
HURT stats (rel) min: 0.04% max: 27.27% x̄: 1.49% x̃: 0.72%
95% mean confidence interval for cycles value: 13.18 90.75
95% mean confidence interval for cycles %-change: 0.29% 1.25%
Cycles are HURT.
No fossil-db changes.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-05 18:38:52 +01:00
|
|
|
|
|
|
|
# b == fsat(NaN) -> b == 0 -> false, and b == NaN -> false.
|
2019-03-05 22:54:35 +00:00
|
|
|
(('feq', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('feq', a, b)),
|
nir/algebraic: Remove some optimizations of comparisons with fsat
When most of these patterns were created, we believed, incorrectly, that
fsat(NaN) was NaN. We have since realized that fsat(NaN) is zero.
Originally, this changed the patterns to use is_a_number. This didn't
help any shaders, so it's easier to just drop the optimizations.
This commit crossed paths with 4c3ad4d0658 ("nir/algebraic: mark more
optimization with fsat(NaN) as inexact") and bc123c396a9
("nir/algebraic: mark some optimizations with fsat(NaN) as inexact").
Given that these don't impact very many shaders, it seems safer to just
remove them.
As discussed in
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8716, I tried
modifying these patterns to use !(b cmp a). Unfortunately, on Intel
GPUs, the results were much worse than just removing the patterns
altogether.
Some other related patterns will be addressed in later commits.
There are still a number of patterns that use the identity fsat(1-X) ==
1 - fsat(X). If X is NaN, the former is zero while the latter is 1.0.
I haven't evaluted these patterns yet. If changes are needed in these
patterns, it should be a separate commit anyway.
v2: Replace arrow `=>` with `->` in comments because the `=>` looks a
lot like `<=` comparison. Suggested by Rhys.
Fixes: 92b75c126bb ("nir/algebraic: Replace checks that a value is between (or not) [0, 1]")
Fixes: a7f0c57673d ("nir/algebraic: Eliminate useless fsat() on operand of comparison w/value in (0, 1)")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel hardware had similar results. (Ice Lake shown)
total instructions in shared programs: 20029060 -> 20029670 (<.01%)
instructions in affected programs: 69236 -> 69846 (0.88%)
helped: 0
HURT: 263
HURT stats (abs) min: 1 max: 20 x̄: 2.32 x̃: 1
HURT stats (rel) min: 0.30% max: 11.11% x̄: 1.35% x̃: 0.98%
95% mean confidence interval for instructions value: 1.86 2.78
95% mean confidence interval for instructions %-change: 1.18% 1.52%
Instructions are HURT.
total cycles in shared programs: 979821278 -> 979834425 (<.01%)
cycles in affected programs: 1476848 -> 1489995 (0.89%)
helped: 49
HURT: 204
helped stats (abs) min: 1 max: 812 x̄: 102.31 x̃: 20
helped stats (rel) min: 0.01% max: 21.43% x̄: 2.23% x̃: 0.52%
HURT stats (abs) min: 2 max: 2600 x̄: 89.02 x̃: 16
HURT stats (rel) min: 0.04% max: 27.27% x̄: 1.49% x̃: 0.72%
95% mean confidence interval for cycles value: 13.18 90.75
95% mean confidence interval for cycles %-change: 0.29% 1.25%
Cycles are HURT.
No fossil-db changes.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-05 18:38:52 +01:00
|
|
|
|
|
|
|
# b != fsat(NaN) -> b != 0 -> true, and b != NaN -> true.
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fneu', a, b)),
|
2019-03-05 22:54:35 +00:00
|
|
|
|
nir/algebraic: Remove some optimizations of comparisons with fsat
When most of these patterns were created, we believed, incorrectly, that
fsat(NaN) was NaN. We have since realized that fsat(NaN) is zero.
Originally, this changed the patterns to use is_a_number. This didn't
help any shaders, so it's easier to just drop the optimizations.
This commit crossed paths with 4c3ad4d0658 ("nir/algebraic: mark more
optimization with fsat(NaN) as inexact") and bc123c396a9
("nir/algebraic: mark some optimizations with fsat(NaN) as inexact").
Given that these don't impact very many shaders, it seems safer to just
remove them.
As discussed in
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8716, I tried
modifying these patterns to use !(b cmp a). Unfortunately, on Intel
GPUs, the results were much worse than just removing the patterns
altogether.
Some other related patterns will be addressed in later commits.
There are still a number of patterns that use the identity fsat(1-X) ==
1 - fsat(X). If X is NaN, the former is zero while the latter is 1.0.
I haven't evaluted these patterns yet. If changes are needed in these
patterns, it should be a separate commit anyway.
v2: Replace arrow `=>` with `->` in comments because the `=>` looks a
lot like `<=` comparison. Suggested by Rhys.
Fixes: 92b75c126bb ("nir/algebraic: Replace checks that a value is between (or not) [0, 1]")
Fixes: a7f0c57673d ("nir/algebraic: Eliminate useless fsat() on operand of comparison w/value in (0, 1)")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel hardware had similar results. (Ice Lake shown)
total instructions in shared programs: 20029060 -> 20029670 (<.01%)
instructions in affected programs: 69236 -> 69846 (0.88%)
helped: 0
HURT: 263
HURT stats (abs) min: 1 max: 20 x̄: 2.32 x̃: 1
HURT stats (rel) min: 0.30% max: 11.11% x̄: 1.35% x̃: 0.98%
95% mean confidence interval for instructions value: 1.86 2.78
95% mean confidence interval for instructions %-change: 1.18% 1.52%
Instructions are HURT.
total cycles in shared programs: 979821278 -> 979834425 (<.01%)
cycles in affected programs: 1476848 -> 1489995 (0.89%)
helped: 49
HURT: 204
helped stats (abs) min: 1 max: 812 x̄: 102.31 x̃: 20
helped stats (rel) min: 0.01% max: 21.43% x̄: 2.23% x̃: 0.52%
HURT stats (abs) min: 2 max: 2600 x̄: 89.02 x̃: 16
HURT stats (rel) min: 0.04% max: 27.27% x̄: 1.49% x̃: 0.72%
95% mean confidence interval for cycles value: 13.18 90.75
95% mean confidence interval for cycles %-change: 0.29% 1.25%
Cycles are HURT.
No fossil-db changes.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-05 18:38:52 +01:00
|
|
|
# fsat(NaN) >= 1 -> 0 >= 1 -> false, and NaN >= 1 -> false.
|
2019-03-05 22:54:35 +00:00
|
|
|
(('fge', ('fsat(is_used_once)', a), 1.0), ('fge', a, 1.0)),
|
nir/algebraic: Remove some optimizations of comparisons with fsat
When most of these patterns were created, we believed, incorrectly, that
fsat(NaN) was NaN. We have since realized that fsat(NaN) is zero.
Originally, this changed the patterns to use is_a_number. This didn't
help any shaders, so it's easier to just drop the optimizations.
This commit crossed paths with 4c3ad4d0658 ("nir/algebraic: mark more
optimization with fsat(NaN) as inexact") and bc123c396a9
("nir/algebraic: mark some optimizations with fsat(NaN) as inexact").
Given that these don't impact very many shaders, it seems safer to just
remove them.
As discussed in
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8716, I tried
modifying these patterns to use !(b cmp a). Unfortunately, on Intel
GPUs, the results were much worse than just removing the patterns
altogether.
Some other related patterns will be addressed in later commits.
There are still a number of patterns that use the identity fsat(1-X) ==
1 - fsat(X). If X is NaN, the former is zero while the latter is 1.0.
I haven't evaluted these patterns yet. If changes are needed in these
patterns, it should be a separate commit anyway.
v2: Replace arrow `=>` with `->` in comments because the `=>` looks a
lot like `<=` comparison. Suggested by Rhys.
Fixes: 92b75c126bb ("nir/algebraic: Replace checks that a value is between (or not) [0, 1]")
Fixes: a7f0c57673d ("nir/algebraic: Eliminate useless fsat() on operand of comparison w/value in (0, 1)")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel hardware had similar results. (Ice Lake shown)
total instructions in shared programs: 20029060 -> 20029670 (<.01%)
instructions in affected programs: 69236 -> 69846 (0.88%)
helped: 0
HURT: 263
HURT stats (abs) min: 1 max: 20 x̄: 2.32 x̃: 1
HURT stats (rel) min: 0.30% max: 11.11% x̄: 1.35% x̃: 0.98%
95% mean confidence interval for instructions value: 1.86 2.78
95% mean confidence interval for instructions %-change: 1.18% 1.52%
Instructions are HURT.
total cycles in shared programs: 979821278 -> 979834425 (<.01%)
cycles in affected programs: 1476848 -> 1489995 (0.89%)
helped: 49
HURT: 204
helped stats (abs) min: 1 max: 812 x̄: 102.31 x̃: 20
helped stats (rel) min: 0.01% max: 21.43% x̄: 2.23% x̃: 0.52%
HURT stats (abs) min: 2 max: 2600 x̄: 89.02 x̃: 16
HURT stats (rel) min: 0.04% max: 27.27% x̄: 1.49% x̃: 0.72%
95% mean confidence interval for cycles value: 13.18 90.75
95% mean confidence interval for cycles %-change: 0.29% 1.25%
Cycles are HURT.
No fossil-db changes.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-05 18:38:52 +01:00
|
|
|
|
|
|
|
# 0 < fsat(NaN) -> 0 < 0 -> false, and 0 < NaN -> false.
|
2019-03-05 22:54:35 +00:00
|
|
|
(('flt', 0.0, ('fsat(is_used_once)', a)), ('flt', 0.0, a)),
|
|
|
|
|
2016-03-02 23:18:34 +00:00
|
|
|
# 0.0 >= b2f(a)
|
|
|
|
# b2f(a) <= 0.0
|
|
|
|
# b2f(a) == 0.0 because b2f(a) can only be 0 or 1
|
|
|
|
# inot(a)
|
2018-12-06 03:36:10 +00:00
|
|
|
(('fge', 0.0, ('b2f', 'a@1')), ('inot', a)),
|
|
|
|
|
|
|
|
(('fge', ('fneg', ('b2f', 'a@1')), 0.0), ('inot', a)),
|
|
|
|
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1')), 0.0), ('ior', a, b)),
|
|
|
|
(('fneu', ('bcsel', a, 1.0, ('b2f', 'b@1')) , 0.0), ('ior', a, b)),
|
|
|
|
(('fneu', ('b2f', 'a@1'), ('fneg', ('b2f', 'b@1'))), ('ior', a, b)),
|
|
|
|
(('fneu', ('fmul', ('b2f', 'a@1'), ('b2f', 'b@1')), 0.0), ('iand', a, b)),
|
|
|
|
(('fneu', ('bcsel', a, ('b2f', 'b@1'), 0.0) , 0.0), ('iand', a, b)),
|
|
|
|
(('fneu', ('fadd', ('b2f', 'a@1'), ('fneg', ('b2f', 'b@1'))), 0.0), ('ixor', a, b)),
|
|
|
|
(('fneu', ('b2f', 'a@1') , ('b2f', 'b@1') ), ('ixor', a, b)),
|
|
|
|
(('fneu', ('fneg', ('b2f', 'a@1')), ('fneg', ('b2f', 'b@1'))), ('ixor', a, b)),
|
2018-12-06 03:36:10 +00:00
|
|
|
(('feq', ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1')), 0.0), ('inot', ('ior', a, b))),
|
|
|
|
(('feq', ('bcsel', a, 1.0, ('b2f', 'b@1')) , 0.0), ('inot', ('ior', a, b))),
|
|
|
|
(('feq', ('b2f', 'a@1'), ('fneg', ('b2f', 'b@1'))), ('inot', ('ior', a, b))),
|
|
|
|
(('feq', ('fmul', ('b2f', 'a@1'), ('b2f', 'b@1')), 0.0), ('inot', ('iand', a, b))),
|
|
|
|
(('feq', ('bcsel', a, ('b2f', 'b@1'), 0.0) , 0.0), ('inot', ('iand', a, b))),
|
|
|
|
(('feq', ('fadd', ('b2f', 'a@1'), ('fneg', ('b2f', 'b@1'))), 0.0), ('ieq', a, b)),
|
|
|
|
(('feq', ('b2f', 'a@1') , ('b2f', 'b@1') ), ('ieq', a, b)),
|
|
|
|
(('feq', ('fneg', ('b2f', 'a@1')), ('fneg', ('b2f', 'b@1'))), ('ieq', a, b)),
|
2018-08-02 01:18:07 +01:00
|
|
|
|
|
|
|
# -(b2f(a) + b2f(b)) < 0
|
|
|
|
# 0 < b2f(a) + b2f(b)
|
|
|
|
# 0 != b2f(a) + b2f(b) b2f must be 0 or 1, so the sum is non-negative
|
|
|
|
# a || b
|
2018-12-06 03:36:10 +00:00
|
|
|
(('flt', ('fneg', ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1'))), 0.0), ('ior', a, b)),
|
|
|
|
(('flt', 0.0, ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1'))), ('ior', a, b)),
|
2018-08-02 01:18:07 +01:00
|
|
|
|
2018-08-02 03:27:01 +01:00
|
|
|
# -(b2f(a) + b2f(b)) >= 0
|
|
|
|
# 0 >= b2f(a) + b2f(b)
|
|
|
|
# 0 == b2f(a) + b2f(b) b2f must be 0 or 1, so the sum is non-negative
|
|
|
|
# !(a || b)
|
2018-12-06 03:36:10 +00:00
|
|
|
(('fge', ('fneg', ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1'))), 0.0), ('inot', ('ior', a, b))),
|
|
|
|
(('fge', 0.0, ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1'))), ('inot', ('ior', a, b))),
|
2018-08-02 03:27:01 +01:00
|
|
|
|
2018-12-18 06:29:26 +00:00
|
|
|
(('flt', a, ('fneg', a)), ('flt', a, 0.0)),
|
|
|
|
(('fge', a, ('fneg', a)), ('fge', a, 0.0)),
|
|
|
|
|
2018-08-02 01:18:07 +01:00
|
|
|
# Some optimizations (below) convert things like (a < b || c < b) into
|
|
|
|
# (min(a, c) < b). However, this interfers with the previous optimizations
|
|
|
|
# that try to remove comparisons with negated sums of b2f. This just
|
|
|
|
# breaks that apart.
|
2018-12-06 03:36:10 +00:00
|
|
|
(('flt', ('fmin', c, ('fneg', ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1')))), 0.0),
|
2018-08-02 01:18:07 +01:00
|
|
|
('ior', ('flt', c, 0.0), ('ior', a, b))),
|
|
|
|
|
2018-02-13 02:58:53 +00:00
|
|
|
(('~flt', ('fadd', a, b), a), ('flt', b, 0.0)),
|
|
|
|
(('~fge', ('fadd', a, b), a), ('fge', b, 0.0)),
|
|
|
|
(('~feq', ('fadd', a, b), a), ('feq', b, 0.0)),
|
2020-08-18 18:51:57 +01:00
|
|
|
(('~fneu', ('fadd', a, b), a), ('fneu', b, 0.0)),
|
2018-02-14 01:44:00 +00:00
|
|
|
(('~flt', ('fadd(is_used_once)', a, '#b'), '#c'), ('flt', a, ('fadd', c, ('fneg', b)))),
|
|
|
|
(('~flt', ('fneg(is_used_once)', ('fadd(is_used_once)', a, '#b')), '#c'), ('flt', ('fneg', ('fadd', c, b)), a)),
|
|
|
|
(('~fge', ('fadd(is_used_once)', a, '#b'), '#c'), ('fge', a, ('fadd', c, ('fneg', b)))),
|
|
|
|
(('~fge', ('fneg(is_used_once)', ('fadd(is_used_once)', a, '#b')), '#c'), ('fge', ('fneg', ('fadd', c, b)), a)),
|
|
|
|
(('~feq', ('fadd(is_used_once)', a, '#b'), '#c'), ('feq', a, ('fadd', c, ('fneg', b)))),
|
|
|
|
(('~feq', ('fneg(is_used_once)', ('fadd(is_used_once)', a, '#b')), '#c'), ('feq', ('fneg', ('fadd', c, b)), a)),
|
2020-08-18 18:51:57 +01:00
|
|
|
(('~fneu', ('fadd(is_used_once)', a, '#b'), '#c'), ('fneu', a, ('fadd', c, ('fneg', b)))),
|
|
|
|
(('~fneu', ('fneg(is_used_once)', ('fadd(is_used_once)', a, '#b')), '#c'), ('fneu', ('fneg', ('fadd', c, b)), a)),
|
2018-02-13 02:58:53 +00:00
|
|
|
|
|
|
|
# Cannot remove the addition from ilt or ige due to overflow.
|
|
|
|
(('ieq', ('iadd', a, b), a), ('ieq', b, 0)),
|
|
|
|
(('ine', ('iadd', a, b), a), ('ine', b, 0)),
|
|
|
|
|
2018-12-06 03:36:10 +00:00
|
|
|
(('feq', ('b2f', 'a@1'), 0.0), ('inot', a)),
|
2020-01-17 21:33:20 +00:00
|
|
|
(('fneu', ('b2f', 'a@1'), 0.0), a),
|
2018-12-06 03:36:10 +00:00
|
|
|
(('ieq', ('b2i', 'a@1'), 0), ('inot', a)),
|
|
|
|
(('ine', ('b2i', 'a@1'), 0), a),
|
2016-03-02 03:05:14 +00:00
|
|
|
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('u2f', a), 0.0), ('ine', a, 0)),
|
2018-11-07 23:32:32 +00:00
|
|
|
(('feq', ('u2f', a), 0.0), ('ieq', a, 0)),
|
|
|
|
(('fge', ('u2f', a), 0.0), True),
|
|
|
|
(('fge', 0.0, ('u2f', a)), ('uge', 0, a)), # ieq instead?
|
|
|
|
(('flt', ('u2f', a), 0.0), False),
|
|
|
|
(('flt', 0.0, ('u2f', a)), ('ult', 0, a)), # ine instead?
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('i2f', a), 0.0), ('ine', a, 0)),
|
2018-11-07 23:32:32 +00:00
|
|
|
(('feq', ('i2f', a), 0.0), ('ieq', a, 0)),
|
|
|
|
(('fge', ('i2f', a), 0.0), ('ige', a, 0)),
|
|
|
|
(('fge', 0.0, ('i2f', a)), ('ige', 0, a)),
|
|
|
|
(('flt', ('i2f', a), 0.0), ('ilt', a, 0)),
|
|
|
|
(('flt', 0.0, ('i2f', a)), ('ilt', 0, a)),
|
2018-07-03 20:39:54 +01:00
|
|
|
|
2016-03-02 23:36:14 +00:00
|
|
|
# 0.0 < fabs(a)
|
|
|
|
# fabs(a) > 0.0
|
|
|
|
# fabs(a) != 0.0 because fabs(a) must be >= 0
|
|
|
|
# a != 0.0
|
2020-08-18 18:51:57 +01:00
|
|
|
(('~flt', 0.0, ('fabs', a)), ('fneu', a, 0.0)),
|
2016-03-02 23:36:14 +00:00
|
|
|
|
2018-07-27 02:26:18 +01:00
|
|
|
# -fabs(a) < 0.0
|
|
|
|
# fabs(a) > 0.0
|
2020-08-18 18:51:57 +01:00
|
|
|
(('~flt', ('fneg', ('fabs', a)), 0.0), ('fneu', a, 0.0)),
|
2018-07-27 02:26:18 +01:00
|
|
|
|
2018-08-02 03:46:26 +01:00
|
|
|
# 0.0 >= fabs(a)
|
|
|
|
# 0.0 == fabs(a) because fabs(a) must be >= 0
|
|
|
|
# 0.0 == a
|
|
|
|
(('fge', 0.0, ('fabs', a)), ('feq', a, 0.0)),
|
|
|
|
|
|
|
|
# -fabs(a) >= 0.0
|
|
|
|
# 0.0 >= fabs(a)
|
|
|
|
(('fge', ('fneg', ('fabs', a)), 0.0), ('feq', a, 0.0)),
|
|
|
|
|
2018-02-02 23:39:49 +00:00
|
|
|
# (a >= 0.0) && (a <= 1.0) -> fsat(a) == a
|
nir/algebraic: Remove some optimizations of comparisons with fsat
When most of these patterns were created, we believed, incorrectly, that
fsat(NaN) was NaN. We have since realized that fsat(NaN) is zero.
Originally, this changed the patterns to use is_a_number. This didn't
help any shaders, so it's easier to just drop the optimizations.
This commit crossed paths with 4c3ad4d0658 ("nir/algebraic: mark more
optimization with fsat(NaN) as inexact") and bc123c396a9
("nir/algebraic: mark some optimizations with fsat(NaN) as inexact").
Given that these don't impact very many shaders, it seems safer to just
remove them.
As discussed in
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8716, I tried
modifying these patterns to use !(b cmp a). Unfortunately, on Intel
GPUs, the results were much worse than just removing the patterns
altogether.
Some other related patterns will be addressed in later commits.
There are still a number of patterns that use the identity fsat(1-X) ==
1 - fsat(X). If X is NaN, the former is zero while the latter is 1.0.
I haven't evaluted these patterns yet. If changes are needed in these
patterns, it should be a separate commit anyway.
v2: Replace arrow `=>` with `->` in comments because the `=>` looks a
lot like `<=` comparison. Suggested by Rhys.
Fixes: 92b75c126bb ("nir/algebraic: Replace checks that a value is between (or not) [0, 1]")
Fixes: a7f0c57673d ("nir/algebraic: Eliminate useless fsat() on operand of comparison w/value in (0, 1)")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel hardware had similar results. (Ice Lake shown)
total instructions in shared programs: 20029060 -> 20029670 (<.01%)
instructions in affected programs: 69236 -> 69846 (0.88%)
helped: 0
HURT: 263
HURT stats (abs) min: 1 max: 20 x̄: 2.32 x̃: 1
HURT stats (rel) min: 0.30% max: 11.11% x̄: 1.35% x̃: 0.98%
95% mean confidence interval for instructions value: 1.86 2.78
95% mean confidence interval for instructions %-change: 1.18% 1.52%
Instructions are HURT.
total cycles in shared programs: 979821278 -> 979834425 (<.01%)
cycles in affected programs: 1476848 -> 1489995 (0.89%)
helped: 49
HURT: 204
helped stats (abs) min: 1 max: 812 x̄: 102.31 x̃: 20
helped stats (rel) min: 0.01% max: 21.43% x̄: 2.23% x̃: 0.52%
HURT stats (abs) min: 2 max: 2600 x̄: 89.02 x̃: 16
HURT stats (rel) min: 0.04% max: 27.27% x̄: 1.49% x̃: 0.72%
95% mean confidence interval for cycles value: 13.18 90.75
95% mean confidence interval for cycles %-change: 0.29% 1.25%
Cycles are HURT.
No fossil-db changes.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-05 18:38:52 +01:00
|
|
|
#
|
|
|
|
# This should be NaN safe.
|
|
|
|
#
|
|
|
|
# NaN >= 0 && 1 >= NaN -> false && false -> false
|
|
|
|
#
|
|
|
|
# vs.
|
|
|
|
#
|
|
|
|
# NaN == fsat(NaN) -> NaN == 0 -> false
|
2018-02-02 23:39:49 +00:00
|
|
|
(('iand', ('fge', a, 0.0), ('fge', 1.0, a)), ('feq', a, ('fsat', a)), '!options->lower_fsat'),
|
|
|
|
|
nir/algebraic: Fix some min/max of b2f replacements
fmin(-A, -B) is -fmax(A, B), and fmax(-A, -B) is -fmin(A, B). Therefore
the logic joining A and B should toggle between ior and iand for the
negated versions.
At the very least, a shader from Euro Truck Simulator 2 in shader-db is
affected by this. The KIL instruction in the (ARB assembly) shader ends
up with the wrong logic. This is _probably_ the source of
https://gitlab.freedesktop.org/mesa/mesa/-/issues/1346.
That said, the issue mentions that Mesa 18.0.5 works, but commit
68420d8322c ("nir: Simplify min and max of b2f") was added in 17.3.
Moreover, I was not able to reproduce the error in the ETS2 shader from
shader-db from any Mesa commit near the time the original fd.o bugzilla
was submitted (December 2018). :shrug:
In fact, the current error in that shader starts with 9167324a86b
("nir/algebraic: Mark some logic-joined comparison reductions as
exact"). That's a bit of a red herring as 9167324a86b just sets off a
chain of replacements that eventually leads to the incorrect min/max of
b2f patterns fixed by this commit.
The other affected shaders in the shader-db results are from Cargo
Commander. These are also ARB assembly shaders.
I think any ARB assembly shader that uses the pattern
SLT r0, ...;
...
KIL -r0;
will suffer from issues related to this.
This change fixes the piglit
tests/spec/arb_fragment_program/kil-of-slt.shader_test test added in
https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/454.
shader-db results:
All Gen6+ platforms had similar result. (Ice Lake shown)
total instructions in shared programs: 20034604 -> 20034486 (<.01%)
instructions in affected programs: 3885 -> 3767 (-3.04%)
helped: 47
HURT: 2
helped stats (abs) min: 2 max: 4 x̄: 2.64 x̃: 2
helped stats (rel) min: 2.33% max: 8.33% x̄: 3.48% x̃: 3.39%
HURT stats (abs) min: 3 max: 3 x̄: 3.00 x̃: 3
HURT stats (rel) min: 13.64% max: 16.67% x̄: 15.15% x̃: 15.15%
95% mean confidence interval for instructions value: -2.83 -1.99
95% mean confidence interval for instructions %-change: -3.84% -1.60%
Instructions are helped.
total cycles in shared programs: 979881379 -> 979879406 (<.01%)
cycles in affected programs: 119873 -> 117900 (-1.65%)
helped: 46
HURT: 3
helped stats (abs) min: 10 max: 756 x̄: 45.41 x̃: 26
helped stats (rel) min: 0.53% max: 19.72% x̄: 1.67% x̃: 1.26%
HURT stats (abs) min: 28 max: 56 x̄: 38.67 x̃: 32
HURT stats (rel) min: 1.44% max: 3.54% x̄: 2.75% x̃: 3.27%
95% mean confidence interval for cycles value: -70.83 -9.70
95% mean confidence interval for cycles %-change: -2.23% -0.57%
Cycles are helped.
Iron Lake and GM45 had similar results. (Iron Lake shown)
total instructions in shared programs: 8115098 -> 8115076 (<.01%)
instructions in affected programs: 2592 -> 2570 (-0.85%)
helped: 32
HURT: 2
helped stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
helped stats (rel) min: 0.88% max: 2.70% x̄: 1.35% x̃: 1.31%
HURT stats (abs) min: 5 max: 5 x̄: 5.00 x̃: 5
HURT stats (rel) min: 17.24% max: 18.52% x̄: 17.88% x̃: 17.88%
95% mean confidence interval for instructions value: -1.15 -0.15
95% mean confidence interval for instructions %-change: -1.83% 1.39%
Inconclusive result (%-change mean confidence interval includes 0).
total cycles in shared programs: 238189718 -> 238189802 (<.01%)
cycles in affected programs: 75076 -> 75160 (0.11%)
helped: 3
HURT: 31
helped stats (abs) min: 2 max: 130 x̄: 44.67 x̃: 2
helped stats (rel) min: 0.18% max: 5.70% x̄: 2.02% x̃: 0.19%
HURT stats (abs) min: 2 max: 70 x̄: 7.03 x̃: 4
HURT stats (rel) min: 0.07% max: 6.41% x̄: 0.53% x̃: 0.15%
95% mean confidence interval for cycles value: -7.27 12.21
95% mean confidence interval for cycles %-change: -0.33% 0.94%
Inconclusive result (value mean confidence interval includes 0).
No fossil-db changes on any Intel platform.
Fixes: 68420d8322c ("nir: Simplify min and max of b2f")
Closes: #1346
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9122>
2021-01-12 20:23:16 +00:00
|
|
|
# Note: fmin(-a, -b) == -fmax(a, b)
|
2018-12-06 03:36:10 +00:00
|
|
|
(('fmax', ('b2f(is_used_once)', 'a@1'), ('b2f', 'b@1')), ('b2f', ('ior', a, b))),
|
nir/algebraic: Fix some min/max of b2f replacements
fmin(-A, -B) is -fmax(A, B), and fmax(-A, -B) is -fmin(A, B). Therefore
the logic joining A and B should toggle between ior and iand for the
negated versions.
At the very least, a shader from Euro Truck Simulator 2 in shader-db is
affected by this. The KIL instruction in the (ARB assembly) shader ends
up with the wrong logic. This is _probably_ the source of
https://gitlab.freedesktop.org/mesa/mesa/-/issues/1346.
That said, the issue mentions that Mesa 18.0.5 works, but commit
68420d8322c ("nir: Simplify min and max of b2f") was added in 17.3.
Moreover, I was not able to reproduce the error in the ETS2 shader from
shader-db from any Mesa commit near the time the original fd.o bugzilla
was submitted (December 2018). :shrug:
In fact, the current error in that shader starts with 9167324a86b
("nir/algebraic: Mark some logic-joined comparison reductions as
exact"). That's a bit of a red herring as 9167324a86b just sets off a
chain of replacements that eventually leads to the incorrect min/max of
b2f patterns fixed by this commit.
The other affected shaders in the shader-db results are from Cargo
Commander. These are also ARB assembly shaders.
I think any ARB assembly shader that uses the pattern
SLT r0, ...;
...
KIL -r0;
will suffer from issues related to this.
This change fixes the piglit
tests/spec/arb_fragment_program/kil-of-slt.shader_test test added in
https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/454.
shader-db results:
All Gen6+ platforms had similar result. (Ice Lake shown)
total instructions in shared programs: 20034604 -> 20034486 (<.01%)
instructions in affected programs: 3885 -> 3767 (-3.04%)
helped: 47
HURT: 2
helped stats (abs) min: 2 max: 4 x̄: 2.64 x̃: 2
helped stats (rel) min: 2.33% max: 8.33% x̄: 3.48% x̃: 3.39%
HURT stats (abs) min: 3 max: 3 x̄: 3.00 x̃: 3
HURT stats (rel) min: 13.64% max: 16.67% x̄: 15.15% x̃: 15.15%
95% mean confidence interval for instructions value: -2.83 -1.99
95% mean confidence interval for instructions %-change: -3.84% -1.60%
Instructions are helped.
total cycles in shared programs: 979881379 -> 979879406 (<.01%)
cycles in affected programs: 119873 -> 117900 (-1.65%)
helped: 46
HURT: 3
helped stats (abs) min: 10 max: 756 x̄: 45.41 x̃: 26
helped stats (rel) min: 0.53% max: 19.72% x̄: 1.67% x̃: 1.26%
HURT stats (abs) min: 28 max: 56 x̄: 38.67 x̃: 32
HURT stats (rel) min: 1.44% max: 3.54% x̄: 2.75% x̃: 3.27%
95% mean confidence interval for cycles value: -70.83 -9.70
95% mean confidence interval for cycles %-change: -2.23% -0.57%
Cycles are helped.
Iron Lake and GM45 had similar results. (Iron Lake shown)
total instructions in shared programs: 8115098 -> 8115076 (<.01%)
instructions in affected programs: 2592 -> 2570 (-0.85%)
helped: 32
HURT: 2
helped stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
helped stats (rel) min: 0.88% max: 2.70% x̄: 1.35% x̃: 1.31%
HURT stats (abs) min: 5 max: 5 x̄: 5.00 x̃: 5
HURT stats (rel) min: 17.24% max: 18.52% x̄: 17.88% x̃: 17.88%
95% mean confidence interval for instructions value: -1.15 -0.15
95% mean confidence interval for instructions %-change: -1.83% 1.39%
Inconclusive result (%-change mean confidence interval includes 0).
total cycles in shared programs: 238189718 -> 238189802 (<.01%)
cycles in affected programs: 75076 -> 75160 (0.11%)
helped: 3
HURT: 31
helped stats (abs) min: 2 max: 130 x̄: 44.67 x̃: 2
helped stats (rel) min: 0.18% max: 5.70% x̄: 2.02% x̃: 0.19%
HURT stats (abs) min: 2 max: 70 x̄: 7.03 x̃: 4
HURT stats (rel) min: 0.07% max: 6.41% x̄: 0.53% x̃: 0.15%
95% mean confidence interval for cycles value: -7.27 12.21
95% mean confidence interval for cycles %-change: -0.33% 0.94%
Inconclusive result (value mean confidence interval includes 0).
No fossil-db changes on any Intel platform.
Fixes: 68420d8322c ("nir: Simplify min and max of b2f")
Closes: #1346
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9122>
2021-01-12 20:23:16 +00:00
|
|
|
(('fmax', ('fneg(is_used_once)', ('b2f(is_used_once)', 'a@1')), ('fneg', ('b2f', 'b@1'))), ('fneg', ('b2f', ('iand', a, b)))),
|
2018-12-06 03:36:10 +00:00
|
|
|
(('fmin', ('b2f(is_used_once)', 'a@1'), ('b2f', 'b@1')), ('b2f', ('iand', a, b))),
|
nir/algebraic: Fix some min/max of b2f replacements
fmin(-A, -B) is -fmax(A, B), and fmax(-A, -B) is -fmin(A, B). Therefore
the logic joining A and B should toggle between ior and iand for the
negated versions.
At the very least, a shader from Euro Truck Simulator 2 in shader-db is
affected by this. The KIL instruction in the (ARB assembly) shader ends
up with the wrong logic. This is _probably_ the source of
https://gitlab.freedesktop.org/mesa/mesa/-/issues/1346.
That said, the issue mentions that Mesa 18.0.5 works, but commit
68420d8322c ("nir: Simplify min and max of b2f") was added in 17.3.
Moreover, I was not able to reproduce the error in the ETS2 shader from
shader-db from any Mesa commit near the time the original fd.o bugzilla
was submitted (December 2018). :shrug:
In fact, the current error in that shader starts with 9167324a86b
("nir/algebraic: Mark some logic-joined comparison reductions as
exact"). That's a bit of a red herring as 9167324a86b just sets off a
chain of replacements that eventually leads to the incorrect min/max of
b2f patterns fixed by this commit.
The other affected shaders in the shader-db results are from Cargo
Commander. These are also ARB assembly shaders.
I think any ARB assembly shader that uses the pattern
SLT r0, ...;
...
KIL -r0;
will suffer from issues related to this.
This change fixes the piglit
tests/spec/arb_fragment_program/kil-of-slt.shader_test test added in
https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/454.
shader-db results:
All Gen6+ platforms had similar result. (Ice Lake shown)
total instructions in shared programs: 20034604 -> 20034486 (<.01%)
instructions in affected programs: 3885 -> 3767 (-3.04%)
helped: 47
HURT: 2
helped stats (abs) min: 2 max: 4 x̄: 2.64 x̃: 2
helped stats (rel) min: 2.33% max: 8.33% x̄: 3.48% x̃: 3.39%
HURT stats (abs) min: 3 max: 3 x̄: 3.00 x̃: 3
HURT stats (rel) min: 13.64% max: 16.67% x̄: 15.15% x̃: 15.15%
95% mean confidence interval for instructions value: -2.83 -1.99
95% mean confidence interval for instructions %-change: -3.84% -1.60%
Instructions are helped.
total cycles in shared programs: 979881379 -> 979879406 (<.01%)
cycles in affected programs: 119873 -> 117900 (-1.65%)
helped: 46
HURT: 3
helped stats (abs) min: 10 max: 756 x̄: 45.41 x̃: 26
helped stats (rel) min: 0.53% max: 19.72% x̄: 1.67% x̃: 1.26%
HURT stats (abs) min: 28 max: 56 x̄: 38.67 x̃: 32
HURT stats (rel) min: 1.44% max: 3.54% x̄: 2.75% x̃: 3.27%
95% mean confidence interval for cycles value: -70.83 -9.70
95% mean confidence interval for cycles %-change: -2.23% -0.57%
Cycles are helped.
Iron Lake and GM45 had similar results. (Iron Lake shown)
total instructions in shared programs: 8115098 -> 8115076 (<.01%)
instructions in affected programs: 2592 -> 2570 (-0.85%)
helped: 32
HURT: 2
helped stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
helped stats (rel) min: 0.88% max: 2.70% x̄: 1.35% x̃: 1.31%
HURT stats (abs) min: 5 max: 5 x̄: 5.00 x̃: 5
HURT stats (rel) min: 17.24% max: 18.52% x̄: 17.88% x̃: 17.88%
95% mean confidence interval for instructions value: -1.15 -0.15
95% mean confidence interval for instructions %-change: -1.83% 1.39%
Inconclusive result (%-change mean confidence interval includes 0).
total cycles in shared programs: 238189718 -> 238189802 (<.01%)
cycles in affected programs: 75076 -> 75160 (0.11%)
helped: 3
HURT: 31
helped stats (abs) min: 2 max: 130 x̄: 44.67 x̃: 2
helped stats (rel) min: 0.18% max: 5.70% x̄: 2.02% x̃: 0.19%
HURT stats (abs) min: 2 max: 70 x̄: 7.03 x̃: 4
HURT stats (rel) min: 0.07% max: 6.41% x̄: 0.53% x̃: 0.15%
95% mean confidence interval for cycles value: -7.27 12.21
95% mean confidence interval for cycles %-change: -0.33% 0.94%
Inconclusive result (value mean confidence interval includes 0).
No fossil-db changes on any Intel platform.
Fixes: 68420d8322c ("nir: Simplify min and max of b2f")
Closes: #1346
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9122>
2021-01-12 20:23:16 +00:00
|
|
|
(('fmin', ('fneg(is_used_once)', ('b2f(is_used_once)', 'a@1')), ('fneg', ('b2f', 'b@1'))), ('fneg', ('b2f', ('ior', a, b)))),
|
2016-03-08 19:11:00 +00:00
|
|
|
|
2018-02-03 01:39:54 +00:00
|
|
|
# fmin(b2f(a), b)
|
|
|
|
# bcsel(a, fmin(b2f(a), b), fmin(b2f(a), b))
|
|
|
|
# bcsel(a, fmin(b2f(True), b), fmin(b2f(False), b))
|
|
|
|
# bcsel(a, fmin(1.0, b), fmin(0.0, b))
|
|
|
|
#
|
|
|
|
# Since b is a constant, constant folding will eliminate the fmin and the
|
|
|
|
# fmax. If b is > 1.0, the bcsel will be replaced with a b2f.
|
2018-12-06 03:36:10 +00:00
|
|
|
(('fmin', ('b2f', 'a@1'), '#b'), ('bcsel', a, ('fmin', b, 1.0), ('fmin', b, 0.0))),
|
2018-02-03 01:39:54 +00:00
|
|
|
|
2018-03-14 23:25:07 +00:00
|
|
|
(('flt', ('fadd(is_used_once)', a, ('fneg', b)), 0.0), ('flt', a, b)),
|
2017-01-12 06:01:03 +00:00
|
|
|
|
2014-12-12 19:13:10 +00:00
|
|
|
(('fge', ('fneg', ('fabs', a)), 0.0), ('feq', a, 0.0)),
|
2018-02-26 22:49:47 +00:00
|
|
|
(('~bcsel', ('flt', b, a), b, a), ('fmin', a, b)),
|
|
|
|
(('~bcsel', ('flt', a, b), b, a), ('fmax', a, b)),
|
2018-01-22 09:29:48 +00:00
|
|
|
(('~bcsel', ('fge', a, b), b, a), ('fmin', a, b)),
|
|
|
|
(('~bcsel', ('fge', b, a), b, a), ('fmax', a, b)),
|
2018-12-04 00:30:44 +00:00
|
|
|
(('bcsel', ('i2b', a), b, c), ('bcsel', ('ine', a, 0), b, c)),
|
2016-08-17 23:03:01 +01:00
|
|
|
(('bcsel', ('inot', a), b, c), ('bcsel', a, c, b)),
|
2015-02-20 09:20:34 +00:00
|
|
|
(('bcsel', a, ('bcsel', a, b, c), d), ('bcsel', a, b, d)),
|
2018-08-01 17:58:19 +01:00
|
|
|
(('bcsel', a, b, ('bcsel', a, c, d)), ('bcsel', a, b, d)),
|
2018-08-02 00:51:35 +01:00
|
|
|
(('bcsel', a, ('bcsel', b, c, d), ('bcsel(is_used_once)', b, c, 'e')), ('bcsel', b, c, ('bcsel', a, d, 'e'))),
|
|
|
|
(('bcsel', a, ('bcsel(is_used_once)', b, c, d), ('bcsel', b, c, 'e')), ('bcsel', b, c, ('bcsel', a, d, 'e'))),
|
|
|
|
(('bcsel', a, ('bcsel', b, c, d), ('bcsel(is_used_once)', b, 'e', d)), ('bcsel', b, ('bcsel', a, c, 'e'), d)),
|
|
|
|
(('bcsel', a, ('bcsel(is_used_once)', b, c, d), ('bcsel', b, 'e', d)), ('bcsel', b, ('bcsel', a, c, 'e'), d)),
|
2019-03-30 03:51:20 +00:00
|
|
|
(('bcsel', a, True, b), ('ior', a, b)),
|
2019-03-29 22:12:47 +00:00
|
|
|
(('bcsel', a, a, b), ('ior', a, b)),
|
|
|
|
(('bcsel', a, b, False), ('iand', a, b)),
|
|
|
|
(('bcsel', a, b, a), ('iand', a, b)),
|
2019-04-23 14:54:24 +01:00
|
|
|
(('~fmin', a, a), a),
|
|
|
|
(('~fmax', a, a), a),
|
2015-05-06 04:20:30 +01:00
|
|
|
(('imin', a, a), a),
|
|
|
|
(('imax', a, a), a),
|
|
|
|
(('umin', a, a), a),
|
2021-05-02 22:48:05 +01:00
|
|
|
(('umin', a, 0), 0),
|
|
|
|
(('umin', a, -1), a),
|
2015-05-06 04:20:30 +01:00
|
|
|
(('umax', a, a), a),
|
2021-05-02 22:48:05 +01:00
|
|
|
(('umax', a, 0), a),
|
|
|
|
(('umax', a, -1), -1),
|
2018-08-15 10:29:42 +01:00
|
|
|
(('fmax', ('fmax', a, b), b), ('fmax', a, b)),
|
|
|
|
(('umax', ('umax', a, b), b), ('umax', a, b)),
|
|
|
|
(('imax', ('imax', a, b), b), ('imax', a, b)),
|
|
|
|
(('fmin', ('fmin', a, b), b), ('fmin', a, b)),
|
|
|
|
(('umin', ('umin', a, b), b), ('umin', a, b)),
|
|
|
|
(('imin', ('imin', a, b), b), ('imin', a, b)),
|
2021-01-12 22:15:46 +00:00
|
|
|
(('fmax', ('fmax', ('fmax', a, b), c), a), ('fmax', ('fmax', a, b), c)),
|
|
|
|
(('umax', ('umax', ('umax', a, b), c), a), ('umax', ('umax', a, b), c)),
|
|
|
|
(('imax', ('imax', ('imax', a, b), c), a), ('imax', ('imax', a, b), c)),
|
|
|
|
(('fmin', ('fmin', ('fmin', a, b), c), a), ('fmin', ('fmin', a, b), c)),
|
|
|
|
(('umin', ('umin', ('umin', a, b), c), a), ('umin', ('umin', a, b), c)),
|
|
|
|
(('imin', ('imin', ('imin', a, b), c), a), ('imin', ('imin', a, b), c)),
|
2020-09-01 07:20:34 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
# Integer sizes
|
|
|
|
for s in [8, 16, 32, 64]:
|
|
|
|
optimizations.extend([
|
|
|
|
(('iand@{}'.format(s), a, ('inot', ('ishr', a, s - 1))), ('imax', a, 0)),
|
|
|
|
|
|
|
|
# Simplify logic to detect sign of an integer.
|
|
|
|
(('ieq', ('iand', 'a@{}'.format(s), 1 << (s - 1)), 0), ('ige', a, 0)),
|
|
|
|
(('ine', ('iand', 'a@{}'.format(s), 1 << (s - 1)), 1 << (s - 1)), ('ige', a, 0)),
|
|
|
|
(('ine', ('iand', 'a@{}'.format(s), 1 << (s - 1)), 0), ('ilt', a, 0)),
|
|
|
|
(('ieq', ('iand', 'a@{}'.format(s), 1 << (s - 1)), 1 << (s - 1)), ('ilt', a, 0)),
|
|
|
|
(('ine', ('ushr', 'a@{}'.format(s), s - 1), 0), ('ilt', a, 0)),
|
|
|
|
(('ieq', ('ushr', 'a@{}'.format(s), s - 1), 0), ('ige', a, 0)),
|
|
|
|
(('ieq', ('ushr', 'a@{}'.format(s), s - 1), 1), ('ilt', a, 0)),
|
|
|
|
(('ine', ('ushr', 'a@{}'.format(s), s - 1), 1), ('ige', a, 0)),
|
|
|
|
(('ine', ('ishr', 'a@{}'.format(s), s - 1), 0), ('ilt', a, 0)),
|
|
|
|
(('ieq', ('ishr', 'a@{}'.format(s), s - 1), 0), ('ige', a, 0)),
|
|
|
|
(('ieq', ('ishr', 'a@{}'.format(s), s - 1), -1), ('ilt', a, 0)),
|
|
|
|
(('ine', ('ishr', 'a@{}'.format(s), s - 1), -1), ('ige', a, 0)),
|
|
|
|
])
|
2020-03-03 18:51:59 +00:00
|
|
|
|
2020-09-01 07:20:34 +01:00
|
|
|
optimizations.extend([
|
2017-01-18 11:23:22 +00:00
|
|
|
(('fmin', a, ('fneg', a)), ('fneg', ('fabs', a))),
|
|
|
|
(('imin', a, ('ineg', a)), ('ineg', ('iabs', a))),
|
|
|
|
(('fmin', a, ('fneg', ('fabs', a))), ('fneg', ('fabs', a))),
|
|
|
|
(('imin', a, ('ineg', ('iabs', a))), ('ineg', ('iabs', a))),
|
2019-04-23 14:54:24 +01:00
|
|
|
(('~fmin', a, ('fabs', a)), a),
|
2017-01-18 11:23:22 +00:00
|
|
|
(('imin', a, ('iabs', a)), a),
|
2019-04-23 14:54:24 +01:00
|
|
|
(('~fmax', a, ('fneg', ('fabs', a))), a),
|
2017-01-18 11:23:22 +00:00
|
|
|
(('imax', a, ('ineg', ('iabs', a))), a),
|
|
|
|
(('fmax', a, ('fabs', a)), ('fabs', a)),
|
|
|
|
(('imax', a, ('iabs', a)), ('iabs', a)),
|
|
|
|
(('fmax', a, ('fneg', a)), ('fabs', a)),
|
2020-01-10 21:59:54 +00:00
|
|
|
(('imax', a, ('ineg', a)), ('iabs', a), '!options->lower_iabs'),
|
2019-06-04 20:54:12 +01:00
|
|
|
(('~fmax', ('fabs', a), 0.0), ('fabs', a)),
|
2020-02-03 21:19:52 +00:00
|
|
|
(('fmin', ('fmax', a, 0.0), 1.0), ('fsat', a), '!options->lower_fsat'),
|
|
|
|
# fmax(fmin(a, 1.0), 0.0) is inexact because it returns 1.0 on NaN, while
|
|
|
|
# fsat(a) returns 0.0.
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fmax', ('fmin', a, 1.0), 0.0), ('fsat', a), '!options->lower_fsat'),
|
2020-02-03 21:19:52 +00:00
|
|
|
# fmin(fmax(a, -1.0), 0.0) is inexact because it returns -1.0 on NaN, while
|
|
|
|
# fneg(fsat(fneg(a))) returns -0.0 on NaN.
|
2019-09-25 15:20:09 +01:00
|
|
|
(('~fmin', ('fmax', a, -1.0), 0.0), ('fneg', ('fsat', ('fneg', a))), '!options->lower_fsat'),
|
2020-02-03 21:19:52 +00:00
|
|
|
# fmax(fmin(a, 0.0), -1.0) is inexact because it returns 0.0 on NaN, while
|
|
|
|
# fneg(fsat(fneg(a))) returns -0.0 on NaN. This only matters if
|
|
|
|
# SignedZeroInfNanPreserve is set, but we don't currently have any way of
|
|
|
|
# representing this in the optimizations other than the usual ~.
|
2019-09-25 15:20:09 +01:00
|
|
|
(('~fmax', ('fmin', a, 0.0), -1.0), ('fneg', ('fsat', ('fneg', a))), '!options->lower_fsat'),
|
nir/algebraic: Mark comparisons generated from lowered fsign precise
This prevents other transformations from converting them to 'a != 0'.
For example, both of these transformations can do this:
(('~flt', 0.0, ('fabs', a)), ('fne', a, 0.0)),
(('~flt', ('fneg', ('fabs', a)), 0.0), ('fne', a, 0.0)),
Both fsign(fabs(NaN)) and fsign(fneg(fabs(NaN))) should produce zero,
but, since 'NaN != 0.0' is true, cascading these transformations could
cause them to generate 1.0 or -1.0 respecively.
No shader-db or fossil-db changes on any Intel platform.
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6358>
2020-02-19 20:47:21 +00:00
|
|
|
# fsat(fsign(NaN)) = fsat(0) = 0, and b2f(0 < NaN) = b2f(False) = 0. Mark
|
|
|
|
# the new comparison precise to prevent it being changed to 'a != 0'.
|
|
|
|
(('fsat', ('fsign', a)), ('b2f', ('!flt', 0.0, a))),
|
2019-03-01 22:41:59 +00:00
|
|
|
(('fsat', ('b2f', a)), ('b2f', a)),
|
2015-01-30 21:53:39 +00:00
|
|
|
(('fsat', a), ('fmin', ('fmax', a, 0.0), 1.0), 'options->lower_fsat'),
|
2015-01-30 22:10:58 +00:00
|
|
|
(('fsat', ('fsat', a)), ('fsat', a)),
|
2019-09-25 15:20:09 +01:00
|
|
|
(('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'),
|
2018-10-23 22:30:41 +01:00
|
|
|
(('fsat', ('fabs(is_used_once)', ('fmul(is_used_once)', a, b))), ('fsat', ('fmul', ('fabs', a), ('fabs', b))), '!options->lower_fsat'),
|
2016-04-09 02:31:16 +01:00
|
|
|
(('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)),
|
|
|
|
(('umin', ('umax', ('umin', ('umax', a, b), c), b), c), ('umin', ('umax', a, b), c)),
|
2020-02-03 21:19:52 +00:00
|
|
|
# Both the left and right patterns are "b" when isnan(a), so this is exact.
|
2020-08-11 23:49:37 +01:00
|
|
|
(('fmax', ('fsat', a), '#b(is_zero_to_one)'), ('fsat', ('fmax', a, b))),
|
2020-02-03 21:19:52 +00:00
|
|
|
# The left pattern is 0.0 when isnan(a) (because fmin(fsat(NaN), b) ->
|
|
|
|
# fmin(0.0, b)) while the right one is "b", so this optimization is inexact.
|
2020-08-11 23:49:37 +01:00
|
|
|
(('~fmin', ('fsat', a), '#b(is_zero_to_one)'), ('fsat', ('fmin', a, b))),
|
2020-02-11 02:23:54 +00:00
|
|
|
|
|
|
|
# If a in [0,b] then b-a is also in [0,b]. Since b in [0,1], max(b-a, 0) =
|
|
|
|
# fsat(b-a).
|
|
|
|
#
|
|
|
|
# If a > b, then b-a < 0 and max(b-a, 0) = fsat(b-a) = 0
|
|
|
|
#
|
|
|
|
# This should be NaN safe since max(NaN, 0) = fsat(NaN) = 0.
|
2020-08-11 23:49:37 +01:00
|
|
|
(('fmax', ('fadd(is_used_once)', ('fneg', 'a(is_not_negative)'), '#b(is_zero_to_one)'), 0.0),
|
2020-02-11 02:23:54 +00:00
|
|
|
('fsat', ('fadd', ('fneg', a), b)), '!options->lower_fsat'),
|
|
|
|
|
2016-04-09 02:31:16 +01:00
|
|
|
(('extract_u8', ('imin', ('imax', a, 0), 0xff), 0), ('imin', ('imax', a, 0), 0xff)),
|
2020-07-08 20:53:07 +01:00
|
|
|
|
|
|
|
# The ior versions are exact because fmin and fmax will always pick a
|
|
|
|
# non-NaN value, if one exists. Therefore (a < NaN) || (a < c) == a <
|
|
|
|
# fmax(NaN, c) == a < c. Mark the fmin or fmax in the replacement as exact
|
|
|
|
# to prevent other optimizations from ruining the "NaN clensing" property
|
|
|
|
# of the fmin or fmax.
|
|
|
|
(('ior', ('flt(is_used_once)', a, b), ('flt', a, c)), ('flt', a, ('!fmax', b, c))),
|
|
|
|
(('ior', ('flt(is_used_once)', a, c), ('flt', b, c)), ('flt', ('!fmin', a, b), c)),
|
|
|
|
(('ior', ('fge(is_used_once)', a, b), ('fge', a, c)), ('fge', a, ('!fmin', b, c))),
|
|
|
|
(('ior', ('fge(is_used_once)', a, c), ('fge', b, c)), ('fge', ('!fmax', a, b), c)),
|
|
|
|
(('ior', ('flt', a, '#b'), ('flt', a, '#c')), ('flt', a, ('!fmax', b, c))),
|
|
|
|
(('ior', ('flt', '#a', c), ('flt', '#b', c)), ('flt', ('!fmin', a, b), c)),
|
|
|
|
(('ior', ('fge', a, '#b'), ('fge', a, '#c')), ('fge', a, ('!fmin', b, c))),
|
|
|
|
(('ior', ('fge', '#a', c), ('fge', '#b', c)), ('fge', ('!fmax', a, b), c)),
|
2018-01-04 23:21:30 +00:00
|
|
|
(('~iand', ('flt(is_used_once)', a, b), ('flt', a, c)), ('flt', a, ('fmin', b, c))),
|
|
|
|
(('~iand', ('flt(is_used_once)', a, c), ('flt', b, c)), ('flt', ('fmax', a, b), c)),
|
|
|
|
(('~iand', ('fge(is_used_once)', a, b), ('fge', a, c)), ('fge', a, ('fmax', b, c))),
|
|
|
|
(('~iand', ('fge(is_used_once)', a, c), ('fge', b, c)), ('fge', ('fmin', a, b), c)),
|
2021-01-29 02:15:26 +00:00
|
|
|
(('iand', ('flt', a, '#b(is_a_number)'), ('flt', a, '#c(is_a_number)')), ('flt', a, ('fmin', b, c))),
|
|
|
|
(('iand', ('flt', '#a(is_a_number)', c), ('flt', '#b(is_a_number)', c)), ('flt', ('fmax', a, b), c)),
|
|
|
|
(('iand', ('fge', a, '#b(is_a_number)'), ('fge', a, '#c(is_a_number)')), ('fge', a, ('fmax', b, c))),
|
|
|
|
(('iand', ('fge', '#a(is_a_number)', c), ('fge', '#b(is_a_number)', c)), ('fge', ('fmin', a, b), c)),
|
2018-01-04 21:30:49 +00:00
|
|
|
|
2018-01-05 21:20:46 +00:00
|
|
|
(('ior', ('ilt(is_used_once)', a, b), ('ilt', a, c)), ('ilt', a, ('imax', b, c))),
|
|
|
|
(('ior', ('ilt(is_used_once)', a, c), ('ilt', b, c)), ('ilt', ('imin', a, b), c)),
|
|
|
|
(('ior', ('ige(is_used_once)', a, b), ('ige', a, c)), ('ige', a, ('imin', b, c))),
|
|
|
|
(('ior', ('ige(is_used_once)', a, c), ('ige', b, c)), ('ige', ('imax', a, b), c)),
|
|
|
|
(('ior', ('ult(is_used_once)', a, b), ('ult', a, c)), ('ult', a, ('umax', b, c))),
|
|
|
|
(('ior', ('ult(is_used_once)', a, c), ('ult', b, c)), ('ult', ('umin', a, b), c)),
|
|
|
|
(('ior', ('uge(is_used_once)', a, b), ('uge', a, c)), ('uge', a, ('umin', b, c))),
|
|
|
|
(('ior', ('uge(is_used_once)', a, c), ('uge', b, c)), ('uge', ('umax', a, b), c)),
|
|
|
|
(('iand', ('ilt(is_used_once)', a, b), ('ilt', a, c)), ('ilt', a, ('imin', b, c))),
|
|
|
|
(('iand', ('ilt(is_used_once)', a, c), ('ilt', b, c)), ('ilt', ('imax', a, b), c)),
|
|
|
|
(('iand', ('ige(is_used_once)', a, b), ('ige', a, c)), ('ige', a, ('imax', b, c))),
|
|
|
|
(('iand', ('ige(is_used_once)', a, c), ('ige', b, c)), ('ige', ('imin', a, b), c)),
|
|
|
|
(('iand', ('ult(is_used_once)', a, b), ('ult', a, c)), ('ult', a, ('umin', b, c))),
|
|
|
|
(('iand', ('ult(is_used_once)', a, c), ('ult', b, c)), ('ult', ('umax', a, b), c)),
|
|
|
|
(('iand', ('uge(is_used_once)', a, b), ('uge', a, c)), ('uge', a, ('umax', b, c))),
|
|
|
|
(('iand', ('uge(is_used_once)', a, c), ('uge', b, c)), ('uge', ('umin', a, b), c)),
|
2020-08-17 23:26:07 +01:00
|
|
|
|
|
|
|
# A number of shaders contain a pattern like a.x < 0.0 || a.x > 1.0 || a.y
|
|
|
|
# < 0.0, || a.y > 1.0 || ... These patterns rearrange and replace in a
|
|
|
|
# single step. Doing just the replacement can lead to an infinite loop as
|
|
|
|
# the pattern is repeatedly applied to the result of the previous
|
|
|
|
# application of the pattern.
|
|
|
|
(('ior', ('ior(is_used_once)', ('flt(is_used_once)', a, c), d), ('flt', b, c)), ('ior', ('flt', ('!fmin', a, b), c), d)),
|
|
|
|
(('ior', ('ior(is_used_once)', ('flt', a, c), d), ('flt(is_used_once)', b, c)), ('ior', ('flt', ('!fmin', a, b), c), d)),
|
|
|
|
(('ior', ('ior(is_used_once)', ('flt(is_used_once)', a, b), d), ('flt', a, c)), ('ior', ('flt', a, ('!fmax', b, c)), d)),
|
|
|
|
(('ior', ('ior(is_used_once)', ('flt', a, b), d), ('flt(is_used_once)', a, c)), ('ior', ('flt', a, ('!fmax', b, c)), d)),
|
2020-09-01 07:20:34 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
# Float sizes
|
|
|
|
for s in [16, 32, 64]:
|
|
|
|
optimizations.extend([
|
|
|
|
# These derive from the previous patterns with the application of b < 0 <=>
|
|
|
|
# 0 < -b. The transformation should be applied if either comparison is
|
|
|
|
# used once as this ensures that the number of comparisons will not
|
|
|
|
# increase. The sources to the ior and iand are not symmetric, so the
|
|
|
|
# rules have to be duplicated to get this behavior.
|
2020-07-08 20:53:07 +01:00
|
|
|
(('ior', ('flt(is_used_once)', 0.0, 'a@{}'.format(s)), ('flt', 'b@{}'.format(s), 0.0)), ('flt', 0.0, ('fmax', a, ('fneg', b)))),
|
|
|
|
(('ior', ('flt', 0.0, 'a@{}'.format(s)), ('flt(is_used_once)', 'b@{}'.format(s), 0.0)), ('flt', 0.0, ('fmax', a, ('fneg', b)))),
|
|
|
|
(('ior', ('fge(is_used_once)', 0.0, 'a@{}'.format(s)), ('fge', 'b@{}'.format(s), 0.0)), ('fge', 0.0, ('fmin', a, ('fneg', b)))),
|
|
|
|
(('ior', ('fge', 0.0, 'a@{}'.format(s)), ('fge(is_used_once)', 'b@{}'.format(s), 0.0)), ('fge', 0.0, ('fmin', a, ('fneg', b)))),
|
2020-09-01 07:20:34 +01:00
|
|
|
(('~iand', ('flt(is_used_once)', 0.0, 'a@{}'.format(s)), ('flt', 'b@{}'.format(s), 0.0)), ('flt', 0.0, ('fmin', a, ('fneg', b)))),
|
|
|
|
(('~iand', ('flt', 0.0, 'a@{}'.format(s)), ('flt(is_used_once)', 'b@{}'.format(s), 0.0)), ('flt', 0.0, ('fmin', a, ('fneg', b)))),
|
|
|
|
(('~iand', ('fge(is_used_once)', 0.0, 'a@{}'.format(s)), ('fge', 'b@{}'.format(s), 0.0)), ('fge', 0.0, ('fmax', a, ('fneg', b)))),
|
|
|
|
(('~iand', ('fge', 0.0, 'a@{}'.format(s)), ('fge(is_used_once)', 'b@{}'.format(s), 0.0)), ('fge', 0.0, ('fmax', a, ('fneg', b)))),
|
|
|
|
|
2020-02-18 20:52:42 +00:00
|
|
|
# The (i2f32, ...) part is an open-coded fsign. When that is combined
|
|
|
|
# with the bcsel, it's basically copysign(1.0, a). There are some
|
|
|
|
# behavior differences between this pattern and copysign w.r.t. ±0 and
|
|
|
|
# NaN. copysign(x, y) blindly takes the sign bit from y and applies it
|
|
|
|
# to x, regardless of whether either or both values are NaN.
|
|
|
|
#
|
|
|
|
# If a != a: bcsel(False, 1.0, i2f(b2i(False) - b2i(False))) = 0,
|
|
|
|
# int(NaN >= 0.0) - int(NaN < 0.0) = 0 - 0 = 0
|
|
|
|
# If a == ±0: bcsel(True, 1.0, ...) = 1.0,
|
|
|
|
# int(±0.0 >= 0.0) - int(±0.0 < 0.0) = 1 - 0 = 1
|
|
|
|
#
|
|
|
|
# For all other values of 'a', the original and replacement behave as
|
|
|
|
# copysign.
|
nir: Make some notes about fsign versus NaN
This commit only documents the current behavior, even if that behavior
is not the behavior preferred by the relevant specs.
In SPIR-V, there are two flavors of the sign instruction, and each lives
in an extended instruction set. The GLSL.std.450 FSign instruction is
defined as:
Result is 1.0 if x > 0, 0.0 if x = 0, or -1.0 if x < 0.
This also matches the GLSL 4.60 definition.
However, the OpenCL.ExtendedInstructionSet.100 sign instruction is
defined as:
Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if
x < 0. Returns 0.0 if x is a NaN.
There are two differences. Each treats -0.0 differently, and each also
treats NaN differently. Specifically, GLSL.std.450 FSign does not
define any specific behavior for NaN.
There has been some discussion in Khronos about the NaN behavior of
GLSL.std.450 FSign. As part of that discussion, I did some research
into how we treat NaN for nir_op_fsign, and this commit just captures
some of those notes.
v2: Document the expected behavior of nir_op_fsign more thoroughly.
Suggested by Rhys. Note that the current implementation of constant
folding does not produce the expected result for NaN. Suggested by
Caio.
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> [v1]
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6358>
2020-02-18 18:18:57 +00:00
|
|
|
#
|
2020-02-18 20:52:42 +00:00
|
|
|
# Marking the replacement comparisons as precise prevents any future
|
|
|
|
# optimizations from replacing either of the comparisons with the
|
|
|
|
# logical-not of the other.
|
nir: Make some notes about fsign versus NaN
This commit only documents the current behavior, even if that behavior
is not the behavior preferred by the relevant specs.
In SPIR-V, there are two flavors of the sign instruction, and each lives
in an extended instruction set. The GLSL.std.450 FSign instruction is
defined as:
Result is 1.0 if x > 0, 0.0 if x = 0, or -1.0 if x < 0.
This also matches the GLSL 4.60 definition.
However, the OpenCL.ExtendedInstructionSet.100 sign instruction is
defined as:
Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if
x < 0. Returns 0.0 if x is a NaN.
There are two differences. Each treats -0.0 differently, and each also
treats NaN differently. Specifically, GLSL.std.450 FSign does not
define any specific behavior for NaN.
There has been some discussion in Khronos about the NaN behavior of
GLSL.std.450 FSign. As part of that discussion, I did some research
into how we treat NaN for nir_op_fsign, and this commit just captures
some of those notes.
v2: Document the expected behavior of nir_op_fsign more thoroughly.
Suggested by Rhys. Note that the current implementation of constant
folding does not produce the expected result for NaN. Suggested by
Caio.
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> [v1]
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6358>
2020-02-18 18:18:57 +00:00
|
|
|
#
|
2020-02-18 20:52:42 +00:00
|
|
|
# Note: Use b2i32 in the replacement because some platforms that
|
|
|
|
# support fp16 don't support int16.
|
2020-09-01 07:20:34 +01:00
|
|
|
(('bcsel@{}'.format(s), ('feq', a, 0.0), 1.0, ('i2f{}'.format(s), ('iadd', ('b2i{}'.format(s), ('flt', 0.0, 'a@{}'.format(s))), ('ineg', ('b2i{}'.format(s), ('flt', 'a@{}'.format(s), 0.0)))))),
|
2020-02-18 20:52:42 +00:00
|
|
|
('i2f{}'.format(s), ('iadd', ('b2i32', ('!fge', a, 0.0)), ('ineg', ('b2i32', ('!flt', a, 0.0)))))),
|
2020-09-01 07:20:34 +01:00
|
|
|
|
|
|
|
(('bcsel', a, ('b2f(is_used_once)', 'b@{}'.format(s)), ('b2f', 'c@{}'.format(s))), ('b2f', ('bcsel', a, b, c))),
|
|
|
|
|
|
|
|
# The C spec says, "If the value of the integral part cannot be represented
|
|
|
|
# by the integer type, the behavior is undefined." "Undefined" can mean
|
|
|
|
# "the conversion doesn't happen at all."
|
|
|
|
(('~i2f{}'.format(s), ('f2i', 'a@{}'.format(s))), ('ftrunc', a)),
|
|
|
|
|
|
|
|
# Ironically, mark these as imprecise because removing the conversions may
|
|
|
|
# preserve more precision than doing the conversions (e.g.,
|
|
|
|
# uint(float(0x81818181u)) == 0x81818200).
|
|
|
|
(('~f2i{}'.format(s), ('i2f', 'a@{}'.format(s))), a),
|
|
|
|
(('~f2i{}'.format(s), ('u2f', 'a@{}'.format(s))), a),
|
|
|
|
(('~f2u{}'.format(s), ('i2f', 'a@{}'.format(s))), a),
|
|
|
|
(('~f2u{}'.format(s), ('u2f', 'a@{}'.format(s))), a),
|
|
|
|
|
|
|
|
(('fadd', ('b2f{}'.format(s), ('flt', 0.0, 'a@{}'.format(s))), ('fneg', ('b2f{}'.format(s), ('flt', 'a@{}'.format(s), 0.0)))), ('fsign', a), '!options->lower_fsign'),
|
|
|
|
(('iadd', ('b2i{}'.format(s), ('flt', 0, 'a@{}'.format(s))), ('ineg', ('b2i{}'.format(s), ('flt', 'a@{}'.format(s), 0)))), ('f2i{}'.format(s), ('fsign', a)), '!options->lower_fsign'),
|
|
|
|
])
|
2018-01-05 21:20:46 +00:00
|
|
|
|
2020-09-04 06:48:35 +01:00
|
|
|
# float? -> float? -> floatS ==> float? -> floatS
|
|
|
|
(('~f2f{}'.format(s), ('f2f', a)), ('f2f{}'.format(s), a)),
|
|
|
|
|
|
|
|
# int? -> float? -> floatS ==> int? -> floatS
|
|
|
|
(('~f2f{}'.format(s), ('u2f', a)), ('u2f{}'.format(s), a)),
|
|
|
|
(('~f2f{}'.format(s), ('i2f', a)), ('i2f{}'.format(s), a)),
|
|
|
|
|
|
|
|
# float? -> float? -> intS ==> float? -> intS
|
|
|
|
(('~f2u{}'.format(s), ('f2f', a)), ('f2u{}'.format(s), a)),
|
|
|
|
(('~f2i{}'.format(s), ('f2f', a)), ('f2i{}'.format(s), a)),
|
|
|
|
|
|
|
|
for B in [32, 64]:
|
|
|
|
if s < B:
|
2020-09-01 07:20:34 +01:00
|
|
|
optimizations.extend([
|
2020-09-04 06:48:35 +01:00
|
|
|
# S = smaller, B = bigger
|
|
|
|
# typeS -> typeB -> typeS ==> identity
|
|
|
|
(('f2f{}'.format(s), ('f2f{}'.format(B), 'a@{}'.format(s))), a),
|
|
|
|
(('i2i{}'.format(s), ('i2i{}'.format(B), 'a@{}'.format(s))), a),
|
|
|
|
(('u2u{}'.format(s), ('u2u{}'.format(B), 'a@{}'.format(s))), a),
|
|
|
|
|
|
|
|
# bool1 -> typeB -> typeS ==> bool1 -> typeS
|
|
|
|
(('f2f{}'.format(s), ('b2f{}'.format(B), 'a@1')), ('b2f{}'.format(s), a)),
|
|
|
|
(('i2i{}'.format(s), ('b2i{}'.format(B), 'a@1')), ('b2i{}'.format(s), a)),
|
|
|
|
(('u2u{}'.format(s), ('b2i{}'.format(B), 'a@1')), ('b2i{}'.format(s), a)),
|
|
|
|
|
|
|
|
# floatS -> floatB -> intB ==> floatS -> intB
|
|
|
|
(('f2u{}'.format(B), ('f2f{}'.format(B), 'a@{}'.format(s))), ('f2u{}'.format(B), a)),
|
|
|
|
(('f2i{}'.format(B), ('f2f{}'.format(B), 'a@{}'.format(s))), ('f2i{}'.format(B), a)),
|
|
|
|
|
|
|
|
# int? -> floatB -> floatS ==> int? -> floatS
|
|
|
|
(('f2f{}'.format(s), ('u2f{}'.format(B), a)), ('u2f{}'.format(s), a)),
|
|
|
|
(('f2f{}'.format(s), ('i2f{}'.format(B), a)), ('i2f{}'.format(s), a)),
|
|
|
|
|
|
|
|
# intS -> intB -> floatB ==> intS -> floatB
|
|
|
|
(('u2f{}'.format(B), ('u2u{}'.format(B), 'a@{}'.format(s))), ('u2f{}'.format(B), a)),
|
|
|
|
(('i2f{}'.format(B), ('i2i{}'.format(B), 'a@{}'.format(s))), ('i2f{}'.format(B), a)),
|
2020-09-01 07:20:34 +01:00
|
|
|
])
|
|
|
|
|
2020-09-04 06:48:35 +01:00
|
|
|
# mediump variants of the above
|
|
|
|
optimizations.extend([
|
|
|
|
# int32 -> float32 -> float16 ==> int32 -> float16
|
|
|
|
(('f2fmp', ('u2f32', 'a@32')), ('u2fmp', a)),
|
|
|
|
(('f2fmp', ('i2f32', 'a@32')), ('i2fmp', a)),
|
|
|
|
|
|
|
|
# float32 -> float16 -> int16 ==> float32 -> int16
|
|
|
|
(('f2u16', ('f2fmp', 'a@32')), ('f2u16', a)),
|
|
|
|
(('f2i16', ('f2fmp', 'a@32')), ('f2i16', a)),
|
|
|
|
|
|
|
|
# float32 -> int32 -> int16 ==> float32 -> int16
|
|
|
|
(('i2imp', ('f2u32', 'a@32')), ('f2ump', a)),
|
|
|
|
(('i2imp', ('f2i32', 'a@32')), ('f2imp', a)),
|
|
|
|
|
|
|
|
# int32 -> int16 -> float16 ==> int32 -> float16
|
|
|
|
(('u2f16', ('i2imp', 'a@32')), ('u2f16', a)),
|
|
|
|
(('i2f16', ('i2imp', 'a@32')), ('i2f16', a)),
|
|
|
|
])
|
|
|
|
|
2020-09-01 07:20:34 +01:00
|
|
|
# Integer sizes
|
|
|
|
for s in [8, 16, 32, 64]:
|
|
|
|
optimizations.extend([
|
2020-10-09 17:33:26 +01:00
|
|
|
(('iand', ('ieq', 'a@{}'.format(s), 0), ('ieq', 'b@{}'.format(s), 0)), ('ieq', ('ior', a, b), 0), 'options->lower_umax'),
|
|
|
|
(('ior', ('ine', 'a@{}'.format(s), 0), ('ine', 'b@{}'.format(s), 0)), ('ine', ('ior', a, b), 0), 'options->lower_umin'),
|
|
|
|
(('iand', ('ieq', 'a@{}'.format(s), 0), ('ieq', 'b@{}'.format(s), 0)), ('ieq', ('umax', a, b), 0), '!options->lower_umax'),
|
|
|
|
(('ior', ('ieq', 'a@{}'.format(s), 0), ('ieq', 'b@{}'.format(s), 0)), ('ieq', ('umin', a, b), 0), '!options->lower_umin'),
|
|
|
|
(('iand', ('ine', 'a@{}'.format(s), 0), ('ine', 'b@{}'.format(s), 0)), ('ine', ('umin', a, b), 0), '!options->lower_umin'),
|
|
|
|
(('ior', ('ine', 'a@{}'.format(s), 0), ('ine', 'b@{}'.format(s), 0)), ('ine', ('umax', a, b), 0), '!options->lower_umax'),
|
2020-09-01 07:20:34 +01:00
|
|
|
|
|
|
|
# True/False are ~0 and 0 in NIR. b2i of True is 1, and -1 is ~0 (True).
|
|
|
|
(('ineg', ('b2i{}'.format(s), 'a@{}'.format(s))), a),
|
|
|
|
|
|
|
|
# SM5 32-bit shifts are defined to use the 5 least significant bits (or 4 bits for 16 bits)
|
|
|
|
(('ishl', 'a@{}'.format(s), ('iand', s - 1, b)), ('ishl', a, b)),
|
|
|
|
(('ishr', 'a@{}'.format(s), ('iand', s - 1, b)), ('ishr', a, b)),
|
|
|
|
(('ushr', 'a@{}'.format(s), ('iand', s - 1, b)), ('ushr', a, b)),
|
|
|
|
])
|
2019-03-21 21:52:58 +00:00
|
|
|
|
2020-09-01 07:20:34 +01:00
|
|
|
optimizations.extend([
|
2019-02-12 00:47:34 +00:00
|
|
|
# Common pattern like 'if (i == 0 || i == 1 || ...)'
|
|
|
|
(('ior', ('ieq', a, 0), ('ieq', a, 1)), ('uge', 1, a)),
|
|
|
|
(('ior', ('uge', 1, a), ('ieq', a, 2)), ('uge', 2, a)),
|
|
|
|
(('ior', ('uge', 2, a), ('ieq', a, 3)), ('uge', 3, a)),
|
|
|
|
|
2019-03-30 03:51:20 +00:00
|
|
|
(('ior', a, ('ieq', a, False)), True),
|
2018-10-19 18:43:43 +01:00
|
|
|
(('ior', a, ('inot', a)), -1),
|
2018-07-16 06:19:29 +01:00
|
|
|
|
2020-08-11 23:49:37 +01:00
|
|
|
(('ine', ('ineg', ('b2i', 'a@1')), ('ineg', ('b2i', 'b@1'))), ('ine', a, b)),
|
|
|
|
(('b2i', ('ine', 'a@1', 'b@1')), ('b2i', ('ixor', a, b))),
|
2018-12-18 05:34:11 +00:00
|
|
|
|
2020-03-03 02:57:44 +00:00
|
|
|
# This pattern occurs coutresy of __flt64_nonnan in the soft-fp64 code.
|
|
|
|
# The first part of the iand comes from the !__feq64_nonnan.
|
|
|
|
#
|
|
|
|
# The second pattern is a reformulation of the first based on the relation
|
|
|
|
# (a == 0 || y == 0) <=> umin(a, y) == 0, where b in the first equation
|
|
|
|
# happens to be y == 0.
|
|
|
|
(('iand', ('inot', ('iand', ('ior', ('ieq', a, 0), b), c)), ('ilt', a, 0)),
|
|
|
|
('iand', ('inot', ('iand', b , c)), ('ilt', a, 0))),
|
|
|
|
(('iand', ('inot', ('iand', ('ieq', ('umin', a, b), 0), c)), ('ilt', a, 0)),
|
|
|
|
('iand', ('inot', ('iand', ('ieq', b , 0), c)), ('ilt', a, 0))),
|
|
|
|
|
2018-01-05 21:29:26 +00:00
|
|
|
# These patterns can result when (a < b || a < c) => (a < min(b, c))
|
|
|
|
# transformations occur before constant propagation and loop-unrolling.
|
2020-08-19 21:35:14 +01:00
|
|
|
#
|
|
|
|
# The flt versions are exact. If isnan(a), the original pattern is
|
|
|
|
# trivially false, and the replacements are false too. If isnan(b):
|
|
|
|
#
|
|
|
|
# a < fmax(NaN, a) => a < a => false vs a < NaN => false
|
|
|
|
(('flt', a, ('fmax', b, a)), ('flt', a, b)),
|
|
|
|
(('flt', ('fmin', a, b), a), ('flt', b, a)),
|
2018-01-05 21:29:26 +00:00
|
|
|
(('~fge', a, ('fmin', b, a)), True),
|
|
|
|
(('~fge', ('fmax', a, b), a), True),
|
2020-08-19 21:35:14 +01:00
|
|
|
(('flt', a, ('fmin', b, a)), False),
|
|
|
|
(('flt', ('fmax', a, b), a), False),
|
nir: Add some missing "optimization undo" patterns
d8d18516b0a and 03fb13f6467 added some patterns to undo conversions like
(('ior', ('flt', a, b), ('flt', a, c)), ('flt', a, ('fmax', b, c)))
If further optimization cause some of the operands to either be the same
or be constants, undoing the transformation can lead to further savings.
I don't know why these patterns were not added in those patches. I did
not check to see which specific patterns actually helped. I just added
all of them for symmetry. This prevents some loop unrolling regressions
Plane Shift caused by Samuel's "nir: implement the GLSL equivalent of if
simplication in nir_opt_if" patch.
Skylake and Broadwell had similar results. (Skylake shown)
total instructions in shared programs: 14369768 -> 14369557 (<.01%)
instructions in affected programs: 44076 -> 43865 (-0.48%)
helped: 141
HURT: 0
helped stats (abs) min: 1 max: 5 x̄: 1.50 x̃: 1
helped stats (rel) min: 0.07% max: 1.52% x̄: 0.66% x̃: 0.60%
95% mean confidence interval for instructions value: -1.67 -1.32
95% mean confidence interval for instructions %-change: -0.72% -0.59%
Instructions are helped.
total cycles in shared programs: 532430629 -> 532425772 (<.01%)
cycles in affected programs: 1170832 -> 1165975 (-0.41%)
helped: 101
HURT: 5
helped stats (abs) min: 1 max: 160 x̄: 48.54 x̃: 32
helped stats (rel) min: <.01% max: 8.49% x̄: 2.76% x̃: 2.03%
HURT stats (abs) min: 2 max: 22 x̄: 9.20 x̃: 4
HURT stats (rel) min: <.01% max: 0.05% x̄: 0.02% x̃: <.01%
95% mean confidence interval for cycles value: -53.64 -38.00
95% mean confidence interval for cycles %-change: -3.06% -2.20%
Cycles are helped.
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2018-05-31 02:06:57 +01:00
|
|
|
(('~fge', a, ('fmax', b, a)), ('fge', a, b)),
|
|
|
|
(('~fge', ('fmin', a, b), a), ('fge', b, a)),
|
2018-01-05 21:29:26 +00:00
|
|
|
|
2018-01-05 21:20:46 +00:00
|
|
|
(('ilt', a, ('imax', b, a)), ('ilt', a, b)),
|
|
|
|
(('ilt', ('imin', a, b), a), ('ilt', b, a)),
|
|
|
|
(('ige', a, ('imin', b, a)), True),
|
|
|
|
(('ige', ('imax', a, b), a), True),
|
|
|
|
(('ult', a, ('umax', b, a)), ('ult', a, b)),
|
|
|
|
(('ult', ('umin', a, b), a), ('ult', b, a)),
|
|
|
|
(('uge', a, ('umin', b, a)), True),
|
|
|
|
(('uge', ('umax', a, b), a), True),
|
nir: Add some missing "optimization undo" patterns
d8d18516b0a and 03fb13f6467 added some patterns to undo conversions like
(('ior', ('flt', a, b), ('flt', a, c)), ('flt', a, ('fmax', b, c)))
If further optimization cause some of the operands to either be the same
or be constants, undoing the transformation can lead to further savings.
I don't know why these patterns were not added in those patches. I did
not check to see which specific patterns actually helped. I just added
all of them for symmetry. This prevents some loop unrolling regressions
Plane Shift caused by Samuel's "nir: implement the GLSL equivalent of if
simplication in nir_opt_if" patch.
Skylake and Broadwell had similar results. (Skylake shown)
total instructions in shared programs: 14369768 -> 14369557 (<.01%)
instructions in affected programs: 44076 -> 43865 (-0.48%)
helped: 141
HURT: 0
helped stats (abs) min: 1 max: 5 x̄: 1.50 x̃: 1
helped stats (rel) min: 0.07% max: 1.52% x̄: 0.66% x̃: 0.60%
95% mean confidence interval for instructions value: -1.67 -1.32
95% mean confidence interval for instructions %-change: -0.72% -0.59%
Instructions are helped.
total cycles in shared programs: 532430629 -> 532425772 (<.01%)
cycles in affected programs: 1170832 -> 1165975 (-0.41%)
helped: 101
HURT: 5
helped stats (abs) min: 1 max: 160 x̄: 48.54 x̃: 32
helped stats (rel) min: <.01% max: 8.49% x̄: 2.76% x̃: 2.03%
HURT stats (abs) min: 2 max: 22 x̄: 9.20 x̃: 4
HURT stats (rel) min: <.01% max: 0.05% x̄: 0.02% x̃: <.01%
95% mean confidence interval for cycles value: -53.64 -38.00
95% mean confidence interval for cycles %-change: -3.06% -2.20%
Cycles are helped.
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2018-05-31 02:06:57 +01:00
|
|
|
(('ilt', a, ('imin', b, a)), False),
|
|
|
|
(('ilt', ('imax', a, b), a), False),
|
|
|
|
(('ige', a, ('imax', b, a)), ('ige', a, b)),
|
|
|
|
(('ige', ('imin', a, b), a), ('ige', b, a)),
|
|
|
|
(('ult', a, ('umin', b, a)), False),
|
|
|
|
(('ult', ('umax', a, b), a), False),
|
|
|
|
(('uge', a, ('umax', b, a)), ('uge', a, b)),
|
|
|
|
(('uge', ('umin', a, b), a), ('uge', b, a)),
|
2019-01-25 11:48:44 +00:00
|
|
|
(('ult', a, ('iand', b, a)), False),
|
|
|
|
(('ult', ('ior', a, b), a), False),
|
|
|
|
(('uge', a, ('iand', b, a)), True),
|
|
|
|
(('uge', ('ior', a, b), a), True),
|
2018-01-05 21:20:46 +00:00
|
|
|
|
nir: Add some missing "optimization undo" patterns
d8d18516b0a and 03fb13f6467 added some patterns to undo conversions like
(('ior', ('flt', a, b), ('flt', a, c)), ('flt', a, ('fmax', b, c)))
If further optimization cause some of the operands to either be the same
or be constants, undoing the transformation can lead to further savings.
I don't know why these patterns were not added in those patches. I did
not check to see which specific patterns actually helped. I just added
all of them for symmetry. This prevents some loop unrolling regressions
Plane Shift caused by Samuel's "nir: implement the GLSL equivalent of if
simplication in nir_opt_if" patch.
Skylake and Broadwell had similar results. (Skylake shown)
total instructions in shared programs: 14369768 -> 14369557 (<.01%)
instructions in affected programs: 44076 -> 43865 (-0.48%)
helped: 141
HURT: 0
helped stats (abs) min: 1 max: 5 x̄: 1.50 x̃: 1
helped stats (rel) min: 0.07% max: 1.52% x̄: 0.66% x̃: 0.60%
95% mean confidence interval for instructions value: -1.67 -1.32
95% mean confidence interval for instructions %-change: -0.72% -0.59%
Instructions are helped.
total cycles in shared programs: 532430629 -> 532425772 (<.01%)
cycles in affected programs: 1170832 -> 1165975 (-0.41%)
helped: 101
HURT: 5
helped stats (abs) min: 1 max: 160 x̄: 48.54 x̃: 32
helped stats (rel) min: <.01% max: 8.49% x̄: 2.76% x̃: 2.03%
HURT stats (abs) min: 2 max: 22 x̄: 9.20 x̃: 4
HURT stats (rel) min: <.01% max: 0.05% x̄: 0.02% x̃: <.01%
95% mean confidence interval for cycles value: -53.64 -38.00
95% mean confidence interval for cycles %-change: -3.06% -2.20%
Cycles are helped.
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2018-05-31 02:06:57 +01:00
|
|
|
(('ilt', '#a', ('imax', '#b', c)), ('ior', ('ilt', a, b), ('ilt', a, c))),
|
|
|
|
(('ilt', ('imin', '#a', b), '#c'), ('ior', ('ilt', a, c), ('ilt', b, c))),
|
|
|
|
(('ige', '#a', ('imin', '#b', c)), ('ior', ('ige', a, b), ('ige', a, c))),
|
|
|
|
(('ige', ('imax', '#a', b), '#c'), ('ior', ('ige', a, c), ('ige', b, c))),
|
|
|
|
(('ult', '#a', ('umax', '#b', c)), ('ior', ('ult', a, b), ('ult', a, c))),
|
|
|
|
(('ult', ('umin', '#a', b), '#c'), ('ior', ('ult', a, c), ('ult', b, c))),
|
|
|
|
(('uge', '#a', ('umin', '#b', c)), ('ior', ('uge', a, b), ('uge', a, c))),
|
|
|
|
(('uge', ('umax', '#a', b), '#c'), ('ior', ('uge', a, c), ('uge', b, c))),
|
2018-01-05 21:20:46 +00:00
|
|
|
(('ilt', '#a', ('imin', '#b', c)), ('iand', ('ilt', a, b), ('ilt', a, c))),
|
|
|
|
(('ilt', ('imax', '#a', b), '#c'), ('iand', ('ilt', a, c), ('ilt', b, c))),
|
|
|
|
(('ige', '#a', ('imax', '#b', c)), ('iand', ('ige', a, b), ('ige', a, c))),
|
|
|
|
(('ige', ('imin', '#a', b), '#c'), ('iand', ('ige', a, c), ('ige', b, c))),
|
|
|
|
(('ult', '#a', ('umin', '#b', c)), ('iand', ('ult', a, b), ('ult', a, c))),
|
|
|
|
(('ult', ('umax', '#a', b), '#c'), ('iand', ('ult', a, c), ('ult', b, c))),
|
|
|
|
(('uge', '#a', ('umax', '#b', c)), ('iand', ('uge', a, b), ('uge', a, c))),
|
|
|
|
(('uge', ('umin', '#a', b), '#c'), ('iand', ('uge', a, c), ('uge', b, c))),
|
|
|
|
|
2019-03-10 15:06:56 +00:00
|
|
|
# Thanks to sign extension, the ishr(a, b) is negative if and only if a is
|
|
|
|
# negative.
|
|
|
|
(('bcsel', ('ilt', a, 0), ('ineg', ('ishr', a, b)), ('ishr', a, b)),
|
|
|
|
('iabs', ('ishr', a, b))),
|
|
|
|
(('iabs', ('ishr', ('iabs', a), b)), ('ishr', ('iabs', a), b)),
|
|
|
|
|
2016-03-02 21:47:56 +00:00
|
|
|
(('fabs', ('slt', a, b)), ('slt', a, b)),
|
|
|
|
(('fabs', ('sge', a, b)), ('sge', a, b)),
|
|
|
|
(('fabs', ('seq', a, b)), ('seq', a, b)),
|
|
|
|
(('fabs', ('sne', a, b)), ('sne', a, b)),
|
2015-03-31 16:25:19 +01:00
|
|
|
(('slt', a, b), ('b2f', ('flt', a, b)), 'options->lower_scmp'),
|
|
|
|
(('sge', a, b), ('b2f', ('fge', a, b)), 'options->lower_scmp'),
|
|
|
|
(('seq', a, b), ('b2f', ('feq', a, b)), 'options->lower_scmp'),
|
2020-08-18 18:51:57 +01:00
|
|
|
(('sne', a, b), ('b2f', ('fneu', a, b)), 'options->lower_scmp'),
|
2019-07-24 18:33:17 +01:00
|
|
|
(('seq', ('seq', a, b), 1.0), ('seq', a, b)),
|
|
|
|
(('seq', ('sne', a, b), 1.0), ('sne', a, b)),
|
|
|
|
(('seq', ('slt', a, b), 1.0), ('slt', a, b)),
|
|
|
|
(('seq', ('sge', a, b), 1.0), ('sge', a, b)),
|
|
|
|
(('sne', ('seq', a, b), 0.0), ('seq', a, b)),
|
|
|
|
(('sne', ('sne', a, b), 0.0), ('sne', a, b)),
|
|
|
|
(('sne', ('slt', a, b), 0.0), ('slt', a, b)),
|
|
|
|
(('sne', ('sge', a, b), 0.0), ('sge', a, b)),
|
|
|
|
(('seq', ('seq', a, b), 0.0), ('sne', a, b)),
|
|
|
|
(('seq', ('sne', a, b), 0.0), ('seq', a, b)),
|
|
|
|
(('seq', ('slt', a, b), 0.0), ('sge', a, b)),
|
|
|
|
(('seq', ('sge', a, b), 0.0), ('slt', a, b)),
|
|
|
|
(('sne', ('seq', a, b), 1.0), ('sne', a, b)),
|
|
|
|
(('sne', ('sne', a, b), 1.0), ('seq', a, b)),
|
|
|
|
(('sne', ('slt', a, b), 1.0), ('sge', a, b)),
|
|
|
|
(('sne', ('sge', a, b), 1.0), ('slt', a, b)),
|
2019-06-02 23:44:49 +01:00
|
|
|
(('fall_equal2', a, b), ('fmin', ('seq', 'a.x', 'b.x'), ('seq', 'a.y', 'b.y')), 'options->lower_vector_cmp'),
|
|
|
|
(('fall_equal3', a, b), ('seq', ('fany_nequal3', a, b), 0.0), 'options->lower_vector_cmp'),
|
|
|
|
(('fall_equal4', a, b), ('seq', ('fany_nequal4', a, b), 0.0), 'options->lower_vector_cmp'),
|
|
|
|
(('fany_nequal2', a, b), ('fmax', ('sne', 'a.x', 'b.x'), ('sne', 'a.y', 'b.y')), 'options->lower_vector_cmp'),
|
|
|
|
(('fany_nequal3', a, b), ('fsat', ('fdot3', ('sne', a, b), ('sne', a, b))), 'options->lower_vector_cmp'),
|
|
|
|
(('fany_nequal4', a, b), ('fsat', ('fdot4', ('sne', a, b), ('sne', a, b))), 'options->lower_vector_cmp'),
|
2020-01-04 00:33:54 +00:00
|
|
|
|
|
|
|
(('ball_iequal2', a, b), ('iand', ('ieq', 'a.x', 'b.x'), ('ieq', 'a.y', 'b.y')), 'options->lower_vector_cmp'),
|
|
|
|
(('ball_iequal3', a, b), ('iand', ('iand', ('ieq', 'a.x', 'b.x'), ('ieq', 'a.y', 'b.y')), ('ieq', 'a.z', 'b.z')), 'options->lower_vector_cmp'),
|
|
|
|
(('ball_iequal4', a, b), ('iand', ('iand', ('ieq', 'a.x', 'b.x'), ('ieq', 'a.y', 'b.y')), ('iand', ('ieq', 'a.z', 'b.z'), ('ieq', 'a.w', 'b.w'))), 'options->lower_vector_cmp'),
|
|
|
|
|
|
|
|
(('bany_inequal2', a, b), ('ior', ('ine', 'a.x', 'b.x'), ('ine', 'a.y', 'b.y')), 'options->lower_vector_cmp'),
|
|
|
|
(('bany_inequal3', a, b), ('ior', ('ior', ('ine', 'a.x', 'b.x'), ('ine', 'a.y', 'b.y')), ('ine', 'a.z', 'b.z')), 'options->lower_vector_cmp'),
|
|
|
|
(('bany_inequal4', a, b), ('ior', ('ior', ('ine', 'a.x', 'b.x'), ('ine', 'a.y', 'b.y')), ('ior', ('ine', 'a.z', 'b.z'), ('ine', 'a.w', 'b.w'))), 'options->lower_vector_cmp'),
|
|
|
|
|
|
|
|
(('ball_fequal2', a, b), ('iand', ('feq', 'a.x', 'b.x'), ('feq', 'a.y', 'b.y')), 'options->lower_vector_cmp'),
|
|
|
|
(('ball_fequal3', a, b), ('iand', ('iand', ('feq', 'a.x', 'b.x'), ('feq', 'a.y', 'b.y')), ('feq', 'a.z', 'b.z')), 'options->lower_vector_cmp'),
|
|
|
|
(('ball_fequal4', a, b), ('iand', ('iand', ('feq', 'a.x', 'b.x'), ('feq', 'a.y', 'b.y')), ('iand', ('feq', 'a.z', 'b.z'), ('feq', 'a.w', 'b.w'))), 'options->lower_vector_cmp'),
|
|
|
|
|
|
|
|
(('bany_fnequal2', a, b), ('ior', ('fneu', 'a.x', 'b.x'), ('fneu', 'a.y', 'b.y')), 'options->lower_vector_cmp'),
|
|
|
|
(('bany_fnequal3', a, b), ('ior', ('ior', ('fneu', 'a.x', 'b.x'), ('fneu', 'a.y', 'b.y')), ('fneu', 'a.z', 'b.z')), 'options->lower_vector_cmp'),
|
|
|
|
(('bany_fnequal4', a, b), ('ior', ('ior', ('fneu', 'a.x', 'b.x'), ('fneu', 'a.y', 'b.y')), ('ior', ('fneu', 'a.z', 'b.z'), ('fneu', 'a.w', 'b.w'))), 'options->lower_vector_cmp'),
|
|
|
|
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('fneg', a), a), ('fneu', a, 0.0)),
|
2015-08-06 12:36:05 +01:00
|
|
|
(('feq', ('fneg', a), a), ('feq', a, 0.0)),
|
2015-03-18 06:30:32 +00:00
|
|
|
# Emulating booleans
|
2018-12-06 03:36:10 +00:00
|
|
|
(('imul', ('b2i', 'a@1'), ('b2i', 'b@1')), ('b2i', ('iand', a, b))),
|
2020-07-15 18:30:34 +01:00
|
|
|
(('iand', ('b2i', 'a@1'), ('b2i', 'b@1')), ('b2i', ('iand', a, b))),
|
|
|
|
(('ior', ('b2i', 'a@1'), ('b2i', 'b@1')), ('b2i', ('ior', a, b))),
|
2018-12-06 03:36:10 +00:00
|
|
|
(('fmul', ('b2f', 'a@1'), ('b2f', 'b@1')), ('b2f', ('iand', a, b))),
|
|
|
|
(('fsat', ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1'))), ('b2f', ('ior', a, b))),
|
2020-09-01 07:30:13 +01:00
|
|
|
(('iand', 'a@bool16', 1.0), ('b2f', a)),
|
2018-12-06 03:32:11 +00:00
|
|
|
(('iand', 'a@bool32', 1.0), ('b2f', a)),
|
2018-12-06 03:36:10 +00:00
|
|
|
(('flt', ('fneg', ('b2f', 'a@1')), 0), a), # Generated by TGSI KILL_IF.
|
nir/algebraic: Add algebraic opt for float comparisons with identical operands.
The flt version could have been added in 56e21647e20d, but our
collective understanding of NaN and comparisons was poor in 2015. The
new "is_a_number" predicate makes the others possible.
All of the helped shaders in shader-db are either from Mad Max or Skia.
Some of the Skia shaders just get decimated by this change:
instructions helped: shaders/skia/580-4.shader_test FS SIMD8: 81 -> 29 (-64.20%) (scheduled: top-down)
I looked at a couple of those shaders, and they had sequences like:
vec1 32 ssa_44 = flt32 ssa_32, ssa_32
vec1 32 ssa_45 = b32csel ssa_44, ssa_43, ssa_0
vec1 32 ssa_46 = fge32 ssa_32, ssa_32
vec1 32 ssa_47 = b32csel ssa_46, ssa_0, ssa_45
vec1 32 ssa_48 = iand ssa_46, ssa_44
vec1 32 ssa_49 = b32csel ssa_48, ssa_43, ssa_0
ssa_44 is replaced with False. Then ssa_47 selects between ssa_0 and
ssa_0, so ssa_47 and ssa_46 are eliminated. ssa_48 is (False && don't
care), so ssa_48 and ssa_49 are eliminated. After that, many
calculations now involve constants of zero, so they are optimized down
too. So it continues until there's not much left!
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel platforms had similar results. (Tiger Lake shown)
total instructions in shared programs: 21072238 -> 21071386 (<.01%)
instructions in affected programs: 33722 -> 32870 (-2.53%)
helped: 146
HURT: 1
helped stats (abs) min: 1 max: 62 x̄: 5.84 x̃: 2
helped stats (rel) min: 0.19% max: 62.35% x̄: 4.09% x̃: 1.07%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.20% max: 0.20% x̄: 0.20% x̃: 0.20%
95% mean confidence interval for instructions value: -7.94 -3.65
95% mean confidence interval for instructions %-change: -5.87% -2.25%
Instructions are helped.
total cycles in shared programs: 856203326 -> 856192238 (<.01%)
cycles in affected programs: 749966 -> 738878 (-1.48%)
helped: 148
HURT: 0
helped stats (abs) min: 1 max: 1226 x̄: 74.92 x̃: 18
helped stats (rel) min: 0.07% max: 49.70% x̄: 2.69% x̃: 0.46%
95% mean confidence interval for cycles value: -104.82 -45.02
95% mean confidence interval for cycles %-change: -4.01% -1.37%
Cycles are helped.
LOST: 4
GAINED: 0
Fossil-db results:
Tiger Lake
Instructions in all programs: 160915223 -> 160898354 (-0.0%)
SENDs in all programs: 6812780 -> 6812780 (+0.0%)
Loops in all programs: 38340 -> 38340 (+0.0%)
Cycles in all programs: 7434144207 -> 7433978462 (-0.0%)
Spills in all programs: 192582 -> 192582 (+0.0%)
Fills in all programs: 304537 -> 304537 (+0.0%)
Ice Lake
Instructions in all programs: 145296298 -> 145279531 (-0.0%)
SENDs in all programs: 6863692 -> 6863692 (+0.0%)
Loops in all programs: 38334 -> 38334 (+0.0%)
Cycles in all programs: 8800257014 -> 8800088384 (-0.0%)
Spills in all programs: 216880 -> 216880 (+0.0%)
Fills in all programs: 334248 -> 334248 (+0.0%)
Skylake
Instructions in all programs: 135891664 -> 135874910 (-0.0%)
SENDs in all programs: 6802946 -> 6802946 (+0.0%)
Loops in all programs: 38331 -> 38331 (+0.0%)
Cycles in all programs: 8444273433 -> 8444130932 (-0.0%)
Spills in all programs: 194839 -> 194839 (+0.0%)
Fills in all programs: 301114 -> 301114 (+0.0%)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-10 23:34:42 +01:00
|
|
|
# Comparison with the same args. Note that these are only done for the
|
|
|
|
# float versions when the source must be a number. Generally, NaN cmp NaN
|
|
|
|
# produces the opposite result of X cmp X. flt is the outlier. NaN < NaN
|
|
|
|
# is false, and, for any number X, X < X is also false.
|
2015-02-07 01:12:59 +00:00
|
|
|
(('ilt', a, a), False),
|
|
|
|
(('ige', a, a), True),
|
|
|
|
(('ieq', a, a), True),
|
|
|
|
(('ine', a, a), False),
|
|
|
|
(('ult', a, a), False),
|
|
|
|
(('uge', a, a), True),
|
nir/algebraic: Add algebraic opt for float comparisons with identical operands.
The flt version could have been added in 56e21647e20d, but our
collective understanding of NaN and comparisons was poor in 2015. The
new "is_a_number" predicate makes the others possible.
All of the helped shaders in shader-db are either from Mad Max or Skia.
Some of the Skia shaders just get decimated by this change:
instructions helped: shaders/skia/580-4.shader_test FS SIMD8: 81 -> 29 (-64.20%) (scheduled: top-down)
I looked at a couple of those shaders, and they had sequences like:
vec1 32 ssa_44 = flt32 ssa_32, ssa_32
vec1 32 ssa_45 = b32csel ssa_44, ssa_43, ssa_0
vec1 32 ssa_46 = fge32 ssa_32, ssa_32
vec1 32 ssa_47 = b32csel ssa_46, ssa_0, ssa_45
vec1 32 ssa_48 = iand ssa_46, ssa_44
vec1 32 ssa_49 = b32csel ssa_48, ssa_43, ssa_0
ssa_44 is replaced with False. Then ssa_47 selects between ssa_0 and
ssa_0, so ssa_47 and ssa_46 are eliminated. ssa_48 is (False && don't
care), so ssa_48 and ssa_49 are eliminated. After that, many
calculations now involve constants of zero, so they are optimized down
too. So it continues until there's not much left!
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
All Intel platforms had similar results. (Tiger Lake shown)
total instructions in shared programs: 21072238 -> 21071386 (<.01%)
instructions in affected programs: 33722 -> 32870 (-2.53%)
helped: 146
HURT: 1
helped stats (abs) min: 1 max: 62 x̄: 5.84 x̃: 2
helped stats (rel) min: 0.19% max: 62.35% x̄: 4.09% x̃: 1.07%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.20% max: 0.20% x̄: 0.20% x̃: 0.20%
95% mean confidence interval for instructions value: -7.94 -3.65
95% mean confidence interval for instructions %-change: -5.87% -2.25%
Instructions are helped.
total cycles in shared programs: 856203326 -> 856192238 (<.01%)
cycles in affected programs: 749966 -> 738878 (-1.48%)
helped: 148
HURT: 0
helped stats (abs) min: 1 max: 1226 x̄: 74.92 x̃: 18
helped stats (rel) min: 0.07% max: 49.70% x̄: 2.69% x̃: 0.46%
95% mean confidence interval for cycles value: -104.82 -45.02
95% mean confidence interval for cycles %-change: -4.01% -1.37%
Cycles are helped.
LOST: 4
GAINED: 0
Fossil-db results:
Tiger Lake
Instructions in all programs: 160915223 -> 160898354 (-0.0%)
SENDs in all programs: 6812780 -> 6812780 (+0.0%)
Loops in all programs: 38340 -> 38340 (+0.0%)
Cycles in all programs: 7434144207 -> 7433978462 (-0.0%)
Spills in all programs: 192582 -> 192582 (+0.0%)
Fills in all programs: 304537 -> 304537 (+0.0%)
Ice Lake
Instructions in all programs: 145296298 -> 145279531 (-0.0%)
SENDs in all programs: 6863692 -> 6863692 (+0.0%)
Loops in all programs: 38334 -> 38334 (+0.0%)
Cycles in all programs: 8800257014 -> 8800088384 (-0.0%)
Spills in all programs: 216880 -> 216880 (+0.0%)
Fills in all programs: 334248 -> 334248 (+0.0%)
Skylake
Instructions in all programs: 135891664 -> 135874910 (-0.0%)
SENDs in all programs: 6802946 -> 6802946 (+0.0%)
Loops in all programs: 38331 -> 38331 (+0.0%)
Cycles in all programs: 8444273433 -> 8444130932 (-0.0%)
Spills in all programs: 194839 -> 194839 (+0.0%)
Fills in all programs: 301114 -> 301114 (+0.0%)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>
2020-08-10 23:34:42 +01:00
|
|
|
(('flt', a, a), False),
|
|
|
|
(('fge', 'a(is_a_number)', a), True),
|
|
|
|
(('feq', 'a(is_a_number)', a), True),
|
|
|
|
(('fneu', 'a(is_a_number)', a), False),
|
2015-01-19 22:57:38 +00:00
|
|
|
# Logical and bit operations
|
|
|
|
(('iand', a, a), a),
|
2015-07-31 17:12:48 +01:00
|
|
|
(('iand', a, ~0), a),
|
2015-01-19 22:57:38 +00:00
|
|
|
(('iand', a, 0), 0),
|
|
|
|
(('ior', a, a), a),
|
|
|
|
(('ior', a, 0), a),
|
2016-07-06 23:00:45 +01:00
|
|
|
(('ior', a, True), True),
|
2015-01-19 22:57:38 +00:00
|
|
|
(('ixor', a, a), 0),
|
2016-02-02 00:34:46 +00:00
|
|
|
(('ixor', a, 0), a),
|
2015-01-19 22:57:38 +00:00
|
|
|
(('inot', ('inot', a)), a),
|
2018-07-23 08:35:02 +01:00
|
|
|
(('ior', ('iand', a, b), b), b),
|
|
|
|
(('ior', ('ior', a, b), b), ('ior', a, b)),
|
|
|
|
(('iand', ('ior', a, b), b), b),
|
|
|
|
(('iand', ('iand', a, b), b), ('iand', a, b)),
|
2015-01-19 22:57:38 +00:00
|
|
|
# DeMorgan's Laws
|
|
|
|
(('iand', ('inot', a), ('inot', b)), ('inot', ('ior', a, b))),
|
|
|
|
(('ior', ('inot', a), ('inot', b)), ('inot', ('iand', a, b))),
|
2015-01-22 07:25:56 +00:00
|
|
|
# Shift optimizations
|
|
|
|
(('ishl', 0, a), 0),
|
|
|
|
(('ishl', a, 0), a),
|
|
|
|
(('ishr', 0, a), 0),
|
|
|
|
(('ishr', a, 0), a),
|
|
|
|
(('ushr', 0, a), 0),
|
2015-04-14 16:40:22 +01:00
|
|
|
(('ushr', a, 0), a),
|
2019-05-30 22:15:51 +01:00
|
|
|
(('ior', ('ishl@16', a, b), ('ushr@16', a, ('iadd', 16, ('ineg', b)))), ('urol', a, b), '!options->lower_rotate'),
|
|
|
|
(('ior', ('ishl@16', a, b), ('ushr@16', a, ('isub', 16, b))), ('urol', a, b), '!options->lower_rotate'),
|
|
|
|
(('ior', ('ishl@32', a, b), ('ushr@32', a, ('iadd', 32, ('ineg', b)))), ('urol', a, b), '!options->lower_rotate'),
|
|
|
|
(('ior', ('ishl@32', a, b), ('ushr@32', a, ('isub', 32, b))), ('urol', a, b), '!options->lower_rotate'),
|
|
|
|
(('ior', ('ushr@16', a, b), ('ishl@16', a, ('iadd', 16, ('ineg', b)))), ('uror', a, b), '!options->lower_rotate'),
|
|
|
|
(('ior', ('ushr@16', a, b), ('ishl@16', a, ('isub', 16, b))), ('uror', a, b), '!options->lower_rotate'),
|
|
|
|
(('ior', ('ushr@32', a, b), ('ishl@32', a, ('iadd', 32, ('ineg', b)))), ('uror', a, b), '!options->lower_rotate'),
|
|
|
|
(('ior', ('ushr@32', a, b), ('ishl@32', a, ('isub', 32, b))), ('uror', a, b), '!options->lower_rotate'),
|
|
|
|
(('urol@16', a, b), ('ior', ('ishl', a, b), ('ushr', a, ('isub', 16, b))), 'options->lower_rotate'),
|
|
|
|
(('urol@32', a, b), ('ior', ('ishl', a, b), ('ushr', a, ('isub', 32, b))), 'options->lower_rotate'),
|
|
|
|
(('uror@16', a, b), ('ior', ('ushr', a, b), ('ishl', a, ('isub', 16, b))), 'options->lower_rotate'),
|
|
|
|
(('uror@32', a, b), ('ior', ('ushr', a, b), ('ishl', a, ('isub', 32, b))), 'options->lower_rotate'),
|
2015-01-22 07:47:06 +00:00
|
|
|
# Exponential/logarithmic identities
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fexp2', ('flog2', a)), a), # 2^lg2(a) = a
|
|
|
|
(('~flog2', ('fexp2', a)), a), # lg2(2^a) = a
|
2015-01-28 18:32:57 +00:00
|
|
|
(('fpow', a, b), ('fexp2', ('fmul', ('flog2', a), b)), 'options->lower_fpow'), # a^b = 2^(lg2(a)*b)
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fexp2', ('fmul', ('flog2', a), b)), ('fpow', a, b), '!options->lower_fpow'), # 2^(lg2(a)*b) = a^b
|
|
|
|
(('~fexp2', ('fadd', ('fmul', ('flog2', a), b), ('fmul', ('flog2', c), d))),
|
|
|
|
('~fmul', ('fpow', a, b), ('fpow', c, d)), '!options->lower_fpow'), # 2^(lg2(a) * b + lg2(c) + d) = a^b * c^d
|
2020-03-27 15:40:38 +00:00
|
|
|
(('~fexp2', ('fmul', ('flog2', a), 0.5)), ('fsqrt', a)),
|
2018-02-05 14:08:03 +00:00
|
|
|
(('~fexp2', ('fmul', ('flog2', a), 2.0)), ('fmul', a, a)),
|
|
|
|
(('~fexp2', ('fmul', ('flog2', a), 4.0)), ('fmul', ('fmul', a, a), ('fmul', a, a))),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fpow', a, 1.0), a),
|
|
|
|
(('~fpow', a, 2.0), ('fmul', a, a)),
|
|
|
|
(('~fpow', a, 4.0), ('fmul', ('fmul', a, a), ('fmul', a, a))),
|
|
|
|
(('~fpow', 2.0, a), ('fexp2', a)),
|
|
|
|
(('~fpow', ('fpow', a, 2.2), 0.454545), a),
|
|
|
|
(('~fpow', ('fabs', ('fpow', a, 2.2)), 0.454545), ('fabs', a)),
|
|
|
|
(('~fsqrt', ('fexp2', a)), ('fexp2', ('fmul', 0.5, a))),
|
|
|
|
(('~frcp', ('fexp2', a)), ('fexp2', ('fneg', a))),
|
|
|
|
(('~frsq', ('fexp2', a)), ('fexp2', ('fmul', -0.5, a))),
|
|
|
|
(('~flog2', ('fsqrt', a)), ('fmul', 0.5, ('flog2', a))),
|
|
|
|
(('~flog2', ('frcp', a)), ('fneg', ('flog2', a))),
|
|
|
|
(('~flog2', ('frsq', a)), ('fmul', -0.5, ('flog2', a))),
|
|
|
|
(('~flog2', ('fpow', a, b)), ('fmul', b, ('flog2', a))),
|
2018-02-05 15:07:45 +00:00
|
|
|
(('~fmul', ('fexp2(is_used_once)', a), ('fexp2(is_used_once)', b)), ('fexp2', ('fadd', a, b))),
|
2018-10-25 03:48:49 +01:00
|
|
|
(('bcsel', ('flt', a, 0.0), 0.0, ('fsqrt', a)), ('fsqrt', ('fmax', a, 0.0))),
|
2019-05-24 12:16:25 +01:00
|
|
|
(('~fmul', ('fsqrt', a), ('fsqrt', a)), ('fabs',a)),
|
2015-01-22 07:52:17 +00:00
|
|
|
# Division and reciprocal
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~fdiv', 1.0, a), ('frcp', a)),
|
nir: Add a lower_fdiv option, turn fdiv into fmul/frcp.
The nir_opt_algebraic rule
(('fadd', ('flog2', a), ('fneg', ('flog2', b))), ('flog2', ('fdiv', a, b))),
can produce new fdiv operations, which need to be lowered on i965,
as we don't actually implement fdiv. (Normally, we handle this in
GLSL IR's lower_instructions pass, but in the above case we introduce
an fdiv after that point. So, make NIR do it for us.)
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Cc: mesa-stable@lists.freedesktop.org
2016-01-05 13:09:46 +00:00
|
|
|
(('fdiv', a, b), ('fmul', a, ('frcp', b)), 'options->lower_fdiv'),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~frcp', ('frcp', a)), a),
|
|
|
|
(('~frcp', ('fsqrt', a)), ('frsq', a)),
|
2015-01-28 18:39:29 +00:00
|
|
|
(('fsqrt', a), ('frcp', ('frsq', a)), 'options->lower_fsqrt'),
|
2016-03-17 18:31:48 +00:00
|
|
|
(('~frcp', ('frsq', a)), ('fsqrt', a), '!options->lower_fsqrt'),
|
2019-05-08 15:26:49 +01:00
|
|
|
# Trig
|
|
|
|
(('fsin', a), lowered_sincos(0.5), 'options->lower_sincos'),
|
|
|
|
(('fcos', a), lowered_sincos(0.75), 'options->lower_sincos'),
|
2015-01-29 00:55:03 +00:00
|
|
|
# Boolean simplifications
|
2020-09-01 07:30:13 +01:00
|
|
|
(('i2b16(is_used_by_if)', a), ('ine16', a, 0)),
|
2018-12-04 00:30:44 +00:00
|
|
|
(('i2b32(is_used_by_if)', a), ('ine32', a, 0)),
|
|
|
|
(('i2b1(is_used_by_if)', a), ('ine', a, 0)),
|
2019-03-30 03:51:20 +00:00
|
|
|
(('ieq', a, True), a),
|
|
|
|
(('ine(is_not_used_by_if)', a, True), ('inot', a)),
|
|
|
|
(('ine', a, False), a),
|
|
|
|
(('ieq(is_not_used_by_if)', a, False), ('inot', 'a')),
|
2016-08-17 23:03:01 +01:00
|
|
|
(('bcsel', a, True, False), a),
|
|
|
|
(('bcsel', a, False, True), ('inot', a)),
|
2015-01-29 00:53:51 +00:00
|
|
|
(('bcsel', True, b, c), b),
|
|
|
|
(('bcsel', False, b, c), c),
|
2015-01-19 22:57:38 +00:00
|
|
|
|
nir/algebraic: Avoid creating new fp64 ops when using softfp64
In commit 00b28a50b2c492eee25ef3f75538aabe1e569ff1, Marek extended
a number of optimizations that had been 32-bit specific to work on
other bit-sizes.
Most optimizations preserve the data type across the transformation.
In other words, an optimization which generates e.g. fp64 operations
only does so when the source expression also contains fp64 operations.
These transformations are fine with respect to lowering, because we
will lower away all expressions that would trigger the search portion
of the expression, and so we'd never apply those rules.
However, a few of the rules create new operations that run afoul of
lowering passes. For example,
('bcsel', a, 1.0, 0.0) => ('b2f', a)
where the result is a double would simply be a selection between two
different 64-bit constants. The replacement expression, on the other
hand, involves a nir_op_b2f64 ALU operation. If we're run after
nir_lower_doubles, then it may not be legal to generate such an
expression anymore (at least without running lowering again, which we
don't do today).
Regressions due to this are blocking the 20.3 release, so for now, we
take the easy route and simply disallow those few rules when doing full
softfp64 lowering, which fixes the immediate problem. But it doesn't
solve the long-term problem in an extensible manner.
In the future, we may want to add a `lowered_alu_ops` bitfield to the
NIR shader, and as lowering passes are run, mark them as taboo. Then,
we could have each algebraic transformation track which operations it
creates in the replacement expression. With both of those in place,
nir_replace_instr could compare the transformation's list of ALU ops
against `lowered_alu_ops` and implicitly skip rules that generate
forbidden ALU operations.
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3504
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7841>
2020-12-01 00:14:55 +00:00
|
|
|
(('bcsel@16', a, 1.0, 0.0), ('b2f', a)),
|
|
|
|
(('bcsel@16', a, 0.0, 1.0), ('b2f', ('inot', a))),
|
|
|
|
(('bcsel@16', a, -1.0, -0.0), ('fneg', ('b2f', a))),
|
|
|
|
(('bcsel@16', a, -0.0, -1.0), ('fneg', ('b2f', ('inot', a)))),
|
|
|
|
(('bcsel@32', a, 1.0, 0.0), ('b2f', a)),
|
|
|
|
(('bcsel@32', a, 0.0, 1.0), ('b2f', ('inot', a))),
|
|
|
|
(('bcsel@32', a, -1.0, -0.0), ('fneg', ('b2f', a))),
|
|
|
|
(('bcsel@32', a, -0.0, -1.0), ('fneg', ('b2f', ('inot', a)))),
|
|
|
|
(('bcsel@64', a, 1.0, 0.0), ('b2f', a), '!(options->lower_doubles_options & nir_lower_fp64_full_software)'),
|
|
|
|
(('bcsel@64', a, 0.0, 1.0), ('b2f', ('inot', a)), '!(options->lower_doubles_options & nir_lower_fp64_full_software)'),
|
|
|
|
(('bcsel@64', a, -1.0, -0.0), ('fneg', ('b2f', a)), '!(options->lower_doubles_options & nir_lower_fp64_full_software)'),
|
|
|
|
(('bcsel@64', a, -0.0, -1.0), ('fneg', ('b2f', ('inot', a))), '!(options->lower_doubles_options & nir_lower_fp64_full_software)'),
|
|
|
|
|
2015-01-29 23:50:18 +00:00
|
|
|
(('bcsel', a, b, b), b),
|
2019-04-23 14:54:24 +01:00
|
|
|
(('~fcsel', a, b, b), b),
|
2015-01-29 23:50:18 +00:00
|
|
|
|
2018-10-19 22:58:36 +01:00
|
|
|
# D3D Boolean emulation
|
|
|
|
(('bcsel', a, -1, 0), ('ineg', ('b2i', 'a@1'))),
|
|
|
|
(('bcsel', a, 0, -1), ('ineg', ('b2i', ('inot', a)))),
|
2020-04-28 11:45:07 +01:00
|
|
|
(('bcsel', a, 1, 0), ('b2i', 'a@1')),
|
|
|
|
(('bcsel', a, 0, 1), ('b2i', ('inot', a))),
|
2018-10-19 22:58:36 +01:00
|
|
|
(('iand', ('ineg', ('b2i', 'a@1')), ('ineg', ('b2i', 'b@1'))),
|
|
|
|
('ineg', ('b2i', ('iand', a, b)))),
|
|
|
|
(('ior', ('ineg', ('b2i','a@1')), ('ineg', ('b2i', 'b@1'))),
|
|
|
|
('ineg', ('b2i', ('ior', a, b)))),
|
|
|
|
(('ieq', ('ineg', ('b2i', 'a@1')), 0), ('inot', a)),
|
|
|
|
(('ieq', ('ineg', ('b2i', 'a@1')), -1), a),
|
|
|
|
(('ine', ('ineg', ('b2i', 'a@1')), 0), a),
|
|
|
|
(('ine', ('ineg', ('b2i', 'a@1')), -1), ('inot', a)),
|
2018-12-18 21:28:22 +00:00
|
|
|
(('iand', ('ineg', ('b2i', a)), 1.0), ('b2f', a)),
|
2019-09-09 23:47:48 +01:00
|
|
|
(('iand', ('ineg', ('b2i', a)), 1), ('b2i', a)),
|
2018-10-19 22:58:36 +01:00
|
|
|
|
2015-03-26 17:09:42 +00:00
|
|
|
# Conversions
|
2020-09-01 07:30:13 +01:00
|
|
|
(('i2b16', ('b2i', 'a@16')), a),
|
2018-11-07 19:43:40 +00:00
|
|
|
(('i2b32', ('b2i', 'a@32')), a),
|
2018-11-07 23:32:32 +00:00
|
|
|
(('f2i', ('ftrunc', a)), ('f2i', a)),
|
|
|
|
(('f2u', ('ftrunc', a)), ('f2u', a)),
|
2016-03-02 02:59:57 +00:00
|
|
|
(('i2b', ('ineg', a)), ('i2b', a)),
|
|
|
|
(('i2b', ('iabs', a)), ('i2b', a)),
|
2018-12-06 03:36:10 +00:00
|
|
|
(('inot', ('f2b1', a)), ('feq', a, 0.0)),
|
2015-03-26 17:09:42 +00:00
|
|
|
|
2020-05-09 03:05:46 +01:00
|
|
|
# Conversions from 16 bits to 32 bits and back can always be removed
|
2019-08-05 07:36:38 +01:00
|
|
|
(('f2fmp', ('f2f32', 'a@16')), a),
|
2020-05-09 03:05:46 +01:00
|
|
|
(('i2imp', ('i2i32', 'a@16')), a),
|
2020-09-04 06:51:49 +01:00
|
|
|
(('i2imp', ('u2u32', 'a@16')), a),
|
2020-09-04 06:48:35 +01:00
|
|
|
|
|
|
|
(('f2imp', ('f2f32', 'a@16')), ('f2i16', a)),
|
|
|
|
(('f2ump', ('f2f32', 'a@16')), ('f2u16', a)),
|
|
|
|
(('i2fmp', ('i2i32', 'a@16')), ('i2f16', a)),
|
|
|
|
(('u2fmp', ('u2u32', 'a@16')), ('u2f16', a)),
|
|
|
|
|
2020-05-11 16:05:15 +01:00
|
|
|
(('f2fmp', ('b2f32', 'a@1')), ('b2f16', a)),
|
2020-05-09 03:05:46 +01:00
|
|
|
(('i2imp', ('b2i32', 'a@1')), ('b2i16', a)),
|
2020-09-04 06:51:49 +01:00
|
|
|
(('i2imp', ('b2i32', 'a@1')), ('b2i16', a)),
|
2020-09-04 06:48:35 +01:00
|
|
|
|
|
|
|
(('f2imp', ('b2f32', 'a@1')), ('b2i16', a)),
|
|
|
|
(('f2ump', ('b2f32', 'a@1')), ('b2i16', a)),
|
|
|
|
(('i2fmp', ('b2i32', 'a@1')), ('b2f16', a)),
|
|
|
|
(('u2fmp', ('b2i32', 'a@1')), ('b2f16', a)),
|
|
|
|
|
2020-05-09 03:05:46 +01:00
|
|
|
# Conversions to 16 bits would be lossy so they should only be removed if
|
2019-08-05 07:36:38 +01:00
|
|
|
# the instruction was generated by the precision lowering pass.
|
|
|
|
(('f2f32', ('f2fmp', 'a@32')), a),
|
2020-05-09 03:05:46 +01:00
|
|
|
(('i2i32', ('i2imp', 'a@32')), a),
|
2020-09-04 06:51:49 +01:00
|
|
|
(('u2u32', ('i2imp', 'a@32')), a),
|
2019-08-05 07:36:38 +01:00
|
|
|
|
2020-09-04 06:48:35 +01:00
|
|
|
(('i2i32', ('f2imp', 'a@32')), ('f2i32', a)),
|
|
|
|
(('u2u32', ('f2ump', 'a@32')), ('f2u32', a)),
|
|
|
|
(('f2f32', ('i2fmp', 'a@32')), ('i2f32', a)),
|
|
|
|
(('f2f32', ('u2fmp', 'a@32')), ('u2f32', a)),
|
|
|
|
|
2020-06-22 16:12:54 +01:00
|
|
|
# Conversions from float32 to float64 and back can be removed as long as
|
|
|
|
# it doesn't need to be precise, since the conversion may e.g. flush denorms
|
|
|
|
(('~f2f32', ('f2f64', 'a@32')), a),
|
|
|
|
|
2018-01-23 09:35:51 +00:00
|
|
|
(('ffloor', 'a(is_integral)'), a),
|
|
|
|
(('fceil', 'a(is_integral)'), a),
|
|
|
|
(('ftrunc', 'a(is_integral)'), a),
|
2019-08-07 16:54:04 +01:00
|
|
|
# fract(x) = x - floor(x), so fract(NaN) = NaN
|
|
|
|
(('~ffract', 'a(is_integral)'), 0.0),
|
2018-01-23 09:35:51 +00:00
|
|
|
(('fabs', 'a(is_not_negative)'), a),
|
|
|
|
(('iabs', 'a(is_not_negative)'), a),
|
|
|
|
(('fsat', 'a(is_not_positive)'), 0.0),
|
|
|
|
|
2018-01-23 13:11:53 +00:00
|
|
|
(('~fmin', 'a(is_not_negative)', 1.0), ('fsat', a), '!options->lower_fsat'),
|
2019-03-05 20:46:11 +00:00
|
|
|
|
2018-10-25 04:13:45 +01:00
|
|
|
# The result of the multiply must be in [-1, 0], so the result of the ffma
|
|
|
|
# must be in [0, 1].
|
|
|
|
(('flt', ('fadd', ('fmul', ('fsat', a), ('fneg', ('fsat', a))), 1.0), 0.0), False),
|
|
|
|
(('flt', ('fadd', ('fneg', ('fmul', ('fsat', a), ('fsat', a))), 1.0), 0.0), False),
|
|
|
|
(('fmax', ('fadd', ('fmul', ('fsat', a), ('fneg', ('fsat', a))), 1.0), 0.0), ('fadd', ('fmul', ('fsat', a), ('fneg', ('fsat', a))), 1.0)),
|
|
|
|
(('fmax', ('fadd', ('fneg', ('fmul', ('fsat', a), ('fsat', a))), 1.0), 0.0), ('fadd', ('fneg', ('fmul', ('fsat', a), ('fsat', a))), 1.0)),
|
|
|
|
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', 'a(is_not_zero)', 0.0), True),
|
2018-01-23 02:00:55 +00:00
|
|
|
(('feq', 'a(is_not_zero)', 0.0), False),
|
2018-10-11 22:21:42 +01:00
|
|
|
|
2019-08-09 00:48:14 +01:00
|
|
|
# In this chart, + means value > 0 and - means value < 0.
|
|
|
|
#
|
|
|
|
# + >= + -> unknown 0 >= + -> false - >= + -> false
|
|
|
|
# + >= 0 -> true 0 >= 0 -> true - >= 0 -> false
|
|
|
|
# + >= - -> true 0 >= - -> true - >= - -> unknown
|
|
|
|
#
|
|
|
|
# Using grouping conceptually similar to a Karnaugh map...
|
|
|
|
#
|
|
|
|
# (+ >= 0, + >= -, 0 >= 0, 0 >= -) == (is_not_negative >= is_not_positive) -> true
|
|
|
|
# (0 >= +, - >= +) == (is_not_positive >= gt_zero) -> false
|
|
|
|
# (- >= +, - >= 0) == (lt_zero >= is_not_negative) -> false
|
|
|
|
#
|
|
|
|
# The flt / ilt cases just invert the expected result.
|
|
|
|
#
|
2019-08-07 16:54:04 +01:00
|
|
|
# The results expecting true, must be marked imprecise. The results
|
|
|
|
# expecting false are fine because NaN compared >= or < anything is false.
|
2018-10-11 22:21:42 +01:00
|
|
|
|
2021-02-26 15:12:42 +00:00
|
|
|
(('fge', 'a(is_a_number_not_negative)', 'b(is_a_number_not_positive)'), True),
|
|
|
|
(('fge', 'a(is_not_positive)', 'b(is_gt_zero)'), False),
|
|
|
|
(('fge', 'a(is_lt_zero)', 'b(is_not_negative)'), False),
|
2019-08-07 16:54:04 +01:00
|
|
|
|
2021-02-26 15:12:42 +00:00
|
|
|
(('flt', 'a(is_not_negative)', 'b(is_not_positive)'), False),
|
|
|
|
(('flt', 'a(is_a_number_not_positive)', 'b(is_a_number_gt_zero)'), True),
|
|
|
|
(('flt', 'a(is_a_number_lt_zero)', 'b(is_a_number_not_negative)'), True),
|
2018-10-11 22:21:42 +01:00
|
|
|
|
2018-01-23 02:00:55 +00:00
|
|
|
(('ine', 'a(is_not_zero)', 0), True),
|
|
|
|
(('ieq', 'a(is_not_zero)', 0), False),
|
2018-10-11 22:21:42 +01:00
|
|
|
|
2018-01-23 02:00:55 +00:00
|
|
|
(('ige', 'a(is_not_negative)', 'b(is_not_positive)'), True),
|
2019-08-09 00:48:14 +01:00
|
|
|
(('ige', 'a(is_not_positive)', 'b(is_gt_zero)'), False),
|
2018-01-23 02:00:55 +00:00
|
|
|
(('ige', 'a(is_lt_zero)', 'b(is_not_negative)'), False),
|
2018-10-11 22:21:42 +01:00
|
|
|
|
2018-01-23 02:00:55 +00:00
|
|
|
(('ilt', 'a(is_not_negative)', 'b(is_not_positive)'), False),
|
2019-08-09 00:48:14 +01:00
|
|
|
(('ilt', 'a(is_not_positive)', 'b(is_gt_zero)'), True),
|
2018-01-23 02:00:55 +00:00
|
|
|
(('ilt', 'a(is_lt_zero)', 'b(is_not_negative)'), True),
|
2018-10-11 22:21:42 +01:00
|
|
|
|
2018-01-23 02:00:55 +00:00
|
|
|
(('ult', 0, 'a(is_gt_zero)'), True),
|
2020-03-06 02:03:35 +00:00
|
|
|
(('ult', a, 0), False),
|
2018-10-11 22:21:42 +01:00
|
|
|
|
2017-02-15 06:22:36 +00:00
|
|
|
# Packing and then unpacking does nothing
|
|
|
|
(('unpack_64_2x32_split_x', ('pack_64_2x32_split', a, b)), a),
|
|
|
|
(('unpack_64_2x32_split_y', ('pack_64_2x32_split', a, b)), b),
|
2020-06-19 16:24:44 +01:00
|
|
|
(('unpack_64_2x32', ('pack_64_2x32_split', a, b)), ('vec2', a, b)),
|
|
|
|
(('unpack_64_2x32', ('pack_64_2x32', a)), a),
|
2021-04-06 18:42:59 +01:00
|
|
|
(('unpack_double_2x32_dxil', ('pack_double_2x32_dxil', a)), a),
|
2017-02-15 06:22:36 +00:00
|
|
|
(('pack_64_2x32_split', ('unpack_64_2x32_split_x', a),
|
|
|
|
('unpack_64_2x32_split_y', a)), a),
|
2020-06-19 16:24:44 +01:00
|
|
|
(('pack_64_2x32', ('vec2', ('unpack_64_2x32_split_x', a),
|
|
|
|
('unpack_64_2x32_split_y', a))), a),
|
|
|
|
(('pack_64_2x32', ('unpack_64_2x32', a)), a),
|
2021-04-06 18:42:59 +01:00
|
|
|
(('pack_double_2x32_dxil', ('unpack_double_2x32_dxil', a)), a),
|
2017-02-15 06:22:36 +00:00
|
|
|
|
2019-07-13 05:26:48 +01:00
|
|
|
# Comparing two halves of an unpack separately. While this optimization
|
|
|
|
# should be correct for non-constant values, it's less obvious that it's
|
|
|
|
# useful in that case. For constant values, the pack will fold and we're
|
|
|
|
# guaranteed to reduce the whole tree to one instruction.
|
|
|
|
(('iand', ('ieq', ('unpack_32_2x16_split_x', a), '#b'),
|
|
|
|
('ieq', ('unpack_32_2x16_split_y', a), '#c')),
|
|
|
|
('ieq', a, ('pack_32_2x16_split', b, c))),
|
|
|
|
|
nir: Recognize open-coded extract_u8.
Two shaders that appear in Unigine benchmarks (Heaven and Valley) unpack
three bytes from an integer and convert each into a float:
float((val >> 16u) & 0xffu)
float((val >> 8u) & 0xffu)
float((val >> 0u) & 0xffu)
Instead of shifting, masking, and type converting like this:
shr(8) g15<1>UD g25<8,8,1>UD 0x00000010UD
and(8) g16<1>UD g15<8,8,1>UD 0x000000ffUD
mov(8) g17<1>F g16<8,8,1>UD
shr(8) g18<1>UD g25<8,8,1>UD 0x00000008UD
and(8) g19<1>UD g18<8,8,1>UD 0x000000ffUD
mov(8) g20<1>F g19<8,8,1>UD
and(8) g21<1>UD g25<8,8,1>UD 0x000000ffUD
mov(8) g22<1>F g21<8,8,1>UD
i965 can simply extract a byte and convert to float in a single
instruction:
mov(8) g17<1>F g25.2<32,8,4>UB
mov(8) g20<1>F g25.1<32,8,4>UB
mov(8) g22<1>F g25.0<32,8,4>UB
This patch implements the first step: recognizing byte extraction. A
later patch will optimize out the conversion to float.
instructions in affected programs: 28568 -> 27450 (-3.91%)
helped: 7
cycles in affected programs: 210076 -> 203144 (-3.30%)
helped: 7
This patch decreases the number of instructions in the two Unigine
programs by:
#1721: 4520 -> 4374 instructions (-3.23%)
#1706: 3752 -> 3582 instructions (-4.53%)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
2016-01-21 17:09:48 +00:00
|
|
|
# Byte extraction
|
2019-02-28 04:15:32 +00:00
|
|
|
(('ushr', 'a@16', 8), ('extract_u8', a, 1), '!options->lower_extract_byte'),
|
2018-08-14 21:10:22 +01:00
|
|
|
(('ushr', 'a@32', 24), ('extract_u8', a, 3), '!options->lower_extract_byte'),
|
2019-02-28 04:12:46 +00:00
|
|
|
(('ushr', 'a@64', 56), ('extract_u8', a, 7), '!options->lower_extract_byte'),
|
2019-02-28 04:15:32 +00:00
|
|
|
(('ishr', 'a@16', 8), ('extract_i8', a, 1), '!options->lower_extract_byte'),
|
2018-08-14 20:37:39 +01:00
|
|
|
(('ishr', 'a@32', 24), ('extract_i8', a, 3), '!options->lower_extract_byte'),
|
2019-02-28 04:12:46 +00:00
|
|
|
(('ishr', 'a@64', 56), ('extract_i8', a, 7), '!options->lower_extract_byte'),
|
2019-07-11 15:31:50 +01:00
|
|
|
(('iand', 0xff, a), ('extract_u8', a, 0), '!options->lower_extract_byte'),
|
|
|
|
|
2020-03-06 16:00:42 +00:00
|
|
|
(('ubfe', a, 0, 8), ('extract_u8', a, 0), '!options->lower_extract_byte'),
|
|
|
|
(('ubfe', a, 8, 8), ('extract_u8', a, 1), '!options->lower_extract_byte'),
|
|
|
|
(('ubfe', a, 16, 8), ('extract_u8', a, 2), '!options->lower_extract_byte'),
|
|
|
|
(('ubfe', a, 24, 8), ('extract_u8', a, 3), '!options->lower_extract_byte'),
|
|
|
|
(('ibfe', a, 0, 8), ('extract_i8', a, 0), '!options->lower_extract_byte'),
|
|
|
|
(('ibfe', a, 8, 8), ('extract_i8', a, 1), '!options->lower_extract_byte'),
|
|
|
|
(('ibfe', a, 16, 8), ('extract_i8', a, 2), '!options->lower_extract_byte'),
|
|
|
|
(('ibfe', a, 24, 8), ('extract_i8', a, 3), '!options->lower_extract_byte'),
|
|
|
|
|
2020-04-03 14:41:38 +01:00
|
|
|
(('extract_u8', ('extract_i8', a, b), 0), ('extract_u8', a, b)),
|
|
|
|
(('extract_u8', ('extract_u8', a, b), 0), ('extract_u8', a, b)),
|
|
|
|
|
2020-03-06 16:00:42 +00:00
|
|
|
# Word extraction
|
|
|
|
(('ushr', ('ishl', 'a@32', 16), 16), ('extract_u16', a, 0), '!options->lower_extract_word'),
|
|
|
|
(('ushr', 'a@32', 16), ('extract_u16', a, 1), '!options->lower_extract_word'),
|
|
|
|
(('ishr', ('ishl', 'a@32', 16), 16), ('extract_i16', a, 0), '!options->lower_extract_word'),
|
|
|
|
(('ishr', 'a@32', 16), ('extract_i16', a, 1), '!options->lower_extract_word'),
|
|
|
|
(('iand', 0xffff, a), ('extract_u16', a, 0), '!options->lower_extract_word'),
|
|
|
|
|
|
|
|
(('ubfe', a, 0, 16), ('extract_u16', a, 0), '!options->lower_extract_word'),
|
|
|
|
(('ubfe', a, 16, 16), ('extract_u16', a, 1), '!options->lower_extract_word'),
|
|
|
|
(('ibfe', a, 0, 16), ('extract_i16', a, 0), '!options->lower_extract_word'),
|
|
|
|
(('ibfe', a, 16, 16), ('extract_i16', a, 1), '!options->lower_extract_word'),
|
|
|
|
|
2020-04-03 14:41:38 +01:00
|
|
|
(('extract_u16', ('extract_i16', a, b), 0), ('extract_u16', a, b)),
|
|
|
|
(('extract_u16', ('extract_u16', a, b), 0), ('extract_u16', a, b)),
|
|
|
|
|
2020-04-21 12:41:41 +01:00
|
|
|
# Lower pack/unpack
|
|
|
|
(('pack_64_2x32_split', a, b), ('ior', ('u2u64', a), ('ishl', ('u2u64', b), 32)), 'options->lower_pack_64_2x32_split'),
|
|
|
|
(('pack_32_2x16_split', a, b), ('ior', ('u2u32', a), ('ishl', ('u2u32', b), 16)), 'options->lower_pack_32_2x16_split'),
|
|
|
|
(('unpack_64_2x32_split_x', a), ('u2u32', a), 'options->lower_unpack_64_2x32_split'),
|
|
|
|
(('unpack_64_2x32_split_y', a), ('u2u32', ('ushr', a, 32)), 'options->lower_unpack_64_2x32_split'),
|
|
|
|
(('unpack_32_2x16_split_x', a), ('u2u16', a), 'options->lower_unpack_32_2x16_split'),
|
|
|
|
(('unpack_32_2x16_split_y', a), ('u2u16', ('ushr', a, 16)), 'options->lower_unpack_32_2x16_split'),
|
|
|
|
|
2019-07-11 15:31:50 +01:00
|
|
|
# Useless masking before unpacking
|
|
|
|
(('unpack_half_2x16_split_x', ('iand', a, 0xffff)), ('unpack_half_2x16_split_x', a)),
|
|
|
|
(('unpack_32_2x16_split_x', ('iand', a, 0xffff)), ('unpack_32_2x16_split_x', a)),
|
|
|
|
(('unpack_64_2x32_split_x', ('iand', a, 0xffffffff)), ('unpack_64_2x32_split_x', a)),
|
|
|
|
(('unpack_half_2x16_split_y', ('iand', a, 0xffff0000)), ('unpack_half_2x16_split_y', a)),
|
|
|
|
(('unpack_32_2x16_split_y', ('iand', a, 0xffff0000)), ('unpack_32_2x16_split_y', a)),
|
|
|
|
(('unpack_64_2x32_split_y', ('iand', a, 0xffffffff00000000)), ('unpack_64_2x32_split_y', a)),
|
2019-10-09 15:27:07 +01:00
|
|
|
|
2020-04-01 00:57:03 +01:00
|
|
|
(('unpack_half_2x16_split_x', ('extract_u16', a, 0)), ('unpack_half_2x16_split_x', a)),
|
|
|
|
(('unpack_half_2x16_split_x', ('extract_u16', a, 1)), ('unpack_half_2x16_split_y', a)),
|
nir/opt_algebraic: optimize unpack_half_2x16_split_x(ushr, a, 16)
Same as extract_u16(a, 1)
Totals from 2021 (1.48% of 136546) affected shaders (RAVEN):
VGPRs: 129516 -> 129524 (+0.01%); split: -0.00%, +0.01%
CodeSize: 12485704 -> 12486600 (+0.01%); split: -0.00%, +0.01%
Instrs: 2435041 -> 2434999 (-0.00%); split: -0.00%, +0.00%
Cycles: 20952552 -> 20952624 (+0.00%); split: -0.00%, +0.00%
VMEM: 374492 -> 374212 (-0.07%); split: +0.01%, -0.08%
SMEM: 123309 -> 123291 (-0.01%); split: +0.00%, -0.02%
VClause: 64156 -> 64164 (+0.01%)
Copies: 191620 -> 191616 (-0.00%); split: -0.03%, +0.03%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6777>
2020-09-18 13:50:25 +01:00
|
|
|
(('unpack_half_2x16_split_x', ('ushr', a, 16)), ('unpack_half_2x16_split_y', a)),
|
2020-04-01 00:57:03 +01:00
|
|
|
(('unpack_32_2x16_split_x', ('extract_u16', a, 0)), ('unpack_32_2x16_split_x', a)),
|
|
|
|
(('unpack_32_2x16_split_x', ('extract_u16', a, 1)), ('unpack_32_2x16_split_y', a)),
|
|
|
|
|
2019-10-09 15:27:07 +01:00
|
|
|
# Optimize half packing
|
|
|
|
(('ishl', ('pack_half_2x16', ('vec2', a, 0)), 16), ('pack_half_2x16', ('vec2', 0, a))),
|
2020-04-02 20:14:12 +01:00
|
|
|
(('ushr', ('pack_half_2x16', ('vec2', 0, a)), 16), ('pack_half_2x16', ('vec2', a, 0))),
|
2019-10-09 15:27:07 +01:00
|
|
|
|
|
|
|
(('iadd', ('pack_half_2x16', ('vec2', a, 0)), ('pack_half_2x16', ('vec2', 0, b))),
|
|
|
|
('pack_half_2x16', ('vec2', a, b))),
|
|
|
|
(('ior', ('pack_half_2x16', ('vec2', a, 0)), ('pack_half_2x16', ('vec2', 0, b))),
|
|
|
|
('pack_half_2x16', ('vec2', a, b))),
|
2020-04-02 20:20:57 +01:00
|
|
|
|
|
|
|
(('ishl', ('pack_half_2x16_split', a, 0), 16), ('pack_half_2x16_split', 0, a)),
|
|
|
|
(('ushr', ('pack_half_2x16_split', 0, a), 16), ('pack_half_2x16_split', a, 0)),
|
|
|
|
(('extract_u16', ('pack_half_2x16_split', 0, a), 1), ('pack_half_2x16_split', a, 0)),
|
|
|
|
|
|
|
|
(('iadd', ('pack_half_2x16_split', a, 0), ('pack_half_2x16_split', 0, b)), ('pack_half_2x16_split', a, b)),
|
|
|
|
(('ior', ('pack_half_2x16_split', a, 0), ('pack_half_2x16_split', 0, b)), ('pack_half_2x16_split', a, b)),
|
2019-08-06 21:11:56 +01:00
|
|
|
])
|
2019-02-28 03:52:12 +00:00
|
|
|
|
2019-02-28 04:08:38 +00:00
|
|
|
# After the ('extract_u8', a, 0) pattern, above, triggers, there will be
|
|
|
|
# patterns like those below.
|
2019-02-28 03:52:12 +00:00
|
|
|
for op in ('ushr', 'ishr'):
|
|
|
|
optimizations.extend([(('extract_u8', (op, 'a@16', 8), 0), ('extract_u8', a, 1))])
|
|
|
|
optimizations.extend([(('extract_u8', (op, 'a@32', 8 * i), 0), ('extract_u8', a, i)) for i in range(1, 4)])
|
|
|
|
optimizations.extend([(('extract_u8', (op, 'a@64', 8 * i), 0), ('extract_u8', a, i)) for i in range(1, 8)])
|
|
|
|
|
|
|
|
optimizations.extend([(('extract_u8', ('extract_u16', a, 1), 0), ('extract_u8', a, 2))])
|
nir: Recognize open-coded extract_u8.
Two shaders that appear in Unigine benchmarks (Heaven and Valley) unpack
three bytes from an integer and convert each into a float:
float((val >> 16u) & 0xffu)
float((val >> 8u) & 0xffu)
float((val >> 0u) & 0xffu)
Instead of shifting, masking, and type converting like this:
shr(8) g15<1>UD g25<8,8,1>UD 0x00000010UD
and(8) g16<1>UD g15<8,8,1>UD 0x000000ffUD
mov(8) g17<1>F g16<8,8,1>UD
shr(8) g18<1>UD g25<8,8,1>UD 0x00000008UD
and(8) g19<1>UD g18<8,8,1>UD 0x000000ffUD
mov(8) g20<1>F g19<8,8,1>UD
and(8) g21<1>UD g25<8,8,1>UD 0x000000ffUD
mov(8) g22<1>F g21<8,8,1>UD
i965 can simply extract a byte and convert to float in a single
instruction:
mov(8) g17<1>F g25.2<32,8,4>UB
mov(8) g20<1>F g25.1<32,8,4>UB
mov(8) g22<1>F g25.0<32,8,4>UB
This patch implements the first step: recognizing byte extraction. A
later patch will optimize out the conversion to float.
instructions in affected programs: 28568 -> 27450 (-3.91%)
helped: 7
cycles in affected programs: 210076 -> 203144 (-3.30%)
helped: 7
This patch decreases the number of instructions in the two Unigine
programs by:
#1721: 4520 -> 4374 instructions (-3.23%)
#1706: 3752 -> 3582 instructions (-4.53%)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
2016-01-21 17:09:48 +00:00
|
|
|
|
2019-02-28 04:08:38 +00:00
|
|
|
# After the ('extract_[iu]8', a, 3) patterns, above, trigger, there will be
|
|
|
|
# patterns like those below.
|
2019-02-28 03:52:12 +00:00
|
|
|
for op in ('extract_u8', 'extract_i8'):
|
2019-02-28 04:15:32 +00:00
|
|
|
optimizations.extend([((op, ('ishl', 'a@16', 8), 1), (op, a, 0))])
|
2019-02-28 03:52:12 +00:00
|
|
|
optimizations.extend([((op, ('ishl', 'a@32', 24 - 8 * i), 3), (op, a, i)) for i in range(2, -1, -1)])
|
2019-02-28 04:12:46 +00:00
|
|
|
optimizations.extend([((op, ('ishl', 'a@64', 56 - 8 * i), 7), (op, a, i)) for i in range(6, -1, -1)])
|
2019-02-28 03:52:12 +00:00
|
|
|
|
|
|
|
optimizations.extend([
|
2015-01-28 18:52:53 +00:00
|
|
|
# Subtracts
|
2021-06-18 15:28:59 +01:00
|
|
|
(('ussub_4x8_vc4', a, 0), a),
|
|
|
|
(('ussub_4x8_vc4', a, ~0), 0),
|
2019-09-25 15:20:09 +01:00
|
|
|
# Lower all Subtractions first - they can get recombined later
|
|
|
|
(('fsub', a, b), ('fadd', a, ('fneg', b))),
|
|
|
|
(('isub', a, b), ('iadd', a, ('ineg', b))),
|
2018-09-11 23:38:36 +01:00
|
|
|
(('uabs_usub', a, b), ('bcsel', ('ult', a, b), ('ineg', ('isub', a, b)), ('isub', a, b))),
|
|
|
|
# This is correct. We don't need isub_sat because the result type is unsigned, so it cannot overflow.
|
|
|
|
(('uabs_isub', a, b), ('bcsel', ('ilt', a, b), ('ineg', ('isub', a, b)), ('isub', a, b))),
|
2016-01-06 23:30:38 +00:00
|
|
|
|
2016-02-22 23:16:49 +00:00
|
|
|
# Propagate negation up multiplication chains
|
2018-10-23 22:30:41 +01:00
|
|
|
(('fmul(is_used_by_non_fsat)', ('fneg', a), b), ('fneg', ('fmul', a, b))),
|
2016-03-31 03:18:16 +01:00
|
|
|
(('imul', ('ineg', a), b), ('ineg', ('imul', a, b))),
|
2016-02-22 23:16:49 +00:00
|
|
|
|
2017-01-12 02:10:55 +00:00
|
|
|
# Propagate constants up multiplication chains
|
|
|
|
(('~fmul(is_used_once)', ('fmul(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), '#c'), ('fmul', ('fmul', a, c), b)),
|
|
|
|
(('imul(is_used_once)', ('imul(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), '#c'), ('imul', ('imul', a, c), b)),
|
2020-06-19 11:30:27 +01:00
|
|
|
# Prefer moving out a multiplication for more MAD/FMA-friendly code
|
|
|
|
(('~fadd(is_used_once)', ('fadd(is_used_once)', 'a(is_not_const)', 'b(is_fmul)'), '#c'), ('fadd', ('fadd', a, c), b)),
|
2017-01-12 02:10:55 +00:00
|
|
|
(('~fadd(is_used_once)', ('fadd(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), '#c'), ('fadd', ('fadd', a, c), b)),
|
|
|
|
(('iadd(is_used_once)', ('iadd(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), '#c'), ('iadd', ('iadd', a, c), b)),
|
|
|
|
|
2016-04-07 06:34:39 +01:00
|
|
|
# Reassociate constants in add/mul chains so they can be folded together.
|
2017-01-12 02:10:55 +00:00
|
|
|
# For now, we mostly only handle cases where the constants are separated by
|
2016-04-07 06:34:39 +01:00
|
|
|
# a single non-constant. We could do better eventually.
|
2019-02-15 22:52:20 +00:00
|
|
|
(('~fmul', '#a', ('fmul', 'b(is_not_const)', '#c')), ('fmul', ('fmul', a, c), b)),
|
|
|
|
(('imul', '#a', ('imul', 'b(is_not_const)', '#c')), ('imul', ('imul', a, c), b)),
|
|
|
|
(('~fadd', '#a', ('fadd', 'b(is_not_const)', '#c')), ('fadd', ('fadd', a, c), b)),
|
|
|
|
(('~fadd', '#a', ('fneg', ('fadd', 'b(is_not_const)', '#c'))), ('fadd', ('fadd', a, ('fneg', c)), ('fneg', b))),
|
|
|
|
(('iadd', '#a', ('iadd', 'b(is_not_const)', '#c')), ('iadd', ('iadd', a, c), b)),
|
2020-03-07 00:05:27 +00:00
|
|
|
(('iand', '#a', ('iand', 'b(is_not_const)', '#c')), ('iand', ('iand', a, c), b)),
|
|
|
|
(('ior', '#a', ('ior', 'b(is_not_const)', '#c')), ('ior', ('ior', a, c), b)),
|
|
|
|
(('ixor', '#a', ('ixor', 'b(is_not_const)', '#c')), ('ixor', ('ixor', a, c), b)),
|
2016-04-07 06:34:39 +01:00
|
|
|
|
2019-06-13 00:48:21 +01:00
|
|
|
# Drop mul-div by the same value when there's no wrapping.
|
|
|
|
(('idiv', ('imul(no_signed_wrap)', a, b), b), a),
|
|
|
|
|
2017-06-30 23:48:19 +01:00
|
|
|
# By definition...
|
|
|
|
(('bcsel', ('ige', ('find_lsb', a), 0), ('find_lsb', a), -1), ('find_lsb', a)),
|
|
|
|
(('bcsel', ('ige', ('ifind_msb', a), 0), ('ifind_msb', a), -1), ('ifind_msb', a)),
|
|
|
|
(('bcsel', ('ige', ('ufind_msb', a), 0), ('ufind_msb', a), -1), ('ufind_msb', a)),
|
|
|
|
|
|
|
|
(('bcsel', ('ine', a, 0), ('find_lsb', a), -1), ('find_lsb', a)),
|
|
|
|
(('bcsel', ('ine', a, 0), ('ifind_msb', a), -1), ('ifind_msb', a)),
|
|
|
|
(('bcsel', ('ine', a, 0), ('ufind_msb', a), -1), ('ufind_msb', a)),
|
|
|
|
|
|
|
|
(('bcsel', ('ine', a, -1), ('ifind_msb', a), -1), ('ifind_msb', a)),
|
|
|
|
|
2020-04-29 15:38:54 +01:00
|
|
|
(('~fmul', ('bcsel(is_used_once)', c, -1.0, 1.0), b), ('bcsel', c, ('fneg', b), b)),
|
|
|
|
(('~fmul', ('bcsel(is_used_once)', c, 1.0, -1.0), b), ('bcsel', c, b, ('fneg', b))),
|
2020-04-30 10:58:08 +01:00
|
|
|
(('~bcsel', ('flt', a, 0.0), ('fneg', a), a), ('fabs', a)),
|
2020-04-29 15:38:54 +01:00
|
|
|
|
nir/algebraic: fold some nested bcsel
Totals from 14266 (10.62% of 134368) affected shaders (Polaris):
SGPRs: 761756 -> 762732 (+0.13%); split: -0.00%, +0.13%
VGPRs: 430392 -> 430924 (+0.12%); split: -0.05%, +0.17%
SpillSGPRs: 4652 -> 4628 (-0.52%); split: -0.60%, +0.09%
CodeSize: 30133000 -> 29949780 (-0.61%); split: -0.66%, +0.05%
MaxWaves: 102122 -> 102111 (-0.01%); split: +0.00%, -0.01%
Instrs: 5845085 -> 5841668 (-0.06%); split: -0.08%, +0.03%
Cycles: 69033140 -> 68889188 (-0.21%); split: -0.22%, +0.01%
VMEM: 8479021 -> 8474978 (-0.05%); split: +0.03%, -0.08%
SMEM: 831437 -> 830464 (-0.12%); split: +0.06%, -0.18%
VClause: 105411 -> 105410 (-0.00%); split: -0.01%, +0.01%
SClause: 327727 -> 327780 (+0.02%); split: -0.00%, +0.02%
Copies: 372704 -> 373306 (+0.16%); split: -0.16%, +0.32%
Branches: 112260 -> 112269 (+0.01%); split: -0.00%, +0.01%
PreSGPRs: 433308 -> 433631 (+0.07%); split: -0.01%, +0.09%
PreVGPRs: 397888 -> 397905 (+0.00%); split: -0.01%, +0.01%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4830>
2020-07-15 18:31:22 +01:00
|
|
|
(('bcsel', a, ('bcsel', b, c, d), d), ('bcsel', ('iand', a, b), c, d)),
|
|
|
|
(('bcsel', a, b, ('bcsel', c, b, d)), ('bcsel', ('ior', a, c), b, d)),
|
|
|
|
|
2016-01-06 23:30:38 +00:00
|
|
|
# Misc. lowering
|
2020-03-10 10:50:30 +00:00
|
|
|
(('fmod', a, b), ('fsub', a, ('fmul', b, ('ffloor', ('fdiv', a, b)))), 'options->lower_fmod'),
|
2019-06-03 21:18:55 +01:00
|
|
|
(('frem', a, b), ('fsub', a, ('fmul', b, ('ftrunc', ('fdiv', a, b)))), 'options->lower_fmod'),
|
2020-06-22 23:01:00 +01:00
|
|
|
(('uadd_carry', a, b), ('b2i', ('ult', ('iadd', a, b), a)), 'options->lower_uadd_carry'),
|
2016-04-26 04:59:06 +01:00
|
|
|
(('usub_borrow@32', a, b), ('b2i', ('ult', a, b)), 'options->lower_usub_borrow'),
|
2016-01-13 19:08:37 +00:00
|
|
|
|
|
|
|
(('bitfield_insert', 'base', 'insert', 'offset', 'bits'),
|
2019-05-02 14:28:59 +01:00
|
|
|
('bcsel', ('ult', 31, 'bits'), 'insert',
|
2016-01-13 19:08:37 +00:00
|
|
|
('bfi', ('bfm', 'bits', 'offset'), 'insert', 'base')),
|
|
|
|
'options->lower_bitfield_insert'),
|
2018-07-12 14:02:27 +01:00
|
|
|
(('ihadd', a, b), ('iadd', ('iand', a, b), ('ishr', ('ixor', a, b), 1)), 'options->lower_hadd'),
|
|
|
|
(('uhadd', a, b), ('iadd', ('iand', a, b), ('ushr', ('ixor', a, b), 1)), 'options->lower_hadd'),
|
|
|
|
(('irhadd', a, b), ('isub', ('ior', a, b), ('ishr', ('ixor', a, b), 1)), 'options->lower_hadd'),
|
|
|
|
(('urhadd', a, b), ('isub', ('ior', a, b), ('ushr', ('ixor', a, b), 1)), 'options->lower_hadd'),
|
2018-09-19 09:17:09 +01:00
|
|
|
(('ihadd@64', a, b), ('iadd', ('iand', a, b), ('ishr', ('ixor', a, b), 1)), 'options->lower_hadd64 || (options->lower_int64_options & nir_lower_iadd64) != 0'),
|
|
|
|
(('uhadd@64', a, b), ('iadd', ('iand', a, b), ('ushr', ('ixor', a, b), 1)), 'options->lower_hadd64 || (options->lower_int64_options & nir_lower_iadd64) != 0'),
|
|
|
|
(('irhadd@64', a, b), ('isub', ('ior', a, b), ('ishr', ('ixor', a, b), 1)), 'options->lower_hadd64 || (options->lower_int64_options & nir_lower_iadd64) != 0'),
|
|
|
|
(('urhadd@64', a, b), ('isub', ('ior', a, b), ('ushr', ('ixor', a, b), 1)), 'options->lower_hadd64 || (options->lower_int64_options & nir_lower_iadd64) != 0'),
|
|
|
|
|
2019-11-27 20:55:27 +00:00
|
|
|
(('uadd_sat@64', a, b), ('bcsel', ('ult', ('iadd', a, b), a), -1, ('iadd', a, b)), 'options->lower_add_sat || (options->lower_int64_options & nir_lower_iadd64) != 0'),
|
2018-07-12 14:02:27 +01:00
|
|
|
(('uadd_sat', a, b), ('bcsel', ('ult', ('iadd', a, b), a), -1, ('iadd', a, b)), 'options->lower_add_sat'),
|
|
|
|
(('usub_sat', a, b), ('bcsel', ('ult', a, b), 0, ('isub', a, b)), 'options->lower_add_sat'),
|
2018-09-19 09:17:31 +01:00
|
|
|
(('usub_sat@64', a, b), ('bcsel', ('ult', a, b), 0, ('isub', a, b)), 'options->lower_usub_sat64 || (options->lower_int64_options & nir_lower_iadd64) != 0'),
|
2016-01-13 19:09:11 +00:00
|
|
|
|
2019-11-27 21:22:38 +00:00
|
|
|
# int64_t sum = a + b;
|
|
|
|
#
|
|
|
|
# if (a < 0 && b < 0 && a < sum)
|
|
|
|
# sum = INT64_MIN;
|
|
|
|
# } else if (a >= 0 && b >= 0 && sum < a)
|
|
|
|
# sum = INT64_MAX;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# A couple optimizations are applied.
|
|
|
|
#
|
|
|
|
# 1. a < sum => sum >= 0. This replacement works because it is known that
|
|
|
|
# a < 0 and b < 0, so sum should also be < 0 unless there was
|
|
|
|
# underflow.
|
|
|
|
#
|
|
|
|
# 2. sum < a => sum < 0. This replacement works because it is known that
|
|
|
|
# a >= 0 and b >= 0, so sum should also be >= 0 unless there was
|
|
|
|
# overflow.
|
|
|
|
#
|
|
|
|
# 3. Invert the second if-condition and swap the order of parameters for
|
|
|
|
# the bcsel. !(a >= 0 && b >= 0 && sum < 0) becomes !(a >= 0) || !(b >=
|
|
|
|
# 0) || !(sum < 0), and that becomes (a < 0) || (b < 0) || (sum >= 0)
|
|
|
|
#
|
|
|
|
# On Intel Gen11, this saves ~11 instructions.
|
|
|
|
(('iadd_sat@64', a, b), ('bcsel',
|
|
|
|
('iand', ('iand', ('ilt', a, 0), ('ilt', b, 0)), ('ige', ('iadd', a, b), 0)),
|
|
|
|
0x8000000000000000,
|
|
|
|
('bcsel',
|
|
|
|
('ior', ('ior', ('ilt', a, 0), ('ilt', b, 0)), ('ige', ('iadd', a, b), 0)),
|
|
|
|
('iadd', a, b),
|
|
|
|
0x7fffffffffffffff)),
|
|
|
|
'(options->lower_int64_options & nir_lower_iadd64) != 0'),
|
|
|
|
|
|
|
|
# int64_t sum = a - b;
|
|
|
|
#
|
|
|
|
# if (a < 0 && b >= 0 && a < sum)
|
|
|
|
# sum = INT64_MIN;
|
|
|
|
# } else if (a >= 0 && b < 0 && a >= sum)
|
|
|
|
# sum = INT64_MAX;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# Optimizations similar to the iadd_sat case are applied here.
|
|
|
|
(('isub_sat@64', a, b), ('bcsel',
|
|
|
|
('iand', ('iand', ('ilt', a, 0), ('ige', b, 0)), ('ige', ('isub', a, b), 0)),
|
|
|
|
0x8000000000000000,
|
|
|
|
('bcsel',
|
|
|
|
('ior', ('ior', ('ilt', a, 0), ('ige', b, 0)), ('ige', ('isub', a, b), 0)),
|
|
|
|
('isub', a, b),
|
|
|
|
0x7fffffffffffffff)),
|
|
|
|
'(options->lower_int64_options & nir_lower_iadd64) != 0'),
|
|
|
|
|
2019-11-28 00:26:03 +00:00
|
|
|
# These are done here instead of in the backend because the int64 lowering
|
|
|
|
# pass will make a mess of the patterns. The first patterns are
|
|
|
|
# conditioned on nir_lower_minmax64 because it was not clear that it was
|
|
|
|
# always an improvement on platforms that have real int64 support. No
|
|
|
|
# shaders in shader-db hit this, so it was hard to say one way or the
|
|
|
|
# other.
|
|
|
|
(('ilt', ('imax(is_used_once)', 'a@64', 'b@64'), 0), ('ilt', ('imax', ('unpack_64_2x32_split_y', a), ('unpack_64_2x32_split_y', b)), 0), '(options->lower_int64_options & nir_lower_minmax64) != 0'),
|
|
|
|
(('ilt', ('imin(is_used_once)', 'a@64', 'b@64'), 0), ('ilt', ('imin', ('unpack_64_2x32_split_y', a), ('unpack_64_2x32_split_y', b)), 0), '(options->lower_int64_options & nir_lower_minmax64) != 0'),
|
|
|
|
(('ige', ('imax(is_used_once)', 'a@64', 'b@64'), 0), ('ige', ('imax', ('unpack_64_2x32_split_y', a), ('unpack_64_2x32_split_y', b)), 0), '(options->lower_int64_options & nir_lower_minmax64) != 0'),
|
|
|
|
(('ige', ('imin(is_used_once)', 'a@64', 'b@64'), 0), ('ige', ('imin', ('unpack_64_2x32_split_y', a), ('unpack_64_2x32_split_y', b)), 0), '(options->lower_int64_options & nir_lower_minmax64) != 0'),
|
|
|
|
(('ilt', 'a@64', 0), ('ilt', ('unpack_64_2x32_split_y', a), 0), '(options->lower_int64_options & nir_lower_icmp64) != 0'),
|
|
|
|
(('ige', 'a@64', 0), ('ige', ('unpack_64_2x32_split_y', a), 0), '(options->lower_int64_options & nir_lower_icmp64) != 0'),
|
|
|
|
|
|
|
|
(('ine', 'a@64', 0), ('ine', ('ior', ('unpack_64_2x32_split_x', a), ('unpack_64_2x32_split_y', a)), 0), '(options->lower_int64_options & nir_lower_icmp64) != 0'),
|
|
|
|
(('ieq', 'a@64', 0), ('ieq', ('ior', ('unpack_64_2x32_split_x', a), ('unpack_64_2x32_split_y', a)), 0), '(options->lower_int64_options & nir_lower_icmp64) != 0'),
|
|
|
|
# 0u < uint(a) <=> uint(a) != 0u
|
|
|
|
(('ult', 0, 'a@64'), ('ine', ('ior', ('unpack_64_2x32_split_x', a), ('unpack_64_2x32_split_y', a)), 0), '(options->lower_int64_options & nir_lower_icmp64) != 0'),
|
|
|
|
|
2018-05-02 22:13:23 +01:00
|
|
|
# Alternative lowering that doesn't rely on bfi.
|
|
|
|
(('bitfield_insert', 'base', 'insert', 'offset', 'bits'),
|
2019-06-27 22:29:37 +01:00
|
|
|
('bcsel', ('ult', 31, 'bits'),
|
|
|
|
'insert',
|
|
|
|
(('ior',
|
|
|
|
('iand', 'base', ('inot', ('ishl', ('isub', ('ishl', 1, 'bits'), 1), 'offset'))),
|
|
|
|
('iand', ('ishl', 'insert', 'offset'), ('ishl', ('isub', ('ishl', 1, 'bits'), 1), 'offset'))))),
|
2018-05-02 22:13:23 +01:00
|
|
|
'options->lower_bitfield_insert_to_shifts'),
|
|
|
|
|
2019-06-13 10:34:01 +01:00
|
|
|
# Alternative lowering that uses bitfield_select.
|
|
|
|
(('bitfield_insert', 'base', 'insert', 'offset', 'bits'),
|
|
|
|
('bcsel', ('ult', 31, 'bits'), 'insert',
|
|
|
|
('bitfield_select', ('bfm', 'bits', 'offset'), ('ishl', 'insert', 'offset'), 'base')),
|
|
|
|
'options->lower_bitfield_insert_to_bitfield_select'),
|
|
|
|
|
2016-01-13 19:09:11 +00:00
|
|
|
(('ibitfield_extract', 'value', 'offset', 'bits'),
|
2019-05-02 14:28:59 +01:00
|
|
|
('bcsel', ('ult', 31, 'bits'), 'value',
|
2016-01-13 19:09:11 +00:00
|
|
|
('ibfe', 'value', 'offset', 'bits')),
|
|
|
|
'options->lower_bitfield_extract'),
|
|
|
|
|
|
|
|
(('ubitfield_extract', 'value', 'offset', 'bits'),
|
|
|
|
('bcsel', ('ult', 31, 'bits'), 'value',
|
|
|
|
('ubfe', 'value', 'offset', 'bits')),
|
|
|
|
'options->lower_bitfield_extract'),
|
2016-01-21 17:09:29 +00:00
|
|
|
|
nir/algebraic: optimize bitfield_select(a, b, 0) to iand(a, b)
(src0 & src1) | (~src0 & src2) to (src0 & src1).
fossils-db (Polaris10):
Totals from 873 (0.63% of 138014) affected shaders:
SGPRs: 33781 -> 33733 (-0.14%)
VGPRs: 37704 -> 37520 (-0.49%); split: -0.51%, +0.02%
CodeSize: 3861460 -> 3853424 (-0.21%); split: -0.21%, +0.00%
MaxWaves: 5306 -> 5305 (-0.02%)
Instrs: 743798 -> 743486 (-0.04%); split: -0.04%, +0.00%
Cycles: 10962244 -> 10960936 (-0.01%); split: -0.01%, +0.00%
VMEM: 128309 -> 128350 (+0.03%); split: +0.33%, -0.30%
SMEM: 44797 -> 44113 (-1.53%); split: +0.02%, -1.54%
Copies: 71875 -> 71674 (-0.28%); split: -0.31%, +0.03%
PreSGPRs: 23484 -> 23479 (-0.02%)
PreVGPRs: 34582 -> 34529 (-0.15%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7479>
2020-11-06 15:43:41 +00:00
|
|
|
# (src0 & src1) | (~src0 & src2). Constant fold if src2 is 0.
|
|
|
|
(('bitfield_select', a, b, 0), ('iand', a, b)),
|
2020-11-10 13:10:35 +00:00
|
|
|
(('bitfield_select', a, ('iand', a, b), c), ('bitfield_select', a, b, c)),
|
nir/algebraic: optimize bitfield_select(a, b, 0) to iand(a, b)
(src0 & src1) | (~src0 & src2) to (src0 & src1).
fossils-db (Polaris10):
Totals from 873 (0.63% of 138014) affected shaders:
SGPRs: 33781 -> 33733 (-0.14%)
VGPRs: 37704 -> 37520 (-0.49%); split: -0.51%, +0.02%
CodeSize: 3861460 -> 3853424 (-0.21%); split: -0.21%, +0.00%
MaxWaves: 5306 -> 5305 (-0.02%)
Instrs: 743798 -> 743486 (-0.04%); split: -0.04%, +0.00%
Cycles: 10962244 -> 10960936 (-0.01%); split: -0.01%, +0.00%
VMEM: 128309 -> 128350 (+0.03%); split: +0.33%, -0.30%
SMEM: 44797 -> 44113 (-1.53%); split: +0.02%, -1.54%
Copies: 71875 -> 71674 (-0.28%); split: -0.31%, +0.03%
PreSGPRs: 23484 -> 23479 (-0.02%)
PreVGPRs: 34582 -> 34529 (-0.15%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7479>
2020-11-06 15:43:41 +00:00
|
|
|
|
2019-01-25 12:56:49 +00:00
|
|
|
# Note that these opcodes are defined to only use the five least significant bits of 'offset' and 'bits'
|
|
|
|
(('ubfe', 'value', 'offset', ('iand', 31, 'bits')), ('ubfe', 'value', 'offset', 'bits')),
|
|
|
|
(('ubfe', 'value', ('iand', 31, 'offset'), 'bits'), ('ubfe', 'value', 'offset', 'bits')),
|
|
|
|
(('ibfe', 'value', 'offset', ('iand', 31, 'bits')), ('ibfe', 'value', 'offset', 'bits')),
|
|
|
|
(('ibfe', 'value', ('iand', 31, 'offset'), 'bits'), ('ibfe', 'value', 'offset', 'bits')),
|
|
|
|
(('bfm', 'bits', ('iand', 31, 'offset')), ('bfm', 'bits', 'offset')),
|
|
|
|
(('bfm', ('iand', 31, 'bits'), 'offset'), ('bfm', 'bits', 'offset')),
|
|
|
|
|
2020-03-05 21:32:07 +00:00
|
|
|
# Section 8.8 (Integer Functions) of the GLSL 4.60 spec says:
|
|
|
|
#
|
|
|
|
# If bits is zero, the result will be zero.
|
|
|
|
#
|
|
|
|
# These patterns prevent other patterns from generating invalid results
|
|
|
|
# when count is zero.
|
|
|
|
(('ubfe', a, b, 0), 0),
|
|
|
|
(('ibfe', a, b, 0), 0),
|
|
|
|
|
|
|
|
(('ubfe', a, 0, '#b'), ('iand', a, ('ushr', 0xffffffff, ('ineg', b)))),
|
|
|
|
|
|
|
|
(('b2i32', ('i2b', ('ubfe', a, b, 1))), ('ubfe', a, b, 1)),
|
|
|
|
(('b2i32', ('i2b', ('ibfe', a, b, 1))), ('ubfe', a, b, 1)), # ubfe in the replacement is correct
|
|
|
|
(('ine', ('ibfe(is_used_once)', a, '#b', '#c'), 0), ('ine', ('iand', a, ('ishl', ('ushr', 0xffffffff, ('ineg', c)), b)), 0)),
|
|
|
|
(('ieq', ('ibfe(is_used_once)', a, '#b', '#c'), 0), ('ieq', ('iand', a, ('ishl', ('ushr', 0xffffffff, ('ineg', c)), b)), 0)),
|
|
|
|
(('ine', ('ubfe(is_used_once)', a, '#b', '#c'), 0), ('ine', ('iand', a, ('ishl', ('ushr', 0xffffffff, ('ineg', c)), b)), 0)),
|
|
|
|
(('ieq', ('ubfe(is_used_once)', a, '#b', '#c'), 0), ('ieq', ('iand', a, ('ishl', ('ushr', 0xffffffff, ('ineg', c)), b)), 0)),
|
|
|
|
|
2018-05-02 21:02:21 +01:00
|
|
|
(('ibitfield_extract', 'value', 'offset', 'bits'),
|
|
|
|
('bcsel', ('ieq', 0, 'bits'),
|
|
|
|
0,
|
|
|
|
('ishr',
|
|
|
|
('ishl', 'value', ('isub', ('isub', 32, 'bits'), 'offset')),
|
|
|
|
('isub', 32, 'bits'))),
|
|
|
|
'options->lower_bitfield_extract_to_shifts'),
|
|
|
|
|
|
|
|
(('ubitfield_extract', 'value', 'offset', 'bits'),
|
|
|
|
('iand',
|
|
|
|
('ushr', 'value', 'offset'),
|
|
|
|
('bcsel', ('ieq', 'bits', 32),
|
|
|
|
0xffffffff,
|
2019-01-26 08:12:46 +00:00
|
|
|
('isub', ('ishl', 1, 'bits'), 1))),
|
2018-05-02 21:02:21 +01:00
|
|
|
'options->lower_bitfield_extract_to_shifts'),
|
|
|
|
|
2018-05-04 21:33:47 +01:00
|
|
|
(('ifind_msb', 'value'),
|
|
|
|
('ufind_msb', ('bcsel', ('ilt', 'value', 0), ('inot', 'value'), 'value')),
|
|
|
|
'options->lower_ifind_msb'),
|
|
|
|
|
2021-03-10 08:38:18 +00:00
|
|
|
(('ifind_msb', 'value'),
|
|
|
|
('bcsel', ('ige', ('ifind_msb_rev', 'value'), 0),
|
|
|
|
('isub', 31, ('ifind_msb_rev', 'value')),
|
|
|
|
('ifind_msb_rev', 'value')),
|
|
|
|
'options->lower_find_msb_to_reverse'),
|
|
|
|
|
|
|
|
(('ufind_msb', 'value'),
|
|
|
|
('bcsel', ('ige', ('ufind_msb_rev', 'value'), 0),
|
|
|
|
('isub', 31, ('ufind_msb_rev', 'value')),
|
|
|
|
('ufind_msb_rev', 'value')),
|
|
|
|
'options->lower_find_msb_to_reverse'),
|
|
|
|
|
2018-05-04 22:02:55 +01:00
|
|
|
(('find_lsb', 'value'),
|
|
|
|
('ufind_msb', ('iand', 'value', ('ineg', 'value'))),
|
|
|
|
'options->lower_find_lsb'),
|
|
|
|
|
nir: Shift count for shift opcodes is always 32-bits
Previously both sources were unsized. This caused problems when the
thing being shifted was 64-bit but the shift count was 32-bit. The
expectation in NIR is that all unsized sources (and destination) will
ultimately have the same size.
The changes in nir_opt_algebraic.py are to prevent errors like:
Failed to parse transformation:
03:12:25 (('extract_i8', 'a', 'b'), ('ishr', ('ishl', 'a', ('imul', ('isub', 3, 'b'), 8)), 24), 'options->lower_extract_byte')
03:12:25 Traceback (most recent call last):
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 610, in __init__
03:12:25 xform = SearchAndReplace(xform)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 495, in __init__
03:12:25 BitSizeValidator(varset).validate(self.search, self.replace)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 311, in validate
03:12:25 validate_dst_class = self._validate_bit_class_up(replace)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 414, in _validate_bit_class_up
03:12:25 src_class = self._validate_bit_class_up(val.sources[i])
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 420, in _validate_bit_class_up
03:12:25 assert src_class == src_type_bits
03:12:25 AssertionError
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Suggested-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Cc: Jason Ekstrand <jason@jlekstrand.net>
2016-10-27 11:02:58 +01:00
|
|
|
(('extract_i8', a, 'b@32'),
|
2016-01-21 17:09:29 +00:00
|
|
|
('ishr', ('ishl', a, ('imul', ('isub', 3, b), 8)), 24),
|
|
|
|
'options->lower_extract_byte'),
|
|
|
|
|
nir: Shift count for shift opcodes is always 32-bits
Previously both sources were unsized. This caused problems when the
thing being shifted was 64-bit but the shift count was 32-bit. The
expectation in NIR is that all unsized sources (and destination) will
ultimately have the same size.
The changes in nir_opt_algebraic.py are to prevent errors like:
Failed to parse transformation:
03:12:25 (('extract_i8', 'a', 'b'), ('ishr', ('ishl', 'a', ('imul', ('isub', 3, 'b'), 8)), 24), 'options->lower_extract_byte')
03:12:25 Traceback (most recent call last):
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 610, in __init__
03:12:25 xform = SearchAndReplace(xform)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 495, in __init__
03:12:25 BitSizeValidator(varset).validate(self.search, self.replace)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 311, in validate
03:12:25 validate_dst_class = self._validate_bit_class_up(replace)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 414, in _validate_bit_class_up
03:12:25 src_class = self._validate_bit_class_up(val.sources[i])
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 420, in _validate_bit_class_up
03:12:25 assert src_class == src_type_bits
03:12:25 AssertionError
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Suggested-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Cc: Jason Ekstrand <jason@jlekstrand.net>
2016-10-27 11:02:58 +01:00
|
|
|
(('extract_u8', a, 'b@32'),
|
2016-01-21 17:09:29 +00:00
|
|
|
('iand', ('ushr', a, ('imul', b, 8)), 0xff),
|
|
|
|
'options->lower_extract_byte'),
|
|
|
|
|
nir: Shift count for shift opcodes is always 32-bits
Previously both sources were unsized. This caused problems when the
thing being shifted was 64-bit but the shift count was 32-bit. The
expectation in NIR is that all unsized sources (and destination) will
ultimately have the same size.
The changes in nir_opt_algebraic.py are to prevent errors like:
Failed to parse transformation:
03:12:25 (('extract_i8', 'a', 'b'), ('ishr', ('ishl', 'a', ('imul', ('isub', 3, 'b'), 8)), 24), 'options->lower_extract_byte')
03:12:25 Traceback (most recent call last):
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 610, in __init__
03:12:25 xform = SearchAndReplace(xform)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 495, in __init__
03:12:25 BitSizeValidator(varset).validate(self.search, self.replace)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 311, in validate
03:12:25 validate_dst_class = self._validate_bit_class_up(replace)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 414, in _validate_bit_class_up
03:12:25 src_class = self._validate_bit_class_up(val.sources[i])
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 420, in _validate_bit_class_up
03:12:25 assert src_class == src_type_bits
03:12:25 AssertionError
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Suggested-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Cc: Jason Ekstrand <jason@jlekstrand.net>
2016-10-27 11:02:58 +01:00
|
|
|
(('extract_i16', a, 'b@32'),
|
2016-01-21 17:09:29 +00:00
|
|
|
('ishr', ('ishl', a, ('imul', ('isub', 1, b), 16)), 16),
|
|
|
|
'options->lower_extract_word'),
|
|
|
|
|
nir: Shift count for shift opcodes is always 32-bits
Previously both sources were unsized. This caused problems when the
thing being shifted was 64-bit but the shift count was 32-bit. The
expectation in NIR is that all unsized sources (and destination) will
ultimately have the same size.
The changes in nir_opt_algebraic.py are to prevent errors like:
Failed to parse transformation:
03:12:25 (('extract_i8', 'a', 'b'), ('ishr', ('ishl', 'a', ('imul', ('isub', 3, 'b'), 8)), 24), 'options->lower_extract_byte')
03:12:25 Traceback (most recent call last):
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 610, in __init__
03:12:25 xform = SearchAndReplace(xform)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 495, in __init__
03:12:25 BitSizeValidator(varset).validate(self.search, self.replace)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 311, in validate
03:12:25 validate_dst_class = self._validate_bit_class_up(replace)
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 414, in _validate_bit_class_up
03:12:25 src_class = self._validate_bit_class_up(val.sources[i])
03:12:25 File "/home/jenkins/workspace/Leeroy_2/repos/mesa/src/compiler/nir/nir_algebraic.py", line 420, in _validate_bit_class_up
03:12:25 assert src_class == src_type_bits
03:12:25 AssertionError
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Suggested-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Cc: Jason Ekstrand <jason@jlekstrand.net>
2016-10-27 11:02:58 +01:00
|
|
|
(('extract_u16', a, 'b@32'),
|
2016-01-21 17:09:29 +00:00
|
|
|
('iand', ('ushr', a, ('imul', b, 16)), 0xffff),
|
|
|
|
'options->lower_extract_word'),
|
2016-01-25 19:05:52 +00:00
|
|
|
|
|
|
|
(('pack_unorm_2x16', 'v'),
|
|
|
|
('pack_uvec2_to_uint',
|
2017-03-08 03:54:37 +00:00
|
|
|
('f2u32', ('fround_even', ('fmul', ('fsat', 'v'), 65535.0)))),
|
2016-01-25 19:05:52 +00:00
|
|
|
'options->lower_pack_unorm_2x16'),
|
|
|
|
|
|
|
|
(('pack_unorm_4x8', 'v'),
|
|
|
|
('pack_uvec4_to_uint',
|
2017-03-08 03:54:37 +00:00
|
|
|
('f2u32', ('fround_even', ('fmul', ('fsat', 'v'), 255.0)))),
|
2016-01-25 19:05:52 +00:00
|
|
|
'options->lower_pack_unorm_4x8'),
|
|
|
|
|
|
|
|
(('pack_snorm_2x16', 'v'),
|
|
|
|
('pack_uvec2_to_uint',
|
2017-03-08 03:54:37 +00:00
|
|
|
('f2i32', ('fround_even', ('fmul', ('fmin', 1.0, ('fmax', -1.0, 'v')), 32767.0)))),
|
2016-01-25 19:05:52 +00:00
|
|
|
'options->lower_pack_snorm_2x16'),
|
|
|
|
|
|
|
|
(('pack_snorm_4x8', 'v'),
|
|
|
|
('pack_uvec4_to_uint',
|
2017-03-08 03:54:37 +00:00
|
|
|
('f2i32', ('fround_even', ('fmul', ('fmin', 1.0, ('fmax', -1.0, 'v')), 127.0)))),
|
2016-01-25 19:05:52 +00:00
|
|
|
'options->lower_pack_snorm_4x8'),
|
2016-01-25 19:07:02 +00:00
|
|
|
|
|
|
|
(('unpack_unorm_2x16', 'v'),
|
2017-03-08 03:54:37 +00:00
|
|
|
('fdiv', ('u2f32', ('vec2', ('extract_u16', 'v', 0),
|
2018-11-07 23:32:32 +00:00
|
|
|
('extract_u16', 'v', 1))),
|
2016-01-25 19:07:02 +00:00
|
|
|
65535.0),
|
|
|
|
'options->lower_unpack_unorm_2x16'),
|
|
|
|
|
|
|
|
(('unpack_unorm_4x8', 'v'),
|
2017-03-08 03:54:37 +00:00
|
|
|
('fdiv', ('u2f32', ('vec4', ('extract_u8', 'v', 0),
|
2018-11-07 23:32:32 +00:00
|
|
|
('extract_u8', 'v', 1),
|
|
|
|
('extract_u8', 'v', 2),
|
|
|
|
('extract_u8', 'v', 3))),
|
2016-01-25 19:07:02 +00:00
|
|
|
255.0),
|
|
|
|
'options->lower_unpack_unorm_4x8'),
|
|
|
|
|
|
|
|
(('unpack_snorm_2x16', 'v'),
|
2018-11-07 23:32:32 +00:00
|
|
|
('fmin', 1.0, ('fmax', -1.0, ('fdiv', ('i2f', ('vec2', ('extract_i16', 'v', 0),
|
|
|
|
('extract_i16', 'v', 1))),
|
2016-01-25 19:07:02 +00:00
|
|
|
32767.0))),
|
|
|
|
'options->lower_unpack_snorm_2x16'),
|
|
|
|
|
|
|
|
(('unpack_snorm_4x8', 'v'),
|
2018-11-07 23:32:32 +00:00
|
|
|
('fmin', 1.0, ('fmax', -1.0, ('fdiv', ('i2f', ('vec4', ('extract_i8', 'v', 0),
|
|
|
|
('extract_i8', 'v', 1),
|
|
|
|
('extract_i8', 'v', 2),
|
|
|
|
('extract_i8', 'v', 3))),
|
2016-01-25 19:07:02 +00:00
|
|
|
127.0))),
|
|
|
|
'options->lower_unpack_snorm_4x8'),
|
2019-02-06 21:12:25 +00:00
|
|
|
|
2019-12-15 18:43:07 +00:00
|
|
|
(('pack_half_2x16_split', 'a@32', 'b@32'),
|
|
|
|
('ior', ('ishl', ('u2u32', ('f2f16', b)), 16), ('u2u32', ('f2f16', a))),
|
2020-04-24 19:27:33 +01:00
|
|
|
'options->lower_pack_split'),
|
2019-12-15 18:43:07 +00:00
|
|
|
|
|
|
|
(('unpack_half_2x16_split_x', 'a@32'),
|
|
|
|
('f2f32', ('u2u16', a)),
|
2020-04-24 19:27:33 +01:00
|
|
|
'options->lower_pack_split'),
|
2019-12-15 18:43:07 +00:00
|
|
|
|
|
|
|
(('unpack_half_2x16_split_y', 'a@32'),
|
|
|
|
('f2f32', ('u2u16', ('ushr', a, 16))),
|
2020-04-24 19:27:33 +01:00
|
|
|
'options->lower_pack_split'),
|
|
|
|
|
|
|
|
(('pack_32_2x16_split', 'a@16', 'b@16'),
|
|
|
|
('ior', ('ishl', ('u2u32', b), 16), ('u2u32', a)),
|
|
|
|
'options->lower_pack_split'),
|
|
|
|
|
|
|
|
(('unpack_32_2x16_split_x', 'a@32'),
|
|
|
|
('u2u16', a),
|
|
|
|
'options->lower_pack_split'),
|
|
|
|
|
|
|
|
(('unpack_32_2x16_split_y', 'a@32'),
|
|
|
|
('u2u16', ('ushr', 'a', 16)),
|
|
|
|
'options->lower_pack_split'),
|
2019-12-15 18:43:07 +00:00
|
|
|
|
2019-02-06 21:12:25 +00:00
|
|
|
(('isign', a), ('imin', ('imax', a, -1), 1), 'options->lower_isign'),
|
2020-04-29 17:56:05 +01:00
|
|
|
(('imin', ('imax', a, -1), 1), ('isign', a), '!options->lower_isign'),
|
|
|
|
(('imax', ('imin', a, 1), -1), ('isign', a), '!options->lower_isign'),
|
nir: Make some notes about fsign versus NaN
This commit only documents the current behavior, even if that behavior
is not the behavior preferred by the relevant specs.
In SPIR-V, there are two flavors of the sign instruction, and each lives
in an extended instruction set. The GLSL.std.450 FSign instruction is
defined as:
Result is 1.0 if x > 0, 0.0 if x = 0, or -1.0 if x < 0.
This also matches the GLSL 4.60 definition.
However, the OpenCL.ExtendedInstructionSet.100 sign instruction is
defined as:
Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if
x < 0. Returns 0.0 if x is a NaN.
There are two differences. Each treats -0.0 differently, and each also
treats NaN differently. Specifically, GLSL.std.450 FSign does not
define any specific behavior for NaN.
There has been some discussion in Khronos about the NaN behavior of
GLSL.std.450 FSign. As part of that discussion, I did some research
into how we treat NaN for nir_op_fsign, and this commit just captures
some of those notes.
v2: Document the expected behavior of nir_op_fsign more thoroughly.
Suggested by Rhys. Note that the current implementation of constant
folding does not produce the expected result for NaN. Suggested by
Caio.
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> [v1]
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6358>
2020-02-18 18:18:57 +00:00
|
|
|
# float(0 < NaN) - float(NaN < 0) = float(False) - float(False) = 0 - 0 = 0
|
nir/algebraic: Mark comparisons generated from lowered fsign precise
This prevents other transformations from converting them to 'a != 0'.
For example, both of these transformations can do this:
(('~flt', 0.0, ('fabs', a)), ('fne', a, 0.0)),
(('~flt', ('fneg', ('fabs', a)), 0.0), ('fne', a, 0.0)),
Both fsign(fabs(NaN)) and fsign(fneg(fabs(NaN))) should produce zero,
but, since 'NaN != 0.0' is true, cascading these transformations could
cause them to generate 1.0 or -1.0 respecively.
No shader-db or fossil-db changes on any Intel platform.
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6358>
2020-02-19 20:47:21 +00:00
|
|
|
# Mark the new comparisons precise to prevent them being changed to 'a !=
|
|
|
|
# 0' or 'a == 0'.
|
|
|
|
(('fsign', a), ('fsub', ('b2f', ('!flt', 0.0, a)), ('b2f', ('!flt', a, 0.0))), 'options->lower_fsign'),
|
2019-09-26 18:32:00 +01:00
|
|
|
|
|
|
|
# Address/offset calculations:
|
2019-09-27 18:15:02 +01:00
|
|
|
# Drivers supporting imul24 should use the nir_lower_amul() pass, this
|
|
|
|
# rule converts everyone else to imul:
|
|
|
|
(('amul', a, b), ('imul', a, b), '!options->has_imul24'),
|
2019-09-26 18:34:51 +01:00
|
|
|
|
2020-04-12 15:36:20 +01:00
|
|
|
(('umul24', a, b),
|
|
|
|
('imul', ('iand', a, 0xffffff), ('iand', b, 0xffffff)),
|
|
|
|
'!options->has_umul24'),
|
|
|
|
(('umad24', a, b, c),
|
|
|
|
('iadd', ('imul', ('iand', a, 0xffffff), ('iand', b, 0xffffff)), c),
|
|
|
|
'!options->has_umad24'),
|
|
|
|
|
2021-04-30 19:46:09 +01:00
|
|
|
# Relaxed 24bit ops
|
|
|
|
(('imul24_relaxed', a, b), ('imul24', a, b), 'options->has_imul24'),
|
|
|
|
(('imul24_relaxed', a, b), ('imul', a, b), '!options->has_imul24'),
|
|
|
|
(('umad24_relaxed', a, b, c), ('umad24', a, b, c), 'options->has_umad24'),
|
|
|
|
(('umad24_relaxed', a, b, c), ('iadd', ('umul24_relaxed', a, b), c), '!options->has_umad24'),
|
|
|
|
(('umul24_relaxed', a, b), ('umul24', a, b), 'options->has_umul24'),
|
|
|
|
(('umul24_relaxed', a, b), ('imul', a, b), '!options->has_umul24'),
|
|
|
|
|
2019-09-26 18:34:51 +01:00
|
|
|
(('imad24_ir3', a, b, 0), ('imul24', a, b)),
|
|
|
|
(('imad24_ir3', a, 0, c), (c)),
|
|
|
|
(('imad24_ir3', a, 1, c), ('iadd', a, c)),
|
|
|
|
|
|
|
|
# if first two srcs are const, crack apart the imad so constant folding
|
|
|
|
# can clean up the imul:
|
|
|
|
# TODO ffma should probably get a similar rule:
|
|
|
|
(('imad24_ir3', '#a', '#b', c), ('iadd', ('imul', a, b), c)),
|
|
|
|
|
|
|
|
# These will turn 24b address/offset calc back into 32b shifts, but
|
|
|
|
# it should be safe to get back some of the bits of precision that we
|
|
|
|
# already decided were no necessary:
|
|
|
|
(('imul24', a, '#b@32(is_pos_power_of_two)'), ('ishl', a, ('find_lsb', b)), '!options->lower_bitops'),
|
|
|
|
(('imul24', a, '#b@32(is_neg_power_of_two)'), ('ineg', ('ishl', a, ('find_lsb', ('iabs', b)))), '!options->lower_bitops'),
|
|
|
|
(('imul24', a, 0), (0)),
|
2021-03-10 08:42:22 +00:00
|
|
|
|
|
|
|
(('fcsel', ('slt', 0, a), b, c), ('fcsel_gt', a, b, c), "options->has_fused_comp_and_csel"),
|
|
|
|
(('fcsel', ('slt', a, 0), b, c), ('fcsel_ge', a, c, b), "options->has_fused_comp_and_csel"),
|
|
|
|
(('fcsel', ('sge', a, 0), b, c), ('fcsel_ge', a, b, c), "options->has_fused_comp_and_csel"),
|
|
|
|
(('fcsel', ('sge', 0, a), b, c), ('fcsel_gt', a, c, b), "options->has_fused_comp_and_csel"),
|
|
|
|
|
|
|
|
(('bcsel', ('ilt', 0, 'a@32'), 'b@32', 'c@32'), ('i32csel_gt', a, b, c), "options->has_fused_comp_and_csel"),
|
|
|
|
(('bcsel', ('ilt', 'a@32', 0), 'b@32', 'c@32'), ('i32csel_ge', a, c, b), "options->has_fused_comp_and_csel"),
|
|
|
|
(('bcsel', ('ige', 'a@32', 0), 'b@32', 'c@32'), ('i32csel_ge', a, b, c), "options->has_fused_comp_and_csel"),
|
|
|
|
(('bcsel', ('ige', 0, 'a@32'), 'b@32', 'c@32'), ('i32csel_gt', a, c, b), "options->has_fused_comp_and_csel"),
|
|
|
|
|
|
|
|
(('bcsel', ('flt', 0, 'a@32'), 'b@32', 'c@32'), ('fcsel_gt', a, b, c), "options->has_fused_comp_and_csel"),
|
|
|
|
(('bcsel', ('flt', 'a@32', 0), 'b@32', 'c@32'), ('fcsel_ge', a, c, b), "options->has_fused_comp_and_csel"),
|
|
|
|
(('bcsel', ('fge', 'a@32', 0), 'b@32', 'c@32'), ('fcsel_ge', a, b, c), "options->has_fused_comp_and_csel"),
|
|
|
|
(('bcsel', ('fge', 0, 'a@32'), 'b@32', 'c@32'), ('fcsel_gt', a, c, b), "options->has_fused_comp_and_csel"),
|
|
|
|
|
2019-02-28 03:52:12 +00:00
|
|
|
])
|
2014-12-12 19:13:10 +00:00
|
|
|
|
2018-07-12 14:02:27 +01:00
|
|
|
# bit_size dependent lowerings
|
|
|
|
for bit_size in [8, 16, 32, 64]:
|
|
|
|
# convenience constants
|
|
|
|
intmax = (1 << (bit_size - 1)) - 1
|
|
|
|
intmin = 1 << (bit_size - 1)
|
|
|
|
|
|
|
|
optimizations += [
|
|
|
|
(('iadd_sat@' + str(bit_size), a, b),
|
|
|
|
('bcsel', ('ige', b, 1), ('bcsel', ('ilt', ('iadd', a, b), a), intmax, ('iadd', a, b)),
|
|
|
|
('bcsel', ('ilt', a, ('iadd', a, b)), intmin, ('iadd', a, b))), 'options->lower_add_sat'),
|
|
|
|
(('isub_sat@' + str(bit_size), a, b),
|
|
|
|
('bcsel', ('ilt', b, 0), ('bcsel', ('ilt', ('isub', a, b), a), intmax, ('isub', a, b)),
|
|
|
|
('bcsel', ('ilt', a, ('isub', a, b)), intmin, ('isub', a, b))), 'options->lower_add_sat'),
|
|
|
|
]
|
|
|
|
|
2020-08-18 18:51:57 +01:00
|
|
|
invert = OrderedDict([('feq', 'fneu'), ('fneu', 'feq')])
|
2018-02-07 01:27:53 +00:00
|
|
|
|
2018-08-09 09:27:19 +01:00
|
|
|
for left, right in itertools.combinations_with_replacement(invert.keys(), 2):
|
2018-02-07 01:27:53 +00:00
|
|
|
optimizations.append((('inot', ('ior(is_used_once)', (left, a, b), (right, c, d))),
|
|
|
|
('iand', (invert[left], a, b), (invert[right], c, d))))
|
|
|
|
optimizations.append((('inot', ('iand(is_used_once)', (left, a, b), (right, c, d))),
|
|
|
|
('ior', (invert[left], a, b), (invert[right], c, d))))
|
|
|
|
|
2018-12-06 18:56:33 +00:00
|
|
|
# Optimize x2bN(b2x(x)) -> x
|
|
|
|
for size in type_sizes('bool'):
|
|
|
|
aN = 'a@' + str(size)
|
|
|
|
f2bN = 'f2b' + str(size)
|
|
|
|
i2bN = 'i2b' + str(size)
|
|
|
|
optimizations.append(((f2bN, ('b2f', aN)), a))
|
|
|
|
optimizations.append(((i2bN, ('b2i', aN)), a))
|
|
|
|
|
2018-10-11 04:36:52 +01:00
|
|
|
# Optimize x2yN(b2x(x)) -> b2y
|
|
|
|
for x, y in itertools.product(['f', 'u', 'i'], ['f', 'u', 'i']):
|
|
|
|
if x != 'f' and y != 'f' and x != y:
|
|
|
|
continue
|
|
|
|
|
|
|
|
b2x = 'b2f' if x == 'f' else 'b2i'
|
|
|
|
b2y = 'b2f' if y == 'f' else 'b2i'
|
2018-11-07 22:25:31 +00:00
|
|
|
x2yN = '{}2{}'.format(x, y)
|
|
|
|
optimizations.append(((x2yN, (b2x, a)), (b2y, a)))
|
2018-10-11 04:36:52 +01:00
|
|
|
|
2019-04-23 00:03:04 +01:00
|
|
|
# Optimize away x2xN(a@N)
|
2020-03-27 05:18:43 +00:00
|
|
|
for t in ['int', 'uint', 'float', 'bool']:
|
2019-04-23 00:03:04 +01:00
|
|
|
for N in type_sizes(t):
|
|
|
|
x2xN = '{0}2{0}{1}'.format(t[0], N)
|
|
|
|
aN = 'a@{0}'.format(N)
|
|
|
|
optimizations.append(((x2xN, aN), a))
|
|
|
|
|
|
|
|
# Optimize x2xN(y2yM(a@P)) -> y2yN(a) for integers
|
|
|
|
# In particular, we can optimize away everything except upcast of downcast and
|
|
|
|
# upcasts where the type differs from the other cast
|
|
|
|
for N, M in itertools.product(type_sizes('uint'), type_sizes('uint')):
|
|
|
|
if N < M:
|
|
|
|
# The outer cast is a down-cast. It doesn't matter what the size of the
|
|
|
|
# argument of the inner cast is because we'll never been in the upcast
|
|
|
|
# of downcast case. Regardless of types, we'll always end up with y2yN
|
|
|
|
# in the end.
|
|
|
|
for x, y in itertools.product(['i', 'u'], ['i', 'u']):
|
|
|
|
x2xN = '{0}2{0}{1}'.format(x, N)
|
|
|
|
y2yM = '{0}2{0}{1}'.format(y, M)
|
|
|
|
y2yN = '{0}2{0}{1}'.format(y, N)
|
|
|
|
optimizations.append(((x2xN, (y2yM, a)), (y2yN, a)))
|
|
|
|
elif N > M:
|
|
|
|
# If the outer cast is an up-cast, we have to be more careful about the
|
|
|
|
# size of the argument of the inner cast and with types. In this case,
|
|
|
|
# the type is always the type of type up-cast which is given by the
|
|
|
|
# outer cast.
|
|
|
|
for P in type_sizes('uint'):
|
|
|
|
# We can't optimize away up-cast of down-cast.
|
|
|
|
if M < P:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Because we're doing down-cast of down-cast, the types always have
|
|
|
|
# to match between the two casts
|
|
|
|
for x in ['i', 'u']:
|
|
|
|
x2xN = '{0}2{0}{1}'.format(x, N)
|
|
|
|
x2xM = '{0}2{0}{1}'.format(x, M)
|
|
|
|
aP = 'a@{0}'.format(P)
|
|
|
|
optimizations.append(((x2xN, (x2xM, aP)), (x2xN, a)))
|
|
|
|
else:
|
|
|
|
# The N == M case is handled by other optimizations
|
|
|
|
pass
|
|
|
|
|
2020-03-28 16:24:08 +00:00
|
|
|
# Downcast operations should be able to see through pack
|
|
|
|
for t in ['i', 'u']:
|
|
|
|
for N in [8, 16, 32]:
|
|
|
|
x2xN = '{0}2{0}{1}'.format(t, N)
|
|
|
|
optimizations += [
|
|
|
|
((x2xN, ('pack_64_2x32_split', a, b)), (x2xN, a)),
|
|
|
|
((x2xN, ('pack_64_2x32_split', a, b)), (x2xN, a)),
|
|
|
|
]
|
|
|
|
|
2019-07-13 05:26:59 +01:00
|
|
|
# Optimize comparisons with up-casts
|
|
|
|
for t in ['int', 'uint', 'float']:
|
|
|
|
for N, M in itertools.product(type_sizes(t), repeat=2):
|
|
|
|
if N == 1 or N >= M:
|
|
|
|
continue
|
|
|
|
|
2020-03-31 13:57:42 +01:00
|
|
|
cond = 'true'
|
|
|
|
if N == 8:
|
|
|
|
cond = 'options->support_8bit_alu'
|
|
|
|
elif N == 16:
|
|
|
|
cond = 'options->support_16bit_alu'
|
2019-07-13 05:26:59 +01:00
|
|
|
x2xM = '{0}2{0}{1}'.format(t[0], M)
|
|
|
|
x2xN = '{0}2{0}{1}'.format(t[0], N)
|
|
|
|
aN = 'a@' + str(N)
|
|
|
|
bN = 'b@' + str(N)
|
|
|
|
xeq = 'feq' if t == 'float' else 'ieq'
|
2020-08-18 18:51:57 +01:00
|
|
|
xne = 'fneu' if t == 'float' else 'ine'
|
2019-07-13 05:26:59 +01:00
|
|
|
xge = '{0}ge'.format(t[0])
|
|
|
|
xlt = '{0}lt'.format(t[0])
|
|
|
|
|
|
|
|
# Up-casts are lossless so for correctly signed comparisons of
|
|
|
|
# up-casted values we can do the comparison at the largest of the two
|
|
|
|
# original sizes and drop one or both of the casts. (We have
|
|
|
|
# optimizations to drop the no-op casts which this may generate.)
|
|
|
|
for P in type_sizes(t):
|
|
|
|
if P == 1 or P > N:
|
|
|
|
continue
|
|
|
|
|
|
|
|
bP = 'b@' + str(P)
|
|
|
|
optimizations += [
|
2020-03-31 13:57:42 +01:00
|
|
|
((xeq, (x2xM, aN), (x2xM, bP)), (xeq, a, (x2xN, b)), cond),
|
|
|
|
((xne, (x2xM, aN), (x2xM, bP)), (xne, a, (x2xN, b)), cond),
|
|
|
|
((xge, (x2xM, aN), (x2xM, bP)), (xge, a, (x2xN, b)), cond),
|
|
|
|
((xlt, (x2xM, aN), (x2xM, bP)), (xlt, a, (x2xN, b)), cond),
|
|
|
|
((xge, (x2xM, bP), (x2xM, aN)), (xge, (x2xN, b), a), cond),
|
|
|
|
((xlt, (x2xM, bP), (x2xM, aN)), (xlt, (x2xN, b), a), cond),
|
2019-07-13 05:26:59 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
# The next bit doesn't work on floats because the range checks would
|
|
|
|
# get way too complicated.
|
|
|
|
if t in ['int', 'uint']:
|
|
|
|
if t == 'int':
|
|
|
|
xN_min = -(1 << (N - 1))
|
|
|
|
xN_max = (1 << (N - 1)) - 1
|
|
|
|
elif t == 'uint':
|
|
|
|
xN_min = 0
|
|
|
|
xN_max = (1 << N) - 1
|
|
|
|
else:
|
|
|
|
assert False
|
|
|
|
|
|
|
|
# If we're up-casting and comparing to a constant, we can unfold
|
|
|
|
# the comparison into a comparison with the shrunk down constant
|
|
|
|
# and a check that the constant fits in the smaller bit size.
|
|
|
|
optimizations += [
|
|
|
|
((xeq, (x2xM, aN), '#b'),
|
2020-03-31 13:57:42 +01:00
|
|
|
('iand', (xeq, a, (x2xN, b)), (xeq, (x2xM, (x2xN, b)), b)), cond),
|
2019-07-13 05:26:59 +01:00
|
|
|
((xne, (x2xM, aN), '#b'),
|
2020-03-31 13:57:42 +01:00
|
|
|
('ior', (xne, a, (x2xN, b)), (xne, (x2xM, (x2xN, b)), b)), cond),
|
2019-07-13 05:26:59 +01:00
|
|
|
((xlt, (x2xM, aN), '#b'),
|
|
|
|
('iand', (xlt, xN_min, b),
|
2020-03-31 13:57:42 +01:00
|
|
|
('ior', (xlt, xN_max, b), (xlt, a, (x2xN, b)))), cond),
|
2019-07-13 05:26:59 +01:00
|
|
|
((xlt, '#a', (x2xM, bN)),
|
|
|
|
('iand', (xlt, a, xN_max),
|
2020-03-31 13:57:42 +01:00
|
|
|
('ior', (xlt, a, xN_min), (xlt, (x2xN, a), b))), cond),
|
2019-07-13 05:26:59 +01:00
|
|
|
((xge, (x2xM, aN), '#b'),
|
|
|
|
('iand', (xge, xN_max, b),
|
2020-03-31 13:57:42 +01:00
|
|
|
('ior', (xge, xN_min, b), (xge, a, (x2xN, b)))), cond),
|
2019-07-13 05:26:59 +01:00
|
|
|
((xge, '#a', (x2xM, bN)),
|
|
|
|
('iand', (xge, a, xN_min),
|
2020-03-31 13:57:42 +01:00
|
|
|
('ior', (xge, a, xN_max), (xge, (x2xN, a), b))), cond),
|
2019-07-13 05:26:59 +01:00
|
|
|
]
|
|
|
|
|
2020-05-21 23:05:08 +01:00
|
|
|
# Convert masking followed by signed downcast to just unsigned downcast
|
|
|
|
optimizations += [
|
|
|
|
(('i2i32', ('iand', 'a@64', 0xffffffff)), ('u2u32', a)),
|
|
|
|
(('i2i16', ('iand', 'a@32', 0xffff)), ('u2u16', a)),
|
|
|
|
(('i2i16', ('iand', 'a@64', 0xffff)), ('u2u16', a)),
|
|
|
|
(('i2i8', ('iand', 'a@16', 0xff)), ('u2u8', a)),
|
|
|
|
(('i2i8', ('iand', 'a@32', 0xff)), ('u2u8', a)),
|
|
|
|
(('i2i8', ('iand', 'a@64', 0xff)), ('u2u8', a)),
|
|
|
|
]
|
|
|
|
|
2021-02-04 17:55:43 +00:00
|
|
|
# Some operations such as iadd have the property that the bottom N bits of the
|
|
|
|
# output only depends on the bottom N bits of each of the inputs so we can
|
|
|
|
# remove casts
|
|
|
|
for N in [16, 32]:
|
|
|
|
for M in [8, 16]:
|
|
|
|
if M >= N:
|
|
|
|
continue
|
|
|
|
|
|
|
|
aN = 'a@' + str(N)
|
|
|
|
u2uM = 'u2u{0}'.format(M)
|
|
|
|
i2iM = 'i2i{0}'.format(M)
|
|
|
|
|
|
|
|
for x in ['u', 'i']:
|
|
|
|
x2xN = '{0}2{0}{1}'.format(x, N)
|
|
|
|
extract_xM = 'extract_{0}{1}'.format(x, M)
|
|
|
|
|
|
|
|
x2xN_M_bits = '{0}(only_lower_{1}_bits_used)'.format(x2xN, M)
|
|
|
|
extract_xM_M_bits = \
|
|
|
|
'{0}(only_lower_{1}_bits_used)'.format(extract_xM, M)
|
|
|
|
optimizations += [
|
|
|
|
((x2xN_M_bits, (u2uM, aN)), a),
|
|
|
|
((extract_xM_M_bits, aN, 0), a),
|
|
|
|
]
|
|
|
|
|
|
|
|
bcsel_M_bits = 'bcsel(only_lower_{0}_bits_used)'.format(M)
|
|
|
|
optimizations += [
|
|
|
|
((bcsel_M_bits, c, (x2xN, (u2uM, aN)), b), ('bcsel', c, a, b)),
|
|
|
|
((bcsel_M_bits, c, (x2xN, (i2iM, aN)), b), ('bcsel', c, a, b)),
|
|
|
|
((bcsel_M_bits, c, (extract_xM, aN, 0), b), ('bcsel', c, a, b)),
|
|
|
|
]
|
|
|
|
|
|
|
|
for op in ['iadd', 'imul', 'iand', 'ior', 'ixor']:
|
|
|
|
op_M_bits = '{0}(only_lower_{1}_bits_used)'.format(op, M)
|
|
|
|
optimizations += [
|
|
|
|
((op_M_bits, (x2xN, (u2uM, aN)), b), (op, a, b)),
|
|
|
|
((op_M_bits, (x2xN, (i2iM, aN)), b), (op, a, b)),
|
|
|
|
((op_M_bits, (extract_xM, aN, 0), b), (op, a, b)),
|
|
|
|
]
|
|
|
|
|
2016-04-27 19:18:04 +01:00
|
|
|
def fexp2i(exp, bits):
|
2020-02-27 19:58:34 +00:00
|
|
|
# Generate an expression which constructs value 2.0^exp or 0.0.
|
|
|
|
#
|
|
|
|
# We assume that exp is already in a valid range:
|
|
|
|
#
|
|
|
|
# * [-15, 15] for 16-bit float
|
|
|
|
# * [-127, 127] for 32-bit float
|
|
|
|
# * [-1023, 1023] for 16-bit float
|
|
|
|
#
|
|
|
|
# If exp is the lowest value in the valid range, a value of 0.0 is
|
|
|
|
# constructed. Otherwise, the value 2.0^exp is constructed.
|
2018-05-24 08:54:45 +01:00
|
|
|
if bits == 16:
|
|
|
|
return ('i2i16', ('ishl', ('iadd', exp, 15), 10))
|
|
|
|
elif bits == 32:
|
2016-04-27 19:18:04 +01:00
|
|
|
return ('ishl', ('iadd', exp, 127), 23)
|
|
|
|
elif bits == 64:
|
2017-02-15 06:15:16 +00:00
|
|
|
return ('pack_64_2x32_split', 0, ('ishl', ('iadd', exp, 1023), 20))
|
2016-04-27 19:18:04 +01:00
|
|
|
else:
|
|
|
|
assert False
|
|
|
|
|
|
|
|
def ldexp(f, exp, bits):
|
2020-02-27 19:58:34 +00:00
|
|
|
# The maximum possible range for a normal exponent is [-126, 127] and,
|
|
|
|
# throwing in denormals, you get a maximum range of [-149, 127]. This
|
|
|
|
# means that we can potentially have a swing of +-276. If you start with
|
|
|
|
# FLT_MAX, you actually have to do ldexp(FLT_MAX, -278) to get it to flush
|
|
|
|
# all the way to zero. The GLSL spec only requires that we handle a subset
|
|
|
|
# of this range. From version 4.60 of the spec:
|
|
|
|
#
|
|
|
|
# "If exp is greater than +128 (single-precision) or +1024
|
|
|
|
# (double-precision), the value returned is undefined. If exp is less
|
|
|
|
# than -126 (single-precision) or -1022 (double-precision), the value
|
|
|
|
# returned may be flushed to zero. Additionally, splitting the value
|
|
|
|
# into a significand and exponent using frexp() and then reconstructing
|
|
|
|
# a floating-point value using ldexp() should yield the original input
|
|
|
|
# for zero and all finite non-denormalized values."
|
|
|
|
#
|
|
|
|
# The SPIR-V spec has similar language.
|
|
|
|
#
|
|
|
|
# In order to handle the maximum value +128 using the fexp2i() helper
|
|
|
|
# above, we have to split the exponent in half and do two multiply
|
|
|
|
# operations.
|
|
|
|
#
|
|
|
|
# First, we clamp exp to a reasonable range. Specifically, we clamp to
|
|
|
|
# twice the full range that is valid for the fexp2i() function above. If
|
|
|
|
# exp/2 is the bottom value of that range, the fexp2i() expression will
|
|
|
|
# yield 0.0f which, when multiplied by f, will flush it to zero which is
|
|
|
|
# allowed by the GLSL and SPIR-V specs for low exponent values. If the
|
|
|
|
# value is clamped from above, then it must have been above the supported
|
|
|
|
# range of the GLSL built-in and therefore any return value is acceptable.
|
2018-05-24 08:54:45 +01:00
|
|
|
if bits == 16:
|
2020-02-27 19:58:34 +00:00
|
|
|
exp = ('imin', ('imax', exp, -30), 30)
|
2018-05-24 08:54:45 +01:00
|
|
|
elif bits == 32:
|
2020-02-27 19:58:34 +00:00
|
|
|
exp = ('imin', ('imax', exp, -254), 254)
|
2016-04-27 19:18:04 +01:00
|
|
|
elif bits == 64:
|
2020-02-27 19:58:34 +00:00
|
|
|
exp = ('imin', ('imax', exp, -2046), 2046)
|
2016-04-27 19:18:04 +01:00
|
|
|
else:
|
|
|
|
assert False
|
2016-03-25 19:12:38 +00:00
|
|
|
|
|
|
|
# Now we compute two powers of 2, one for exp/2 and one for exp-exp/2.
|
|
|
|
# (We use ishr which isn't the same for -1, but the -1 case still works
|
|
|
|
# since we use exp-exp/2 as the second exponent.) While the spec
|
|
|
|
# technically defines ldexp as f * 2.0^exp, simply multiplying once doesn't
|
|
|
|
# work with denormals and doesn't allow for the full swing in exponents
|
|
|
|
# that you can get with normalized values. Instead, we create two powers
|
|
|
|
# of two and multiply by them each in turn. That way the effective range
|
|
|
|
# of our exponent is doubled.
|
2016-04-27 19:18:04 +01:00
|
|
|
pow2_1 = fexp2i(('ishr', exp, 1), bits)
|
|
|
|
pow2_2 = fexp2i(('isub', exp, ('ishr', exp, 1)), bits)
|
2016-03-25 19:12:38 +00:00
|
|
|
return ('fmul', ('fmul', f, pow2_1), pow2_2)
|
|
|
|
|
2016-04-27 19:18:04 +01:00
|
|
|
optimizations += [
|
2018-05-24 08:54:45 +01:00
|
|
|
(('ldexp@16', 'x', 'exp'), ldexp('x', 'exp', 16), 'options->lower_ldexp'),
|
2018-02-27 08:19:21 +00:00
|
|
|
(('ldexp@32', 'x', 'exp'), ldexp('x', 'exp', 32), 'options->lower_ldexp'),
|
|
|
|
(('ldexp@64', 'x', 'exp'), ldexp('x', 'exp', 64), 'options->lower_ldexp'),
|
2016-04-27 19:18:04 +01:00
|
|
|
]
|
2016-03-25 19:12:38 +00:00
|
|
|
|
2016-02-02 00:44:18 +00:00
|
|
|
# Unreal Engine 4 demo applications open-codes bitfieldReverse()
|
|
|
|
def bitfield_reverse(u):
|
|
|
|
step1 = ('ior', ('ishl', u, 16), ('ushr', u, 16))
|
|
|
|
step2 = ('ior', ('ishl', ('iand', step1, 0x00ff00ff), 8), ('ushr', ('iand', step1, 0xff00ff00), 8))
|
|
|
|
step3 = ('ior', ('ishl', ('iand', step2, 0x0f0f0f0f), 4), ('ushr', ('iand', step2, 0xf0f0f0f0), 4))
|
|
|
|
step4 = ('ior', ('ishl', ('iand', step3, 0x33333333), 2), ('ushr', ('iand', step3, 0xcccccccc), 2))
|
2019-06-24 23:12:56 +01:00
|
|
|
step5 = ('ior(many-comm-expr)', ('ishl', ('iand', step4, 0x55555555), 1), ('ushr', ('iand', step4, 0xaaaaaaaa), 1))
|
2016-02-02 00:44:18 +00:00
|
|
|
|
|
|
|
return step5
|
|
|
|
|
2019-08-26 21:28:09 +01:00
|
|
|
optimizations += [(bitfield_reverse('x@32'), ('bitfield_reverse', 'x'), '!options->lower_bitfield_reverse')]
|
2016-02-02 00:44:18 +00:00
|
|
|
|
2020-09-04 19:26:01 +01:00
|
|
|
# "all_equal(eq(a, b), vec(~0))" is the same as "all_equal(a, b)"
|
|
|
|
# "any_nequal(neq(a, b), vec(0))" is the same as "any_nequal(a, b)"
|
|
|
|
for ncomp in [2, 3, 4, 8, 16]:
|
|
|
|
optimizations += [
|
|
|
|
(('ball_iequal' + str(ncomp), ('ieq', a, b), ~0), ('ball_iequal' + str(ncomp), a, b)),
|
|
|
|
(('ball_iequal' + str(ncomp), ('feq', a, b), ~0), ('ball_fequal' + str(ncomp), a, b)),
|
|
|
|
(('bany_inequal' + str(ncomp), ('ine', a, b), 0), ('bany_inequal' + str(ncomp), a, b)),
|
|
|
|
(('bany_inequal' + str(ncomp), ('fneu', a, b), 0), ('bany_fnequal' + str(ncomp), a, b)),
|
|
|
|
]
|
|
|
|
|
2016-12-20 05:29:51 +00:00
|
|
|
# For any float comparison operation, "cmp", if you have "a == a && a cmp b"
|
|
|
|
# then the "a == a" is redundant because it's equivalent to "a is not NaN"
|
|
|
|
# and, if a is a NaN then the second comparison will fail anyway.
|
|
|
|
for op in ['flt', 'fge', 'feq']:
|
|
|
|
optimizations += [
|
2019-10-24 22:41:20 +01:00
|
|
|
(('iand', ('feq', a, a), (op, a, b)), ('!' + op, a, b)),
|
|
|
|
(('iand', ('feq', a, a), (op, b, a)), ('!' + op, b, a)),
|
2016-12-20 05:29:51 +00:00
|
|
|
]
|
2016-02-02 00:44:18 +00:00
|
|
|
|
2015-01-29 00:53:51 +00:00
|
|
|
# Add optimizations to handle the case where the result of a ternary is
|
|
|
|
# compared to a constant. This way we can take things like
|
|
|
|
#
|
|
|
|
# (a ? 0 : 1) > 0
|
|
|
|
#
|
|
|
|
# and turn it into
|
|
|
|
#
|
|
|
|
# a ? (0 > 0) : (1 > 0)
|
|
|
|
#
|
|
|
|
# which constant folding will eat for lunch. The resulting ternary will
|
|
|
|
# further get cleaned up by the boolean reductions above and we will be
|
|
|
|
# left with just the original variable "a".
|
2020-01-25 01:10:07 +00:00
|
|
|
for op in ['feq', 'fneu', 'ieq', 'ine']:
|
|
|
|
optimizations += [
|
|
|
|
((op, ('bcsel', 'a', '#b', '#c'), '#d'),
|
|
|
|
('bcsel', 'a', (op, 'b', 'd'), (op, 'c', 'd'))),
|
|
|
|
]
|
|
|
|
|
|
|
|
for op in ['flt', 'fge', 'ilt', 'ige', 'ult', 'uge']:
|
2015-01-29 00:53:51 +00:00
|
|
|
optimizations += [
|
|
|
|
((op, ('bcsel', 'a', '#b', '#c'), '#d'),
|
|
|
|
('bcsel', 'a', (op, 'b', 'd'), (op, 'c', 'd'))),
|
|
|
|
((op, '#d', ('bcsel', a, '#b', '#c')),
|
|
|
|
('bcsel', 'a', (op, 'd', 'b'), (op, 'd', 'c'))),
|
|
|
|
]
|
|
|
|
|
2016-03-02 23:39:09 +00:00
|
|
|
|
|
|
|
# For example, this converts things like
|
|
|
|
#
|
|
|
|
# 1 + mix(0, a - 1, condition)
|
|
|
|
#
|
|
|
|
# into
|
|
|
|
#
|
|
|
|
# mix(1, (a-1)+1, condition)
|
|
|
|
#
|
|
|
|
# Other optimizations will rearrange the constants.
|
|
|
|
for op in ['fadd', 'fmul', 'iadd', 'imul']:
|
|
|
|
optimizations += [
|
|
|
|
((op, ('bcsel(is_used_once)', a, '#b', c), '#d'), ('bcsel', a, (op, b, d), (op, c, d)))
|
|
|
|
]
|
|
|
|
|
2019-03-27 22:07:20 +00:00
|
|
|
# For derivatives in compute shaders, GLSL_NV_compute_shader_derivatives
|
|
|
|
# states:
|
|
|
|
#
|
|
|
|
# If neither layout qualifier is specified, derivatives in compute shaders
|
|
|
|
# return zero, which is consistent with the handling of built-in texture
|
|
|
|
# functions like texture() in GLSL 4.50 compute shaders.
|
|
|
|
for op in ['fddx', 'fddx_fine', 'fddx_coarse',
|
|
|
|
'fddy', 'fddy_fine', 'fddy_coarse']:
|
|
|
|
optimizations += [
|
|
|
|
((op, 'a'), 0.0, 'info->stage == MESA_SHADER_COMPUTE && info->cs.derivative_group == DERIVATIVE_GROUP_NONE')
|
|
|
|
]
|
|
|
|
|
2019-05-12 23:09:38 +01:00
|
|
|
# Some optimizations for ir3-specific instructions.
|
|
|
|
optimizations += [
|
|
|
|
# 'al * bl': If either 'al' or 'bl' is zero, return zero.
|
|
|
|
(('umul_low', '#a(is_lower_half_zero)', 'b'), (0)),
|
|
|
|
# '(ah * bl) << 16 + c': If either 'ah' or 'bl' is zero, return 'c'.
|
2019-06-10 20:38:39 +01:00
|
|
|
(('imadsh_mix16', '#a@32(is_lower_half_zero)', 'b@32', 'c@32'), ('c')),
|
|
|
|
(('imadsh_mix16', 'a@32', '#b@32(is_upper_half_zero)', 'c@32'), ('c')),
|
2019-05-12 23:09:38 +01:00
|
|
|
]
|
|
|
|
|
2019-11-01 23:23:09 +00:00
|
|
|
# These kinds of sequences can occur after nir_opt_peephole_select.
|
|
|
|
#
|
|
|
|
# NOTE: fadd is not handled here because that gets in the way of ffma
|
|
|
|
# generation in the i965 driver. Instead, fadd and ffma are handled in
|
|
|
|
# late_optimizations.
|
|
|
|
|
|
|
|
for op in ['flrp']:
|
|
|
|
optimizations += [
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c, d), (op, b, c, e)), (op, b, c, ('bcsel', a, d, e))),
|
|
|
|
(('bcsel', a, (op, b, c, d), (op + '(is_used_once)', b, c, e)), (op, b, c, ('bcsel', a, d, e))),
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c, d), (op, b, e, d)), (op, b, ('bcsel', a, c, e), d)),
|
|
|
|
(('bcsel', a, (op, b, c, d), (op + '(is_used_once)', b, e, d)), (op, b, ('bcsel', a, c, e), d)),
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c, d), (op, e, c, d)), (op, ('bcsel', a, b, e), c, d)),
|
|
|
|
(('bcsel', a, (op, b, c, d), (op + '(is_used_once)', e, c, d)), (op, ('bcsel', a, b, e), c, d)),
|
|
|
|
]
|
|
|
|
|
|
|
|
for op in ['fmul', 'iadd', 'imul', 'iand', 'ior', 'ixor', 'fmin', 'fmax', 'imin', 'imax', 'umin', 'umax']:
|
|
|
|
optimizations += [
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c), (op, b, 'd(is_not_const)')), (op, b, ('bcsel', a, c, d))),
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, 'c(is_not_const)'), (op, b, d)), (op, b, ('bcsel', a, c, d))),
|
|
|
|
(('bcsel', a, (op, b, 'c(is_not_const)'), (op + '(is_used_once)', b, d)), (op, b, ('bcsel', a, c, d))),
|
|
|
|
(('bcsel', a, (op, b, c), (op + '(is_used_once)', b, 'd(is_not_const)')), (op, b, ('bcsel', a, c, d))),
|
|
|
|
]
|
|
|
|
|
|
|
|
for op in ['fpow']:
|
|
|
|
optimizations += [
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c), (op, b, d)), (op, b, ('bcsel', a, c, d))),
|
|
|
|
(('bcsel', a, (op, b, c), (op + '(is_used_once)', b, d)), (op, b, ('bcsel', a, c, d))),
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c), (op, d, c)), (op, ('bcsel', a, b, d), c)),
|
|
|
|
(('bcsel', a, (op, b, c), (op + '(is_used_once)', d, c)), (op, ('bcsel', a, b, d), c)),
|
|
|
|
]
|
|
|
|
|
2020-04-29 18:50:27 +01:00
|
|
|
for op in ['frcp', 'frsq', 'fsqrt', 'fexp2', 'flog2', 'fsign', 'fsin', 'fcos', 'fneg', 'fabs', 'fsign']:
|
2019-11-01 23:23:09 +00:00
|
|
|
optimizations += [
|
2020-04-29 18:50:27 +01:00
|
|
|
(('bcsel', c, (op + '(is_used_once)', a), (op + '(is_used_once)', b)), (op, ('bcsel', c, a, b))),
|
|
|
|
]
|
|
|
|
|
|
|
|
for op in ['ineg', 'iabs', 'inot', 'isign']:
|
|
|
|
optimizations += [
|
|
|
|
((op, ('bcsel', c, '#a', '#b')), ('bcsel', c, (op, a), (op, b))),
|
2019-11-01 23:23:09 +00:00
|
|
|
]
|
|
|
|
|
2021-08-05 22:19:27 +01:00
|
|
|
optimizations.extend([
|
|
|
|
(('fisnormal', 'a@32'), ('ult', 0x1ffffff, ('iadd', ('ishl', a, 1), 0x1000000)), 'options->lower_fisnormal')
|
|
|
|
])
|
|
|
|
|
nir: Propagate *2*16 conversions into vectors
If we have code like:
('f2f16', ('vec2', ('f2f32', 'a@16'), '#b@32'))
We would like to eliminate the conversions, but the existing rules can't
see into the the (heterogenous) vector. So instead of trying to
eliminate in one pass, we add opts to propagate the f2f16 into the
vector. Even if nothing further happens, this is often a win since then
the created vector is smaller (half2 instead of float2). Hence the above
gets transformed to
('vec2', ('f2f16', ('f2f32', 'a@16')), ('f2f16', '#b@32'))
Then the existing f2f16(f2f32) rule will kick in for the first component
and constant folding will for the second and we'll be left with
('vec2', 'a@16', '#b@16')
...eliminating all conversions.
v2: Predicate on !options->vectorize_vec2_16bit. As discussed, this
optimization helps greatly on true vector architectures (like Midgard)
but wreaks havoc on more modern SIMD-within-a-register architectures
(like Bifrost and modern AMD). So let's predicate on that.
v3: Extend for integers as well and add a comment explaining the
transforms.
Results on Midgard (unfortunately a true SIMD architecture):
total instructions in shared programs: 51359 -> 50963 (-0.77%)
instructions in affected programs: 4523 -> 4127 (-8.76%)
helped: 53
HURT: 0
helped stats (abs) min: 1 max: 86 x̄: 7.47 x̃: 6
helped stats (rel) min: 1.71% max: 28.00% x̄: 9.66% x̃: 7.34%
95% mean confidence interval for instructions value: -10.58 -4.36
95% mean confidence interval for instructions %-change: -11.45% -7.88%
Instructions are helped.
total bundles in shared programs: 25825 -> 25670 (-0.60%)
bundles in affected programs: 2057 -> 1902 (-7.54%)
helped: 53
HURT: 0
helped stats (abs) min: 1 max: 26 x̄: 2.92 x̃: 2
helped stats (rel) min: 2.86% max: 30.00% x̄: 8.64% x̃: 8.33%
95% mean confidence interval for bundles value: -3.93 -1.92
95% mean confidence interval for bundles %-change: -10.69% -6.59%
Bundles are helped.
total quadwords in shared programs: 41359 -> 41055 (-0.74%)
quadwords in affected programs: 3801 -> 3497 (-8.00%)
helped: 57
HURT: 0
helped stats (abs) min: 1 max: 57 x̄: 5.33 x̃: 4
helped stats (rel) min: 1.92% max: 21.05% x̄: 8.22% x̃: 6.67%
95% mean confidence interval for quadwords value: -7.35 -3.32
95% mean confidence interval for quadwords %-change: -9.54% -6.90%
Quadwords are helped.
total registers in shared programs: 3849 -> 3807 (-1.09%)
registers in affected programs: 167 -> 125 (-25.15%)
helped: 32
HURT: 1
helped stats (abs) min: 1 max: 3 x̄: 1.34 x̃: 1
helped stats (rel) min: 20.00% max: 50.00% x̄: 26.35% x̃: 20.00%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 16.67% max: 16.67% x̄: 16.67% x̃: 16.67%
95% mean confidence interval for registers value: -1.54 -1.00
95% mean confidence interval for registers %-change: -29.41% -20.69%
Registers are helped.
total threads in shared programs: 2471 -> 2520 (1.98%)
threads in affected programs: 49 -> 98 (100.00%)
helped: 25
HURT: 0
helped stats (abs) min: 1 max: 2 x̄: 1.96 x̃: 2
helped stats (rel) min: 100.00% max: 100.00% x̄: 100.00% x̃: 100.00%
95% mean confidence interval for threads value: 1.88 2.04
95% mean confidence interval for threads %-change: 100.00% 100.00%
Threads are [helped].
total spills in shared programs: 168 -> 168 (0.00%)
spills in affected programs: 0 -> 0
helped: 0
HURT: 0
total fills in shared programs: 186 -> 186 (0.00%)
fills in affected programs: 0 -> 0
helped: 0
HURT: 0
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4999>
2020-05-11 15:02:49 +01:00
|
|
|
# This section contains optimizations to propagate downsizing conversions of
|
|
|
|
# constructed vectors into vectors of downsized components. Whether this is
|
|
|
|
# useful depends on the SIMD semantics of the backend. On a true SIMD machine,
|
|
|
|
# this reduces the register pressure of the vector itself and often enables the
|
|
|
|
# conversions to be eliminated via other algebraic rules or constant folding.
|
|
|
|
# In the worst case on a SIMD architecture, the propagated conversions may be
|
|
|
|
# revectorized via nir_opt_vectorize so instruction count is minimally
|
|
|
|
# impacted.
|
|
|
|
#
|
|
|
|
# On a machine with SIMD-within-a-register only, this actually
|
|
|
|
# counterintuitively hurts instruction count. These machines are the same that
|
|
|
|
# require vectorize_vec2_16bit, so we predicate the optimizations on that flag
|
|
|
|
# not being set.
|
|
|
|
#
|
|
|
|
# Finally for scalar architectures, there should be no difference in generated
|
|
|
|
# code since it all ends up scalarized at the end, but it might minimally help
|
|
|
|
# compile-times.
|
|
|
|
|
|
|
|
for i in range(2, 4 + 1):
|
|
|
|
for T in ('f', 'u', 'i'):
|
|
|
|
vec_inst = ('vec' + str(i),)
|
|
|
|
|
|
|
|
indices = ['a', 'b', 'c', 'd']
|
|
|
|
suffix_in = tuple((indices[j] + '@32') for j in range(i))
|
|
|
|
|
|
|
|
to_16 = '{}2{}16'.format(T, T)
|
|
|
|
to_mp = '{}2{}mp'.format(T, T)
|
|
|
|
|
|
|
|
out_16 = tuple((to_16, indices[j]) for j in range(i))
|
|
|
|
out_mp = tuple((to_mp, indices[j]) for j in range(i))
|
|
|
|
|
|
|
|
optimizations += [
|
|
|
|
((to_16, vec_inst + suffix_in), vec_inst + out_16, '!options->vectorize_vec2_16bit'),
|
|
|
|
]
|
2020-09-04 06:51:49 +01:00
|
|
|
# u2ump doesn't exist, because it's equal to i2imp
|
|
|
|
if T in ['f', 'i']:
|
|
|
|
optimizations += [
|
|
|
|
((to_mp, vec_inst + suffix_in), vec_inst + out_mp, '!options->vectorize_vec2_16bit')
|
|
|
|
]
|
nir: Propagate *2*16 conversions into vectors
If we have code like:
('f2f16', ('vec2', ('f2f32', 'a@16'), '#b@32'))
We would like to eliminate the conversions, but the existing rules can't
see into the the (heterogenous) vector. So instead of trying to
eliminate in one pass, we add opts to propagate the f2f16 into the
vector. Even if nothing further happens, this is often a win since then
the created vector is smaller (half2 instead of float2). Hence the above
gets transformed to
('vec2', ('f2f16', ('f2f32', 'a@16')), ('f2f16', '#b@32'))
Then the existing f2f16(f2f32) rule will kick in for the first component
and constant folding will for the second and we'll be left with
('vec2', 'a@16', '#b@16')
...eliminating all conversions.
v2: Predicate on !options->vectorize_vec2_16bit. As discussed, this
optimization helps greatly on true vector architectures (like Midgard)
but wreaks havoc on more modern SIMD-within-a-register architectures
(like Bifrost and modern AMD). So let's predicate on that.
v3: Extend for integers as well and add a comment explaining the
transforms.
Results on Midgard (unfortunately a true SIMD architecture):
total instructions in shared programs: 51359 -> 50963 (-0.77%)
instructions in affected programs: 4523 -> 4127 (-8.76%)
helped: 53
HURT: 0
helped stats (abs) min: 1 max: 86 x̄: 7.47 x̃: 6
helped stats (rel) min: 1.71% max: 28.00% x̄: 9.66% x̃: 7.34%
95% mean confidence interval for instructions value: -10.58 -4.36
95% mean confidence interval for instructions %-change: -11.45% -7.88%
Instructions are helped.
total bundles in shared programs: 25825 -> 25670 (-0.60%)
bundles in affected programs: 2057 -> 1902 (-7.54%)
helped: 53
HURT: 0
helped stats (abs) min: 1 max: 26 x̄: 2.92 x̃: 2
helped stats (rel) min: 2.86% max: 30.00% x̄: 8.64% x̃: 8.33%
95% mean confidence interval for bundles value: -3.93 -1.92
95% mean confidence interval for bundles %-change: -10.69% -6.59%
Bundles are helped.
total quadwords in shared programs: 41359 -> 41055 (-0.74%)
quadwords in affected programs: 3801 -> 3497 (-8.00%)
helped: 57
HURT: 0
helped stats (abs) min: 1 max: 57 x̄: 5.33 x̃: 4
helped stats (rel) min: 1.92% max: 21.05% x̄: 8.22% x̃: 6.67%
95% mean confidence interval for quadwords value: -7.35 -3.32
95% mean confidence interval for quadwords %-change: -9.54% -6.90%
Quadwords are helped.
total registers in shared programs: 3849 -> 3807 (-1.09%)
registers in affected programs: 167 -> 125 (-25.15%)
helped: 32
HURT: 1
helped stats (abs) min: 1 max: 3 x̄: 1.34 x̃: 1
helped stats (rel) min: 20.00% max: 50.00% x̄: 26.35% x̃: 20.00%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 16.67% max: 16.67% x̄: 16.67% x̃: 16.67%
95% mean confidence interval for registers value: -1.54 -1.00
95% mean confidence interval for registers %-change: -29.41% -20.69%
Registers are helped.
total threads in shared programs: 2471 -> 2520 (1.98%)
threads in affected programs: 49 -> 98 (100.00%)
helped: 25
HURT: 0
helped stats (abs) min: 1 max: 2 x̄: 1.96 x̃: 2
helped stats (rel) min: 100.00% max: 100.00% x̄: 100.00% x̃: 100.00%
95% mean confidence interval for threads value: 1.88 2.04
95% mean confidence interval for threads %-change: 100.00% 100.00%
Threads are [helped].
total spills in shared programs: 168 -> 168 (0.00%)
spills in affected programs: 0 -> 0
helped: 0
HURT: 0
total fills in shared programs: 186 -> 186 (0.00%)
fills in affected programs: 0 -> 0
helped: 0
HURT: 0
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4999>
2020-05-11 15:02:49 +01:00
|
|
|
|
2017-01-13 06:25:11 +00:00
|
|
|
# This section contains "late" optimizations that should be run before
|
|
|
|
# creating ffmas and calling regular optimizations for the final time.
|
|
|
|
# Optimizations should go here if they help code generation and conflict
|
|
|
|
# with the regular optimizations.
|
|
|
|
before_ffma_optimizations = [
|
|
|
|
# Propagate constants down multiplication chains
|
|
|
|
(('~fmul(is_used_once)', ('fmul(is_used_once)', 'a(is_not_const)', '#b'), 'c(is_not_const)'), ('fmul', ('fmul', a, c), b)),
|
|
|
|
(('imul(is_used_once)', ('imul(is_used_once)', 'a(is_not_const)', '#b'), 'c(is_not_const)'), ('imul', ('imul', a, c), b)),
|
|
|
|
(('~fadd(is_used_once)', ('fadd(is_used_once)', 'a(is_not_const)', '#b'), 'c(is_not_const)'), ('fadd', ('fadd', a, c), b)),
|
|
|
|
(('iadd(is_used_once)', ('iadd(is_used_once)', 'a(is_not_const)', '#b'), 'c(is_not_const)'), ('iadd', ('iadd', a, c), b)),
|
|
|
|
|
|
|
|
(('~fadd', ('fmul', a, b), ('fmul', a, c)), ('fmul', a, ('fadd', b, c))),
|
|
|
|
(('iadd', ('imul', a, b), ('imul', a, c)), ('imul', a, ('iadd', b, c))),
|
|
|
|
(('~fadd', ('fneg', a), a), 0.0),
|
|
|
|
(('iadd', ('ineg', a), a), 0),
|
|
|
|
(('iadd', ('ineg', a), ('iadd', a, b)), b),
|
|
|
|
(('iadd', a, ('iadd', ('ineg', a), b)), b),
|
|
|
|
(('~fadd', ('fneg', a), ('fadd', a, b)), b),
|
|
|
|
(('~fadd', a, ('fadd', ('fneg', a), b)), b),
|
2018-08-23 03:15:15 +01:00
|
|
|
|
2020-08-11 23:49:37 +01:00
|
|
|
(('~flrp', ('fadd(is_used_once)', a, -1.0), ('fadd(is_used_once)', a, 1.0), d), ('fadd', ('flrp', -1.0, 1.0, d), a)),
|
|
|
|
(('~flrp', ('fadd(is_used_once)', a, 1.0), ('fadd(is_used_once)', a, -1.0), d), ('fadd', ('flrp', 1.0, -1.0, d), a)),
|
|
|
|
(('~flrp', ('fadd(is_used_once)', a, '#b'), ('fadd(is_used_once)', a, '#c'), d), ('fadd', ('fmul', d, ('fadd', c, ('fneg', b))), ('fadd', a, b))),
|
2017-01-13 06:25:11 +00:00
|
|
|
]
|
|
|
|
|
2015-03-24 00:11:49 +00:00
|
|
|
# This section contains "late" optimizations that should be run after the
|
|
|
|
# regular optimizations have finished. Optimizations should go here if
|
|
|
|
# they help code generation but do not necessarily produce code that is
|
|
|
|
# more easily optimizable.
|
|
|
|
late_optimizations = [
|
2020-07-08 01:30:42 +01:00
|
|
|
# The rearrangements are fine w.r.t. NaN. However, they produce incorrect
|
|
|
|
# results if one operand is +Inf and the other is -Inf.
|
|
|
|
#
|
|
|
|
# 1. Inf + -Inf = NaN
|
|
|
|
# 2. ∀x: x + NaN = NaN and x - NaN = NaN
|
|
|
|
# 3. ∀x: x != NaN = true
|
|
|
|
# 4. ∀x, ∀ cmp ∈ {<, >, ≤, ≥, =}: x cmp NaN = false
|
|
|
|
#
|
|
|
|
# a=Inf, b=-Inf a=-Inf, b=Inf a=NaN b=NaN
|
|
|
|
# (a+b) < 0 false false false false
|
|
|
|
# a < -b false false false false
|
|
|
|
# -(a+b) < 0 false false false false
|
|
|
|
# -a < b false false false false
|
|
|
|
# (a+b) >= 0 false false false false
|
|
|
|
# a >= -b true true false false
|
|
|
|
# -(a+b) >= 0 false false false false
|
|
|
|
# -a >= b true true false false
|
|
|
|
# (a+b) == 0 false false false false
|
|
|
|
# a == -b true true false false
|
|
|
|
# (a+b) != 0 true true true true
|
|
|
|
# a != -b false false true true
|
2018-01-11 02:50:58 +00:00
|
|
|
(('flt', ('fadd(is_used_once)', a, b), 0.0), ('flt', a, ('fneg', b))),
|
|
|
|
(('flt', ('fneg(is_used_once)', ('fadd(is_used_once)', a, b)), 0.0), ('flt', ('fneg', a), b)),
|
2021-02-02 18:18:42 +00:00
|
|
|
(('flt', 0.0, ('fadd(is_used_once)', a, b) ), ('flt', ('fneg', a), b)),
|
|
|
|
(('flt', 0.0, ('fneg(is_used_once)', ('fadd(is_used_once)', a, b))), ('flt', a, ('fneg', b))),
|
2018-01-11 02:50:58 +00:00
|
|
|
(('~fge', ('fadd(is_used_once)', a, b), 0.0), ('fge', a, ('fneg', b))),
|
|
|
|
(('~fge', ('fneg(is_used_once)', ('fadd(is_used_once)', a, b)), 0.0), ('fge', ('fneg', a), b)),
|
2021-02-02 18:18:42 +00:00
|
|
|
(('~fge', 0.0, ('fadd(is_used_once)', a, b) ), ('fge', ('fneg', a), b)),
|
|
|
|
(('~fge', 0.0, ('fneg(is_used_once)', ('fadd(is_used_once)', a, b))), ('fge', a, ('fneg', b))),
|
2018-01-11 02:50:58 +00:00
|
|
|
(('~feq', ('fadd(is_used_once)', a, b), 0.0), ('feq', a, ('fneg', b))),
|
|
|
|
(('~fneu', ('fadd(is_used_once)', a, b), 0.0), ('fneu', a, ('fneg', b))),
|
2016-03-17 18:31:48 +00:00
|
|
|
|
2020-08-11 02:34:37 +01:00
|
|
|
# If either source must be finite, then the original (a+b) cannot produce
|
|
|
|
# NaN due to Inf-Inf. The patterns and the replacements produce the same
|
|
|
|
# result if b is NaN. Therefore, the replacements are exact.
|
2018-01-11 02:50:58 +00:00
|
|
|
(('fge', ('fadd(is_used_once)', 'a(is_finite)', b), 0.0), ('fge', a, ('fneg', b))),
|
|
|
|
(('fge', ('fneg(is_used_once)', ('fadd(is_used_once)', 'a(is_finite)', b)), 0.0), ('fge', ('fneg', a), b)),
|
2021-02-02 18:18:42 +00:00
|
|
|
(('fge', 0.0, ('fadd(is_used_once)', 'a(is_finite)', b) ), ('fge', ('fneg', a), b)),
|
|
|
|
(('fge', 0.0, ('fneg(is_used_once)', ('fadd(is_used_once)', 'a(is_finite)', b))), ('fge', a, ('fneg', b))),
|
2018-01-11 02:50:58 +00:00
|
|
|
(('feq', ('fadd(is_used_once)', 'a(is_finite)', b), 0.0), ('feq', a, ('fneg', b))),
|
|
|
|
(('fneu', ('fadd(is_used_once)', 'a(is_finite)', b), 0.0), ('fneu', a, ('fneg', b))),
|
2020-08-11 02:34:37 +01:00
|
|
|
|
2019-03-05 20:08:29 +00:00
|
|
|
# nir_lower_to_source_mods will collapse this, but its existence during the
|
|
|
|
# optimization loop can prevent other optimizations.
|
|
|
|
(('fneg', ('fneg', a)), a),
|
|
|
|
|
2019-09-25 15:20:09 +01:00
|
|
|
# Subtractions get lowered during optimization, so we need to recombine them
|
2020-09-04 11:24:26 +01:00
|
|
|
(('fadd', a, ('fneg', 'b')), ('fsub', 'a', 'b'), 'options->has_fsub'),
|
2020-08-27 14:35:04 +01:00
|
|
|
(('fneg', a), ('fmul', a, -1.0), 'options->lower_fneg'),
|
2020-09-04 11:24:26 +01:00
|
|
|
(('iadd', a, ('ineg', 'b')), ('isub', 'a', 'b'), 'options->has_isub || options->lower_ineg'),
|
2020-08-27 14:35:04 +01:00
|
|
|
(('ineg', a), ('isub', 0, a), 'options->lower_ineg'),
|
2020-01-10 21:59:54 +00:00
|
|
|
(('iabs', a), ('imax', a, ('ineg', a)), 'options->lower_iabs'),
|
2020-09-24 16:46:31 +01:00
|
|
|
(('~fadd@16', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma16'),
|
|
|
|
(('~fadd@32', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma32'),
|
|
|
|
(('~fadd@64', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma64'),
|
2019-09-25 15:20:09 +01:00
|
|
|
|
2021-06-29 01:41:20 +01:00
|
|
|
(('iadd', ('iadd(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), 'c(is_not_const)'), ('iadd3', a, b, c), 'options->has_iadd3'),
|
|
|
|
(('iadd', ('isub(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), 'c(is_not_const)'), ('iadd3', a, ('ineg', b), c), 'options->has_iadd3'),
|
|
|
|
(('isub', ('isub(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), 'c(is_not_const)'), ('iadd3', a, ('ineg', b), ('ineg', c)), 'options->has_iadd3'),
|
|
|
|
|
2019-03-05 22:54:35 +00:00
|
|
|
# These are duplicated from the main optimizations table. The late
|
|
|
|
# patterns that rearrange expressions like x - .5 < 0 to x < .5 can create
|
|
|
|
# new patterns like these. The patterns that compare with zero are removed
|
|
|
|
# because they are unlikely to be created in by anything in
|
|
|
|
# late_optimizations.
|
|
|
|
(('flt', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('flt', b, a)),
|
|
|
|
(('fge', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fge', a, b)),
|
|
|
|
(('feq', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('feq', a, b)),
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fneu', a, b)),
|
2019-03-05 22:54:35 +00:00
|
|
|
|
|
|
|
(('fge', ('fsat(is_used_once)', a), 1.0), ('fge', a, 1.0)),
|
|
|
|
|
2018-01-11 22:14:25 +00:00
|
|
|
(('~fge', ('fmin(is_used_once)', ('fadd(is_used_once)', a, b), ('fadd', c, d)), 0.0), ('iand', ('fge', a, ('fneg', b)), ('fge', c, ('fneg', d)))),
|
|
|
|
|
2019-03-06 22:07:18 +00:00
|
|
|
(('flt', ('fneg', a), ('fneg', b)), ('flt', b, a)),
|
|
|
|
(('fge', ('fneg', a), ('fneg', b)), ('fge', b, a)),
|
|
|
|
(('feq', ('fneg', a), ('fneg', b)), ('feq', b, a)),
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('fneg', a), ('fneg', b)), ('fneu', b, a)),
|
2019-03-06 22:07:18 +00:00
|
|
|
(('flt', ('fneg', a), -1.0), ('flt', 1.0, a)),
|
|
|
|
(('flt', -1.0, ('fneg', a)), ('flt', a, 1.0)),
|
|
|
|
(('fge', ('fneg', a), -1.0), ('fge', 1.0, a)),
|
|
|
|
(('fge', -1.0, ('fneg', a)), ('fge', a, 1.0)),
|
2020-08-18 18:51:57 +01:00
|
|
|
(('fneu', ('fneg', a), -1.0), ('fneu', 1.0, a)),
|
2019-03-06 22:07:18 +00:00
|
|
|
(('feq', -1.0, ('fneg', a)), ('feq', a, 1.0)),
|
|
|
|
|
|
|
|
(('ior', a, a), a),
|
|
|
|
(('iand', a, a), a),
|
|
|
|
|
2018-03-28 06:57:07 +01:00
|
|
|
(('~fadd', ('fneg(is_used_once)', ('fsat(is_used_once)', 'a(is_not_fmul)')), 1.0), ('fsat', ('fadd', 1.0, ('fneg', a)))),
|
|
|
|
|
2020-06-20 22:33:57 +01:00
|
|
|
(('fdot2', a, b), ('fdot2_replicated', a, b), 'options->fdot_replicates'),
|
|
|
|
(('fdot3', a, b), ('fdot3_replicated', a, b), 'options->fdot_replicates'),
|
|
|
|
(('fdot4', a, b), ('fdot4_replicated', a, b), 'options->fdot_replicates'),
|
2015-09-23 00:54:27 +01:00
|
|
|
(('fdph', a, b), ('fdph_replicated', a, b), 'options->fdot_replicates'),
|
2017-01-03 11:54:48 +00:00
|
|
|
|
2020-08-11 23:49:37 +01:00
|
|
|
(('~flrp', ('fadd(is_used_once)', a, b), ('fadd(is_used_once)', a, c), d), ('fadd', ('flrp', b, c, d), a)),
|
2018-08-23 03:15:15 +01:00
|
|
|
|
2018-08-06 21:07:59 +01:00
|
|
|
# A similar operation could apply to any ffma(#a, b, #(-a/2)), but this
|
|
|
|
# particular operation is common for expanding values stored in a texture
|
|
|
|
# from [0,1] to [-1,1].
|
|
|
|
(('~ffma@32', a, 2.0, -1.0), ('flrp', -1.0, 1.0, a ), '!options->lower_flrp32'),
|
|
|
|
(('~ffma@32', a, -2.0, -1.0), ('flrp', -1.0, 1.0, ('fneg', a)), '!options->lower_flrp32'),
|
|
|
|
(('~ffma@32', a, -2.0, 1.0), ('flrp', 1.0, -1.0, a ), '!options->lower_flrp32'),
|
|
|
|
(('~ffma@32', a, 2.0, 1.0), ('flrp', 1.0, -1.0, ('fneg', a)), '!options->lower_flrp32'),
|
|
|
|
(('~fadd@32', ('fmul(is_used_once)', 2.0, a), -1.0), ('flrp', -1.0, 1.0, a ), '!options->lower_flrp32'),
|
|
|
|
(('~fadd@32', ('fmul(is_used_once)', -2.0, a), -1.0), ('flrp', -1.0, 1.0, ('fneg', a)), '!options->lower_flrp32'),
|
|
|
|
(('~fadd@32', ('fmul(is_used_once)', -2.0, a), 1.0), ('flrp', 1.0, -1.0, a ), '!options->lower_flrp32'),
|
|
|
|
(('~fadd@32', ('fmul(is_used_once)', 2.0, a), 1.0), ('flrp', 1.0, -1.0, ('fneg', a)), '!options->lower_flrp32'),
|
|
|
|
|
2018-08-06 21:05:08 +01:00
|
|
|
# flrp(a, b, a)
|
|
|
|
# a*(1-a) + b*a
|
|
|
|
# a + -a*a + a*b (1)
|
|
|
|
# a + a*(b - a)
|
|
|
|
# Option 1: ffma(a, (b-a), a)
|
|
|
|
#
|
|
|
|
# Alternately, after (1):
|
|
|
|
# a*(1+b) + -a*a
|
|
|
|
# a*((1+b) + -a)
|
|
|
|
#
|
|
|
|
# Let b=1
|
|
|
|
#
|
|
|
|
# Option 2: ffma(a, 2, -(a*a))
|
|
|
|
# Option 3: ffma(a, 2, (-a)*a)
|
|
|
|
# Option 4: ffma(a, -a, (2*a)
|
|
|
|
# Option 5: a * (2 - a)
|
|
|
|
#
|
|
|
|
# There are a lot of other possible combinations.
|
|
|
|
(('~ffma@32', ('fadd', b, ('fneg', a)), a, a), ('flrp', a, b, a), '!options->lower_flrp32'),
|
|
|
|
(('~ffma@32', a, 2.0, ('fneg', ('fmul', a, a))), ('flrp', a, 1.0, a), '!options->lower_flrp32'),
|
|
|
|
(('~ffma@32', a, 2.0, ('fmul', ('fneg', a), a)), ('flrp', a, 1.0, a), '!options->lower_flrp32'),
|
|
|
|
(('~ffma@32', a, ('fneg', a), ('fmul', 2.0, a)), ('flrp', a, 1.0, a), '!options->lower_flrp32'),
|
|
|
|
(('~fmul@32', a, ('fadd', 2.0, ('fneg', a))), ('flrp', a, 1.0, a), '!options->lower_flrp32'),
|
|
|
|
|
2017-01-12 10:51:56 +00:00
|
|
|
# we do these late so that we don't get in the way of creating ffmas
|
|
|
|
(('fmin', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmin', a, b))),
|
|
|
|
(('fmax', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmax', a, b))),
|
2018-12-03 22:41:07 +00:00
|
|
|
|
2019-11-02 02:53:06 +00:00
|
|
|
# Putting this in 'optimizations' interferes with the bcsel(a, op(b, c),
|
|
|
|
# op(b, d)) => op(b, bcsel(a, c, d)) transformations. I do not know why.
|
|
|
|
(('bcsel', ('feq', ('fsqrt', 'a(is_not_negative)'), 0.0), intBitsToFloat(0x7f7fffff), ('frsq', a)),
|
|
|
|
('fmin', ('frsq', a), intBitsToFloat(0x7f7fffff))),
|
|
|
|
|
2019-06-06 01:23:11 +01:00
|
|
|
# Things that look like DPH in the source shader may get expanded to
|
|
|
|
# something that looks like dot(v1.xyz, v2.xyz) + v1.w by the time it gets
|
|
|
|
# to NIR. After FFMA is generated, this can look like:
|
|
|
|
#
|
|
|
|
# fadd(ffma(v1.z, v2.z, ffma(v1.y, v2.y, fmul(v1.x, v2.x))), v1.w)
|
|
|
|
#
|
|
|
|
# Reassociate the last addition into the first multiplication.
|
2019-08-31 19:40:32 +01:00
|
|
|
#
|
|
|
|
# Some shaders do not use 'invariant' in vertex and (possibly) geometry
|
|
|
|
# shader stages on some outputs that are intended to be invariant. For
|
|
|
|
# various reasons, this optimization may not be fully applied in all
|
|
|
|
# shaders used for different rendering passes of the same geometry. This
|
|
|
|
# can result in Z-fighting artifacts (at best). For now, disable this
|
|
|
|
# optimization in these stages. See bugzilla #111490. In tessellation
|
|
|
|
# stages applications seem to use 'precise' when necessary, so allow the
|
|
|
|
# optimization in those stages.
|
2019-06-06 01:23:11 +01:00
|
|
|
(('~fadd', ('ffma(is_used_once)', a, b, ('ffma', c, d, ('fmul', 'e(is_not_const_and_not_fsign)', 'f(is_not_const_and_not_fsign)'))), 'g(is_not_const)'),
|
2019-08-31 19:40:32 +01:00
|
|
|
('ffma', a, b, ('ffma', c, d, ('ffma', e, 'f', 'g'))), '(info->stage != MESA_SHADER_VERTEX && info->stage != MESA_SHADER_GEOMETRY) && !options->intel_vec4'),
|
|
|
|
(('~fadd', ('ffma(is_used_once)', a, b, ('fmul', 'c(is_not_const_and_not_fsign)', 'd(is_not_const_and_not_fsign)') ), 'e(is_not_const)'),
|
|
|
|
('ffma', a, b, ('ffma', c, d, e)), '(info->stage != MESA_SHADER_VERTEX && info->stage != MESA_SHADER_GEOMETRY) && !options->intel_vec4'),
|
2021-01-21 04:38:45 +00:00
|
|
|
(('~fadd', ('fneg', ('ffma(is_used_once)', a, b, ('ffma', c, d, ('fmul', 'e(is_not_const_and_not_fsign)', 'f(is_not_const_and_not_fsign)')))), 'g(is_not_const)'),
|
|
|
|
('ffma', ('fneg', a), b, ('ffma', ('fneg', c), d, ('ffma', ('fneg', e), 'f', 'g'))), '(info->stage != MESA_SHADER_VERTEX && info->stage != MESA_SHADER_GEOMETRY) && !options->intel_vec4'),
|
2019-10-09 11:36:22 +01:00
|
|
|
|
2020-03-06 21:22:45 +00:00
|
|
|
# Section 8.8 (Integer Functions) of the GLSL 4.60 spec says:
|
|
|
|
#
|
|
|
|
# If bits is zero, the result will be zero.
|
|
|
|
#
|
|
|
|
# These prevent the next two lowerings generating incorrect results when
|
|
|
|
# count is zero.
|
|
|
|
(('ubfe', a, b, 0), 0),
|
|
|
|
(('ibfe', a, b, 0), 0),
|
|
|
|
|
|
|
|
# On Intel GPUs, BFE is a 3-source instruction. Like all 3-source
|
|
|
|
# instructions on Intel GPUs, it cannot have an immediate values as
|
|
|
|
# sources. There are also limitations on source register strides. As a
|
|
|
|
# result, it is very easy for 3-source instruction combined with either
|
|
|
|
# loads of immediate values or copies from weird register strides to be
|
|
|
|
# more expensive than the primitive instructions it represents.
|
|
|
|
(('ubfe', a, '#b', '#c'), ('iand', ('ushr', 0xffffffff, ('ineg', c)), ('ushr', a, b)), 'options->lower_bfe_with_two_constants'),
|
|
|
|
|
|
|
|
# b is the lowest order bit to be extracted and c is the number of bits to
|
|
|
|
# extract. The inner shift removes the bits above b + c by shifting left
|
|
|
|
# 32 - (b + c). ishl only sees the low 5 bits of the shift count, which is
|
|
|
|
# -(b + c). The outer shift moves the bit that was at b to bit zero.
|
|
|
|
# After the first shift, that bit is now at b + (32 - (b + c)) or 32 - c.
|
|
|
|
# This means that it must be shifted right by 32 - c or -c bits.
|
|
|
|
(('ibfe', a, '#b', '#c'), ('ishr', ('ishl', a, ('ineg', ('iadd', b, c))), ('ineg', c)), 'options->lower_bfe_with_two_constants'),
|
|
|
|
|
|
|
|
# Clean up no-op shifts that may result from the bfe lowerings.
|
|
|
|
(('ishl', a, 0), a),
|
|
|
|
(('ishl', a, -32), a),
|
|
|
|
(('ishr', a, 0), a),
|
|
|
|
(('ishr', a, -32), a),
|
|
|
|
(('ushr', a, 0), a),
|
2015-03-24 00:11:49 +00:00
|
|
|
]
|
|
|
|
|
2021-02-04 19:27:08 +00:00
|
|
|
# A few more extract cases we'd rather leave late
|
|
|
|
for N in [16, 32]:
|
|
|
|
aN = 'a@{0}'.format(N)
|
|
|
|
u2uM = 'u2u{0}'.format(M)
|
|
|
|
i2iM = 'i2i{0}'.format(M)
|
|
|
|
|
|
|
|
for x in ['u', 'i']:
|
|
|
|
x2xN = '{0}2{0}{1}'.format(x, N)
|
|
|
|
extract_x8 = 'extract_{0}8'.format(x)
|
|
|
|
extract_x16 = 'extract_{0}16'.format(x)
|
|
|
|
|
|
|
|
late_optimizations.extend([
|
|
|
|
((x2xN, ('u2u8', aN)), (extract_x8, a, 0), '!options->lower_extract_byte'),
|
|
|
|
((x2xN, ('i2i8', aN)), (extract_x8, a, 0), '!options->lower_extract_byte'),
|
|
|
|
])
|
|
|
|
|
|
|
|
if N > 16:
|
|
|
|
late_optimizations.extend([
|
|
|
|
((x2xN, ('u2u16', aN)), (extract_x16, a, 0), '!options->lower_extract_word'),
|
|
|
|
((x2xN, ('i2i16', aN)), (extract_x16, a, 0), '!options->lower_extract_word'),
|
|
|
|
])
|
|
|
|
|
2020-03-25 15:38:06 +00:00
|
|
|
# Byte insertion
|
|
|
|
late_optimizations.extend([(('ishl', ('extract_u8', 'a@32', 0), 8 * i), ('insert_u8', a, i), '!options->lower_insert_byte') for i in range(1, 4)])
|
|
|
|
late_optimizations.extend([(('iand', ('ishl', 'a@32', 8 * i), 0xff << (8 * i)), ('insert_u8', a, i), '!options->lower_insert_byte') for i in range(1, 4)])
|
|
|
|
late_optimizations.append((('ishl', 'a@32', 24), ('insert_u8', a, 3), '!options->lower_insert_byte'))
|
|
|
|
|
|
|
|
late_optimizations += [
|
|
|
|
# Word insertion
|
|
|
|
(('ishl', 'a@32', 16), ('insert_u16', a, 1), '!options->lower_insert_word'),
|
|
|
|
|
|
|
|
# Extract and then insert
|
|
|
|
(('insert_u8', ('extract_u8', 'a', 0), b), ('insert_u8', a, b)),
|
|
|
|
(('insert_u16', ('extract_u16', 'a', 0), b), ('insert_u16', a, b)),
|
|
|
|
]
|
2021-02-04 19:27:08 +00:00
|
|
|
|
2020-09-01 07:20:34 +01:00
|
|
|
# Integer sizes
|
|
|
|
for s in [8, 16, 32, 64]:
|
|
|
|
late_optimizations.extend([
|
|
|
|
(('iand', ('ine(is_used_once)', 'a@{}'.format(s), 0), ('ine', 'b@{}'.format(s), 0)), ('ine', ('umin', a, b), 0)),
|
|
|
|
(('ior', ('ieq(is_used_once)', 'a@{}'.format(s), 0), ('ieq', 'b@{}'.format(s), 0)), ('ieq', ('umin', a, b), 0)),
|
|
|
|
])
|
|
|
|
|
|
|
|
# Float sizes
|
|
|
|
for s in [16, 32, 64]:
|
|
|
|
late_optimizations.extend([
|
|
|
|
(('~fadd@{}'.format(s), 1.0, ('fmul(is_used_once)', c , ('fadd', b, -1.0 ))), ('fadd', ('fadd', 1.0, ('fneg', c)), ('fmul', b, c)), 'options->lower_flrp{}'.format(s)),
|
|
|
|
(('bcsel', a, 0, ('b2f{}'.format(s), ('inot', 'b@bool'))), ('b2f{}'.format(s), ('inot', ('ior', a, b)))),
|
|
|
|
])
|
|
|
|
|
2019-11-01 23:23:09 +00:00
|
|
|
for op in ['fadd']:
|
|
|
|
late_optimizations += [
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c), (op, b, d)), (op, b, ('bcsel', a, c, d))),
|
|
|
|
(('bcsel', a, (op, b, c), (op + '(is_used_once)', b, d)), (op, b, ('bcsel', a, c, d))),
|
|
|
|
]
|
|
|
|
|
|
|
|
for op in ['ffma']:
|
|
|
|
late_optimizations += [
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c, d), (op, b, c, e)), (op, b, c, ('bcsel', a, d, e))),
|
|
|
|
(('bcsel', a, (op, b, c, d), (op + '(is_used_once)', b, c, e)), (op, b, c, ('bcsel', a, d, e))),
|
|
|
|
|
|
|
|
(('bcsel', a, (op + '(is_used_once)', b, c, d), (op, b, e, d)), (op, b, ('bcsel', a, c, e), d)),
|
|
|
|
(('bcsel', a, (op, b, c, d), (op + '(is_used_once)', b, e, d)), (op, b, ('bcsel', a, c, e), d)),
|
|
|
|
]
|
|
|
|
|
2020-09-06 02:09:38 +01:00
|
|
|
# mediump: If an opcode is surrounded by conversions, remove the conversions.
|
|
|
|
# The rationale is that type conversions + the low precision opcode are more
|
|
|
|
# expensive that the same arithmetic opcode at higher precision.
|
|
|
|
#
|
|
|
|
# This must be done in late optimizations, because we need normal optimizations to
|
|
|
|
# first eliminate temporary up-conversions such as in op1(f2fmp(f2f32(op2()))).
|
|
|
|
#
|
|
|
|
# Unary opcodes
|
|
|
|
for op in ['fabs', 'fceil', 'fcos', 'fddx', 'fddx_coarse', 'fddx_fine', 'fddy',
|
|
|
|
'fddy_coarse', 'fddy_fine', 'fexp2', 'ffloor', 'ffract', 'flog2', 'fneg',
|
|
|
|
'frcp', 'fround_even', 'frsq', 'fsat', 'fsign', 'fsin', 'fsqrt']:
|
|
|
|
late_optimizations += [(('~f2f32', (op, ('f2fmp', a))), (op, a))]
|
|
|
|
|
|
|
|
# Binary opcodes
|
|
|
|
for op in ['fadd', 'fdiv', 'fmax', 'fmin', 'fmod', 'fmul', 'fpow', 'frem']:
|
|
|
|
late_optimizations += [(('~f2f32', (op, ('f2fmp', a), ('f2fmp', b))), (op, a, b))]
|
|
|
|
|
|
|
|
# Ternary opcodes
|
|
|
|
for op in ['ffma', 'flrp']:
|
|
|
|
late_optimizations += [(('~f2f32', (op, ('f2fmp', a), ('f2fmp', b), ('f2fmp', c))), (op, a, b, c))]
|
|
|
|
|
|
|
|
# Comparison opcodes
|
|
|
|
for op in ['feq', 'fge', 'flt', 'fneu']:
|
|
|
|
late_optimizations += [(('~' + op, ('f2fmp', a), ('f2fmp', b)), (op, a, b))]
|
|
|
|
|
|
|
|
# Do this last, so that the f2fmp patterns above have effect.
|
|
|
|
late_optimizations += [
|
|
|
|
# Convert *2*mp instructions to concrete *2*16 instructions. At this point
|
|
|
|
# any conversions that could have been removed will have been removed in
|
|
|
|
# nir_opt_algebraic so any remaining ones are required.
|
|
|
|
(('f2fmp', a), ('f2f16', a)),
|
|
|
|
(('f2imp', a), ('f2i16', a)),
|
|
|
|
(('f2ump', a), ('f2u16', a)),
|
|
|
|
(('i2imp', a), ('i2i16', a)),
|
|
|
|
(('i2fmp', a), ('i2f16', a)),
|
|
|
|
(('i2imp', a), ('u2u16', a)),
|
|
|
|
(('u2fmp', a), ('u2f16', a)),
|
|
|
|
]
|
|
|
|
|
nir/algebraic: Distribute source modifiers into instructions
There are three main classes of cases that are helped by this change:
1. When the negation is applied to a value being type converted (e.g.,
float(-x)). This could possibly also be handled with more clever
code generation.
2. When the negation is applied to a phi node source (e.g., x = -(...);
at the end of a basic block). This was the original case that caught
my attention while looking at shader-db dumps.
3. When the negation is applied to the source of an instruction that
cannot have source modifiers. This includes texture instructions and
math box instructions on pre-Gen7 platforms (see more details below).
In many these cases the negation can be propagated into the instructions
that generate the value (e.g., -(a*b) = (-a)*b).
In addition to the operations implemtned in this patch, I also tried:
- frcp - Helped 6 or fewer shaders on Gen7+, and hurt just as many on
pre-Gen7. On Gen6 and earlier, frcp is a math box instruction, and
math box instructions cannot have source modifiers.
I suspect this is why so many more shaders are helped on Gen6 than on
Gen5 or Gen7. Gen6 supports OpenGL 3.3, so a lot more shaders
compile on it. A lot of these shaders may have things like cos(-x)
or rcp(-x) that could result in an explicit negation instruction.
- bcsel - Hurt a few shaders with none helped. bcsel operates on
integer sources, so the fabs or fneg cannot be a source modifier in
the bcsel itself.
- Integer instructions - No changes on any Intel platform.
Some notes about the shader-db results below.
- On Tiger Lake, a single Deus Ex fragment shader is hurt for both
spills and fills.
- On Haswell, a different Deus Ex fragment shader is hurt for both
spills and fills.
- On GM45, the "LOST: 1" and "GAINED: 1" is a single Left4Dead 2
(very high graphics settings, lol) fragment shader that upgrades
from SIMD8 to SIMD16.
v2: Add support for fsign. Add some patterns that remove redundant
negations and redundant absolute value rather than trying to push them
down the tree.
Tiger Lake
total instructions in shared programs: 17611333 -> 17586465 (-0.14%)
instructions in affected programs: 3033734 -> 3008866 (-0.82%)
helped: 10310
HURT: 632
helped stats (abs) min: 1 max: 35 x̄: 2.61 x̃: 1
helped stats (rel) min: 0.04% max: 16.67% x̄: 1.43% x̃: 1.01%
HURT stats (abs) min: 1 max: 47 x̄: 3.21 x̃: 2
HURT stats (rel) min: 0.04% max: 5.08% x̄: 0.88% x̃: 0.63%
95% mean confidence interval for instructions value: -2.33 -2.21
95% mean confidence interval for instructions %-change: -1.32% -1.27%
Instructions are helped.
total cycles in shared programs: 338365223 -> 338262252 (-0.03%)
cycles in affected programs: 125291811 -> 125188840 (-0.08%)
helped: 5224
HURT: 2031
helped stats (abs) min: 1 max: 5670 x̄: 46.73 x̃: 12
helped stats (rel) min: <.01% max: 34.78% x̄: 1.91% x̃: 0.97%
HURT stats (abs) min: 1 max: 2882 x̄: 69.50 x̃: 14
HURT stats (rel) min: <.01% max: 44.93% x̄: 2.35% x̃: 0.74%
95% mean confidence interval for cycles value: -18.71 -9.68
95% mean confidence interval for cycles %-change: -0.80% -0.63%
Cycles are helped.
total spills in shared programs: 8942 -> 8946 (0.04%)
spills in affected programs: 8 -> 12 (50.00%)
helped: 0
HURT: 1
total fills in shared programs: 9399 -> 9401 (0.02%)
fills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
Ice Lake
total instructions in shared programs: 16124348 -> 16102258 (-0.14%)
instructions in affected programs: 2830928 -> 2808838 (-0.78%)
helped: 11294
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.96 x̃: 1
helped stats (rel) min: 0.07% max: 17.65% x̄: 1.32% x̃: 0.93%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 3.45% max: 4.00% x̄: 3.72% x̃: 3.72%
95% mean confidence interval for instructions value: -1.99 -1.93
95% mean confidence interval for instructions %-change: -1.34% -1.29%
Instructions are helped.
total cycles in shared programs: 335393932 -> 335325794 (-0.02%)
cycles in affected programs: 123834609 -> 123766471 (-0.06%)
helped: 5034
HURT: 2128
helped stats (abs) min: 1 max: 3256 x̄: 43.39 x̃: 11
helped stats (rel) min: <.01% max: 35.79% x̄: 1.98% x̃: 1.00%
HURT stats (abs) min: 1 max: 2634 x̄: 70.63 x̃: 16
HURT stats (rel) min: <.01% max: 49.49% x̄: 2.73% x̃: 0.62%
95% mean confidence interval for cycles value: -13.66 -5.37
95% mean confidence interval for cycles %-change: -0.69% -0.48%
Cycles are helped.
LOST: 0
GAINED: 2
Skylake
total instructions in shared programs: 14949240 -> 14927930 (-0.14%)
instructions in affected programs: 2594756 -> 2573446 (-0.82%)
helped: 11000
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.94 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.91
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 324829346 -> 324821596 (<.01%)
cycles in affected programs: 121566087 -> 121558337 (<.01%)
helped: 4611
HURT: 2147
helped stats (abs) min: 1 max: 3715 x̄: 33.29 x̃: 10
helped stats (rel) min: <.01% max: 36.08% x̄: 1.94% x̃: 1.00%
HURT stats (abs) min: 1 max: 2551 x̄: 67.88 x̃: 16
HURT stats (rel) min: <.01% max: 53.79% x̄: 3.69% x̃: 0.89%
95% mean confidence interval for cycles value: -4.25 1.96
95% mean confidence interval for cycles %-change: -0.28% -0.02%
Inconclusive result (value mean confidence interval includes 0).
Broadwell
total instructions in shared programs: 14971203 -> 14949957 (-0.14%)
instructions in affected programs: 2635699 -> 2614453 (-0.81%)
helped: 10982
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.93 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.90
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 336215033 -> 336086458 (-0.04%)
cycles in affected programs: 127383198 -> 127254623 (-0.10%)
helped: 4884
HURT: 1963
helped stats (abs) min: 1 max: 25696 x̄: 51.78 x̃: 12
helped stats (rel) min: <.01% max: 58.28% x̄: 2.00% x̃: 1.05%
HURT stats (abs) min: 1 max: 3401 x̄: 63.33 x̃: 16
HURT stats (rel) min: <.01% max: 39.95% x̄: 2.20% x̃: 0.70%
95% mean confidence interval for cycles value: -29.99 -7.57
95% mean confidence interval for cycles %-change: -0.89% -0.71%
Cycles are helped.
total fills in shared programs: 24905 -> 24901 (-0.02%)
fills in affected programs: 117 -> 113 (-3.42%)
helped: 4
HURT: 0
LOST: 0
GAINED: 16
Haswell
total instructions in shared programs: 13148927 -> 13131528 (-0.13%)
instructions in affected programs: 2220941 -> 2203542 (-0.78%)
helped: 8017
HURT: 4
helped stats (abs) min: 1 max: 12 x̄: 2.17 x̃: 1
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.40% x̃: 0.93%
HURT stats (abs) min: 1 max: 7 x̄: 2.50 x̃: 1
HURT stats (rel) min: 0.33% max: 4.76% x̄: 2.73% x̃: 2.91%
95% mean confidence interval for instructions value: -2.21 -2.13
95% mean confidence interval for instructions %-change: -1.43% -1.37%
Instructions are helped.
total cycles in shared programs: 321221791 -> 321079870 (-0.04%)
cycles in affected programs: 126886055 -> 126744134 (-0.11%)
helped: 4674
HURT: 1729
helped stats (abs) min: 1 max: 23654 x̄: 56.47 x̃: 16
helped stats (rel) min: <.01% max: 53.22% x̄: 2.13% x̃: 1.05%
HURT stats (abs) min: 1 max: 3694 x̄: 70.58 x̃: 18
HURT stats (rel) min: <.01% max: 63.06% x̄: 2.48% x̃: 0.90%
95% mean confidence interval for cycles value: -33.31 -11.02
95% mean confidence interval for cycles %-change: -0.99% -0.78%
Cycles are helped.
total spills in shared programs: 19872 -> 19874 (0.01%)
spills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
total fills in shared programs: 20941 -> 20941 (0.00%)
fills in affected programs: 62 -> 62 (0.00%)
helped: 1
HURT: 1
LOST: 0
GAINED: 8
Ivy Bridge
total instructions in shared programs: 11875553 -> 11853839 (-0.18%)
instructions in affected programs: 1553112 -> 1531398 (-1.40%)
helped: 7304
HURT: 3
helped stats (abs) min: 1 max: 16 x̄: 2.97 x̃: 2
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.62% x̃: 1.15%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.05% max: 3.33% x̄: 2.44% x̃: 2.94%
95% mean confidence interval for instructions value: -3.04 -2.90
95% mean confidence interval for instructions %-change: -1.65% -1.59%
Instructions are helped.
total cycles in shared programs: 178246425 -> 178184484 (-0.03%)
cycles in affected programs: 13702146 -> 13640205 (-0.45%)
helped: 4409
HURT: 1566
helped stats (abs) min: 1 max: 531 x̄: 24.52 x̃: 13
helped stats (rel) min: <.01% max: 38.67% x̄: 2.14% x̃: 1.02%
HURT stats (abs) min: 1 max: 356 x̄: 29.48 x̃: 10
HURT stats (rel) min: <.01% max: 64.73% x̄: 1.87% x̃: 0.70%
95% mean confidence interval for cycles value: -11.60 -9.14
95% mean confidence interval for cycles %-change: -1.19% -0.99%
Cycles are helped.
LOST: 0
GAINED: 10
Sandy Bridge
total instructions in shared programs: 10695740 -> 10667483 (-0.26%)
instructions in affected programs: 2337607 -> 2309350 (-1.21%)
helped: 10720
HURT: 1
helped stats (abs) min: 1 max: 49 x̄: 2.64 x̃: 2
helped stats (rel) min: 0.07% max: 20.00% x̄: 1.54% x̃: 1.13%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.04% max: 1.04% x̄: 1.04% x̃: 1.04%
95% mean confidence interval for instructions value: -2.69 -2.58
95% mean confidence interval for instructions %-change: -1.57% -1.51%
Instructions are helped.
total cycles in shared programs: 153478839 -> 153416223 (-0.04%)
cycles in affected programs: 22050900 -> 21988284 (-0.28%)
helped: 5342
HURT: 2200
helped stats (abs) min: 1 max: 1020 x̄: 20.34 x̃: 16
helped stats (rel) min: <.01% max: 24.05% x̄: 1.51% x̃: 0.86%
HURT stats (abs) min: 1 max: 335 x̄: 20.93 x̃: 6
HURT stats (rel) min: <.01% max: 20.18% x̄: 1.03% x̃: 0.30%
95% mean confidence interval for cycles value: -9.18 -7.42
95% mean confidence interval for cycles %-change: -0.82% -0.71%
Cycles are helped.
Iron Lake
total instructions in shared programs: 8114882 -> 8105574 (-0.11%)
instructions in affected programs: 1232504 -> 1223196 (-0.76%)
helped: 4109
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.27 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 0.99% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.94% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.31 -2.21
95% mean confidence interval for instructions %-change: -1.01% -0.96%
Instructions are helped.
total cycles in shared programs: 188504036 -> 188466296 (-0.02%)
cycles in affected programs: 31203798 -> 31166058 (-0.12%)
helped: 3447
HURT: 36
helped stats (abs) min: 2 max: 92 x̄: 11.03 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.21% x̃: 0.13%
HURT stats (abs) min: 2 max: 30 x̄: 7.33 x̃: 6
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.18% x̃: 0.10%
95% mean confidence interval for cycles value: -11.16 -10.51
95% mean confidence interval for cycles %-change: -0.22% -0.20%
Cycles are helped.
LOST: 0
GAINED: 1
GM45
total instructions in shared programs: 4989697 -> 4984531 (-0.10%)
instructions in affected programs: 703952 -> 698786 (-0.73%)
helped: 2493
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.07 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 1.03% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.95% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.13 -2.01
95% mean confidence interval for instructions %-change: -1.07% -0.99%
Instructions are helped.
total cycles in shared programs: 128929136 -> 128903886 (-0.02%)
cycles in affected programs: 21583096 -> 21557846 (-0.12%)
helped: 2214
HURT: 17
helped stats (abs) min: 2 max: 92 x̄: 11.44 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.24% x̃: 0.13%
HURT stats (abs) min: 2 max: 8 x̄: 4.24 x̃: 4
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.20% x̃: 0.09%
95% mean confidence interval for cycles value: -11.75 -10.88
95% mean confidence interval for cycles %-change: -0.25% -0.22%
Cycles are helped.
LOST: 1
GAINED: 1
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1359>
2019-07-15 23:55:00 +01:00
|
|
|
distribute_src_mods = [
|
|
|
|
# Try to remove some spurious negations rather than pushing them down.
|
|
|
|
(('fmul', ('fneg', a), ('fneg', b)), ('fmul', a, b)),
|
|
|
|
(('ffma', ('fneg', a), ('fneg', b), c), ('ffma', a, b, c)),
|
2020-06-20 22:33:57 +01:00
|
|
|
(('fdot2_replicated', ('fneg', a), ('fneg', b)), ('fdot2_replicated', a, b)),
|
|
|
|
(('fdot3_replicated', ('fneg', a), ('fneg', b)), ('fdot3_replicated', a, b)),
|
|
|
|
(('fdot4_replicated', ('fneg', a), ('fneg', b)), ('fdot4_replicated', a, b)),
|
nir/algebraic: Distribute source modifiers into instructions
There are three main classes of cases that are helped by this change:
1. When the negation is applied to a value being type converted (e.g.,
float(-x)). This could possibly also be handled with more clever
code generation.
2. When the negation is applied to a phi node source (e.g., x = -(...);
at the end of a basic block). This was the original case that caught
my attention while looking at shader-db dumps.
3. When the negation is applied to the source of an instruction that
cannot have source modifiers. This includes texture instructions and
math box instructions on pre-Gen7 platforms (see more details below).
In many these cases the negation can be propagated into the instructions
that generate the value (e.g., -(a*b) = (-a)*b).
In addition to the operations implemtned in this patch, I also tried:
- frcp - Helped 6 or fewer shaders on Gen7+, and hurt just as many on
pre-Gen7. On Gen6 and earlier, frcp is a math box instruction, and
math box instructions cannot have source modifiers.
I suspect this is why so many more shaders are helped on Gen6 than on
Gen5 or Gen7. Gen6 supports OpenGL 3.3, so a lot more shaders
compile on it. A lot of these shaders may have things like cos(-x)
or rcp(-x) that could result in an explicit negation instruction.
- bcsel - Hurt a few shaders with none helped. bcsel operates on
integer sources, so the fabs or fneg cannot be a source modifier in
the bcsel itself.
- Integer instructions - No changes on any Intel platform.
Some notes about the shader-db results below.
- On Tiger Lake, a single Deus Ex fragment shader is hurt for both
spills and fills.
- On Haswell, a different Deus Ex fragment shader is hurt for both
spills and fills.
- On GM45, the "LOST: 1" and "GAINED: 1" is a single Left4Dead 2
(very high graphics settings, lol) fragment shader that upgrades
from SIMD8 to SIMD16.
v2: Add support for fsign. Add some patterns that remove redundant
negations and redundant absolute value rather than trying to push them
down the tree.
Tiger Lake
total instructions in shared programs: 17611333 -> 17586465 (-0.14%)
instructions in affected programs: 3033734 -> 3008866 (-0.82%)
helped: 10310
HURT: 632
helped stats (abs) min: 1 max: 35 x̄: 2.61 x̃: 1
helped stats (rel) min: 0.04% max: 16.67% x̄: 1.43% x̃: 1.01%
HURT stats (abs) min: 1 max: 47 x̄: 3.21 x̃: 2
HURT stats (rel) min: 0.04% max: 5.08% x̄: 0.88% x̃: 0.63%
95% mean confidence interval for instructions value: -2.33 -2.21
95% mean confidence interval for instructions %-change: -1.32% -1.27%
Instructions are helped.
total cycles in shared programs: 338365223 -> 338262252 (-0.03%)
cycles in affected programs: 125291811 -> 125188840 (-0.08%)
helped: 5224
HURT: 2031
helped stats (abs) min: 1 max: 5670 x̄: 46.73 x̃: 12
helped stats (rel) min: <.01% max: 34.78% x̄: 1.91% x̃: 0.97%
HURT stats (abs) min: 1 max: 2882 x̄: 69.50 x̃: 14
HURT stats (rel) min: <.01% max: 44.93% x̄: 2.35% x̃: 0.74%
95% mean confidence interval for cycles value: -18.71 -9.68
95% mean confidence interval for cycles %-change: -0.80% -0.63%
Cycles are helped.
total spills in shared programs: 8942 -> 8946 (0.04%)
spills in affected programs: 8 -> 12 (50.00%)
helped: 0
HURT: 1
total fills in shared programs: 9399 -> 9401 (0.02%)
fills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
Ice Lake
total instructions in shared programs: 16124348 -> 16102258 (-0.14%)
instructions in affected programs: 2830928 -> 2808838 (-0.78%)
helped: 11294
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.96 x̃: 1
helped stats (rel) min: 0.07% max: 17.65% x̄: 1.32% x̃: 0.93%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 3.45% max: 4.00% x̄: 3.72% x̃: 3.72%
95% mean confidence interval for instructions value: -1.99 -1.93
95% mean confidence interval for instructions %-change: -1.34% -1.29%
Instructions are helped.
total cycles in shared programs: 335393932 -> 335325794 (-0.02%)
cycles in affected programs: 123834609 -> 123766471 (-0.06%)
helped: 5034
HURT: 2128
helped stats (abs) min: 1 max: 3256 x̄: 43.39 x̃: 11
helped stats (rel) min: <.01% max: 35.79% x̄: 1.98% x̃: 1.00%
HURT stats (abs) min: 1 max: 2634 x̄: 70.63 x̃: 16
HURT stats (rel) min: <.01% max: 49.49% x̄: 2.73% x̃: 0.62%
95% mean confidence interval for cycles value: -13.66 -5.37
95% mean confidence interval for cycles %-change: -0.69% -0.48%
Cycles are helped.
LOST: 0
GAINED: 2
Skylake
total instructions in shared programs: 14949240 -> 14927930 (-0.14%)
instructions in affected programs: 2594756 -> 2573446 (-0.82%)
helped: 11000
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.94 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.91
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 324829346 -> 324821596 (<.01%)
cycles in affected programs: 121566087 -> 121558337 (<.01%)
helped: 4611
HURT: 2147
helped stats (abs) min: 1 max: 3715 x̄: 33.29 x̃: 10
helped stats (rel) min: <.01% max: 36.08% x̄: 1.94% x̃: 1.00%
HURT stats (abs) min: 1 max: 2551 x̄: 67.88 x̃: 16
HURT stats (rel) min: <.01% max: 53.79% x̄: 3.69% x̃: 0.89%
95% mean confidence interval for cycles value: -4.25 1.96
95% mean confidence interval for cycles %-change: -0.28% -0.02%
Inconclusive result (value mean confidence interval includes 0).
Broadwell
total instructions in shared programs: 14971203 -> 14949957 (-0.14%)
instructions in affected programs: 2635699 -> 2614453 (-0.81%)
helped: 10982
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.93 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.90
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 336215033 -> 336086458 (-0.04%)
cycles in affected programs: 127383198 -> 127254623 (-0.10%)
helped: 4884
HURT: 1963
helped stats (abs) min: 1 max: 25696 x̄: 51.78 x̃: 12
helped stats (rel) min: <.01% max: 58.28% x̄: 2.00% x̃: 1.05%
HURT stats (abs) min: 1 max: 3401 x̄: 63.33 x̃: 16
HURT stats (rel) min: <.01% max: 39.95% x̄: 2.20% x̃: 0.70%
95% mean confidence interval for cycles value: -29.99 -7.57
95% mean confidence interval for cycles %-change: -0.89% -0.71%
Cycles are helped.
total fills in shared programs: 24905 -> 24901 (-0.02%)
fills in affected programs: 117 -> 113 (-3.42%)
helped: 4
HURT: 0
LOST: 0
GAINED: 16
Haswell
total instructions in shared programs: 13148927 -> 13131528 (-0.13%)
instructions in affected programs: 2220941 -> 2203542 (-0.78%)
helped: 8017
HURT: 4
helped stats (abs) min: 1 max: 12 x̄: 2.17 x̃: 1
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.40% x̃: 0.93%
HURT stats (abs) min: 1 max: 7 x̄: 2.50 x̃: 1
HURT stats (rel) min: 0.33% max: 4.76% x̄: 2.73% x̃: 2.91%
95% mean confidence interval for instructions value: -2.21 -2.13
95% mean confidence interval for instructions %-change: -1.43% -1.37%
Instructions are helped.
total cycles in shared programs: 321221791 -> 321079870 (-0.04%)
cycles in affected programs: 126886055 -> 126744134 (-0.11%)
helped: 4674
HURT: 1729
helped stats (abs) min: 1 max: 23654 x̄: 56.47 x̃: 16
helped stats (rel) min: <.01% max: 53.22% x̄: 2.13% x̃: 1.05%
HURT stats (abs) min: 1 max: 3694 x̄: 70.58 x̃: 18
HURT stats (rel) min: <.01% max: 63.06% x̄: 2.48% x̃: 0.90%
95% mean confidence interval for cycles value: -33.31 -11.02
95% mean confidence interval for cycles %-change: -0.99% -0.78%
Cycles are helped.
total spills in shared programs: 19872 -> 19874 (0.01%)
spills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
total fills in shared programs: 20941 -> 20941 (0.00%)
fills in affected programs: 62 -> 62 (0.00%)
helped: 1
HURT: 1
LOST: 0
GAINED: 8
Ivy Bridge
total instructions in shared programs: 11875553 -> 11853839 (-0.18%)
instructions in affected programs: 1553112 -> 1531398 (-1.40%)
helped: 7304
HURT: 3
helped stats (abs) min: 1 max: 16 x̄: 2.97 x̃: 2
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.62% x̃: 1.15%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.05% max: 3.33% x̄: 2.44% x̃: 2.94%
95% mean confidence interval for instructions value: -3.04 -2.90
95% mean confidence interval for instructions %-change: -1.65% -1.59%
Instructions are helped.
total cycles in shared programs: 178246425 -> 178184484 (-0.03%)
cycles in affected programs: 13702146 -> 13640205 (-0.45%)
helped: 4409
HURT: 1566
helped stats (abs) min: 1 max: 531 x̄: 24.52 x̃: 13
helped stats (rel) min: <.01% max: 38.67% x̄: 2.14% x̃: 1.02%
HURT stats (abs) min: 1 max: 356 x̄: 29.48 x̃: 10
HURT stats (rel) min: <.01% max: 64.73% x̄: 1.87% x̃: 0.70%
95% mean confidence interval for cycles value: -11.60 -9.14
95% mean confidence interval for cycles %-change: -1.19% -0.99%
Cycles are helped.
LOST: 0
GAINED: 10
Sandy Bridge
total instructions in shared programs: 10695740 -> 10667483 (-0.26%)
instructions in affected programs: 2337607 -> 2309350 (-1.21%)
helped: 10720
HURT: 1
helped stats (abs) min: 1 max: 49 x̄: 2.64 x̃: 2
helped stats (rel) min: 0.07% max: 20.00% x̄: 1.54% x̃: 1.13%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.04% max: 1.04% x̄: 1.04% x̃: 1.04%
95% mean confidence interval for instructions value: -2.69 -2.58
95% mean confidence interval for instructions %-change: -1.57% -1.51%
Instructions are helped.
total cycles in shared programs: 153478839 -> 153416223 (-0.04%)
cycles in affected programs: 22050900 -> 21988284 (-0.28%)
helped: 5342
HURT: 2200
helped stats (abs) min: 1 max: 1020 x̄: 20.34 x̃: 16
helped stats (rel) min: <.01% max: 24.05% x̄: 1.51% x̃: 0.86%
HURT stats (abs) min: 1 max: 335 x̄: 20.93 x̃: 6
HURT stats (rel) min: <.01% max: 20.18% x̄: 1.03% x̃: 0.30%
95% mean confidence interval for cycles value: -9.18 -7.42
95% mean confidence interval for cycles %-change: -0.82% -0.71%
Cycles are helped.
Iron Lake
total instructions in shared programs: 8114882 -> 8105574 (-0.11%)
instructions in affected programs: 1232504 -> 1223196 (-0.76%)
helped: 4109
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.27 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 0.99% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.94% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.31 -2.21
95% mean confidence interval for instructions %-change: -1.01% -0.96%
Instructions are helped.
total cycles in shared programs: 188504036 -> 188466296 (-0.02%)
cycles in affected programs: 31203798 -> 31166058 (-0.12%)
helped: 3447
HURT: 36
helped stats (abs) min: 2 max: 92 x̄: 11.03 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.21% x̃: 0.13%
HURT stats (abs) min: 2 max: 30 x̄: 7.33 x̃: 6
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.18% x̃: 0.10%
95% mean confidence interval for cycles value: -11.16 -10.51
95% mean confidence interval for cycles %-change: -0.22% -0.20%
Cycles are helped.
LOST: 0
GAINED: 1
GM45
total instructions in shared programs: 4989697 -> 4984531 (-0.10%)
instructions in affected programs: 703952 -> 698786 (-0.73%)
helped: 2493
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.07 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 1.03% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.95% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.13 -2.01
95% mean confidence interval for instructions %-change: -1.07% -0.99%
Instructions are helped.
total cycles in shared programs: 128929136 -> 128903886 (-0.02%)
cycles in affected programs: 21583096 -> 21557846 (-0.12%)
helped: 2214
HURT: 17
helped stats (abs) min: 2 max: 92 x̄: 11.44 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.24% x̃: 0.13%
HURT stats (abs) min: 2 max: 8 x̄: 4.24 x̃: 4
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.20% x̃: 0.09%
95% mean confidence interval for cycles value: -11.75 -10.88
95% mean confidence interval for cycles %-change: -0.25% -0.22%
Cycles are helped.
LOST: 1
GAINED: 1
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1359>
2019-07-15 23:55:00 +01:00
|
|
|
(('fneg', ('fneg', a)), a),
|
|
|
|
|
2020-06-20 21:48:19 +01:00
|
|
|
(('fneg', ('fmul(is_used_once)', a, b)), ('fmul', ('fneg', a), b)),
|
|
|
|
(('fabs', ('fmul(is_used_once)', a, b)), ('fmul', ('fabs', a), ('fabs', b))),
|
|
|
|
|
nir/algebraic: Distribute source modifiers into instructions
There are three main classes of cases that are helped by this change:
1. When the negation is applied to a value being type converted (e.g.,
float(-x)). This could possibly also be handled with more clever
code generation.
2. When the negation is applied to a phi node source (e.g., x = -(...);
at the end of a basic block). This was the original case that caught
my attention while looking at shader-db dumps.
3. When the negation is applied to the source of an instruction that
cannot have source modifiers. This includes texture instructions and
math box instructions on pre-Gen7 platforms (see more details below).
In many these cases the negation can be propagated into the instructions
that generate the value (e.g., -(a*b) = (-a)*b).
In addition to the operations implemtned in this patch, I also tried:
- frcp - Helped 6 or fewer shaders on Gen7+, and hurt just as many on
pre-Gen7. On Gen6 and earlier, frcp is a math box instruction, and
math box instructions cannot have source modifiers.
I suspect this is why so many more shaders are helped on Gen6 than on
Gen5 or Gen7. Gen6 supports OpenGL 3.3, so a lot more shaders
compile on it. A lot of these shaders may have things like cos(-x)
or rcp(-x) that could result in an explicit negation instruction.
- bcsel - Hurt a few shaders with none helped. bcsel operates on
integer sources, so the fabs or fneg cannot be a source modifier in
the bcsel itself.
- Integer instructions - No changes on any Intel platform.
Some notes about the shader-db results below.
- On Tiger Lake, a single Deus Ex fragment shader is hurt for both
spills and fills.
- On Haswell, a different Deus Ex fragment shader is hurt for both
spills and fills.
- On GM45, the "LOST: 1" and "GAINED: 1" is a single Left4Dead 2
(very high graphics settings, lol) fragment shader that upgrades
from SIMD8 to SIMD16.
v2: Add support for fsign. Add some patterns that remove redundant
negations and redundant absolute value rather than trying to push them
down the tree.
Tiger Lake
total instructions in shared programs: 17611333 -> 17586465 (-0.14%)
instructions in affected programs: 3033734 -> 3008866 (-0.82%)
helped: 10310
HURT: 632
helped stats (abs) min: 1 max: 35 x̄: 2.61 x̃: 1
helped stats (rel) min: 0.04% max: 16.67% x̄: 1.43% x̃: 1.01%
HURT stats (abs) min: 1 max: 47 x̄: 3.21 x̃: 2
HURT stats (rel) min: 0.04% max: 5.08% x̄: 0.88% x̃: 0.63%
95% mean confidence interval for instructions value: -2.33 -2.21
95% mean confidence interval for instructions %-change: -1.32% -1.27%
Instructions are helped.
total cycles in shared programs: 338365223 -> 338262252 (-0.03%)
cycles in affected programs: 125291811 -> 125188840 (-0.08%)
helped: 5224
HURT: 2031
helped stats (abs) min: 1 max: 5670 x̄: 46.73 x̃: 12
helped stats (rel) min: <.01% max: 34.78% x̄: 1.91% x̃: 0.97%
HURT stats (abs) min: 1 max: 2882 x̄: 69.50 x̃: 14
HURT stats (rel) min: <.01% max: 44.93% x̄: 2.35% x̃: 0.74%
95% mean confidence interval for cycles value: -18.71 -9.68
95% mean confidence interval for cycles %-change: -0.80% -0.63%
Cycles are helped.
total spills in shared programs: 8942 -> 8946 (0.04%)
spills in affected programs: 8 -> 12 (50.00%)
helped: 0
HURT: 1
total fills in shared programs: 9399 -> 9401 (0.02%)
fills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
Ice Lake
total instructions in shared programs: 16124348 -> 16102258 (-0.14%)
instructions in affected programs: 2830928 -> 2808838 (-0.78%)
helped: 11294
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.96 x̃: 1
helped stats (rel) min: 0.07% max: 17.65% x̄: 1.32% x̃: 0.93%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 3.45% max: 4.00% x̄: 3.72% x̃: 3.72%
95% mean confidence interval for instructions value: -1.99 -1.93
95% mean confidence interval for instructions %-change: -1.34% -1.29%
Instructions are helped.
total cycles in shared programs: 335393932 -> 335325794 (-0.02%)
cycles in affected programs: 123834609 -> 123766471 (-0.06%)
helped: 5034
HURT: 2128
helped stats (abs) min: 1 max: 3256 x̄: 43.39 x̃: 11
helped stats (rel) min: <.01% max: 35.79% x̄: 1.98% x̃: 1.00%
HURT stats (abs) min: 1 max: 2634 x̄: 70.63 x̃: 16
HURT stats (rel) min: <.01% max: 49.49% x̄: 2.73% x̃: 0.62%
95% mean confidence interval for cycles value: -13.66 -5.37
95% mean confidence interval for cycles %-change: -0.69% -0.48%
Cycles are helped.
LOST: 0
GAINED: 2
Skylake
total instructions in shared programs: 14949240 -> 14927930 (-0.14%)
instructions in affected programs: 2594756 -> 2573446 (-0.82%)
helped: 11000
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.94 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.91
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 324829346 -> 324821596 (<.01%)
cycles in affected programs: 121566087 -> 121558337 (<.01%)
helped: 4611
HURT: 2147
helped stats (abs) min: 1 max: 3715 x̄: 33.29 x̃: 10
helped stats (rel) min: <.01% max: 36.08% x̄: 1.94% x̃: 1.00%
HURT stats (abs) min: 1 max: 2551 x̄: 67.88 x̃: 16
HURT stats (rel) min: <.01% max: 53.79% x̄: 3.69% x̃: 0.89%
95% mean confidence interval for cycles value: -4.25 1.96
95% mean confidence interval for cycles %-change: -0.28% -0.02%
Inconclusive result (value mean confidence interval includes 0).
Broadwell
total instructions in shared programs: 14971203 -> 14949957 (-0.14%)
instructions in affected programs: 2635699 -> 2614453 (-0.81%)
helped: 10982
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.93 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.90
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 336215033 -> 336086458 (-0.04%)
cycles in affected programs: 127383198 -> 127254623 (-0.10%)
helped: 4884
HURT: 1963
helped stats (abs) min: 1 max: 25696 x̄: 51.78 x̃: 12
helped stats (rel) min: <.01% max: 58.28% x̄: 2.00% x̃: 1.05%
HURT stats (abs) min: 1 max: 3401 x̄: 63.33 x̃: 16
HURT stats (rel) min: <.01% max: 39.95% x̄: 2.20% x̃: 0.70%
95% mean confidence interval for cycles value: -29.99 -7.57
95% mean confidence interval for cycles %-change: -0.89% -0.71%
Cycles are helped.
total fills in shared programs: 24905 -> 24901 (-0.02%)
fills in affected programs: 117 -> 113 (-3.42%)
helped: 4
HURT: 0
LOST: 0
GAINED: 16
Haswell
total instructions in shared programs: 13148927 -> 13131528 (-0.13%)
instructions in affected programs: 2220941 -> 2203542 (-0.78%)
helped: 8017
HURT: 4
helped stats (abs) min: 1 max: 12 x̄: 2.17 x̃: 1
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.40% x̃: 0.93%
HURT stats (abs) min: 1 max: 7 x̄: 2.50 x̃: 1
HURT stats (rel) min: 0.33% max: 4.76% x̄: 2.73% x̃: 2.91%
95% mean confidence interval for instructions value: -2.21 -2.13
95% mean confidence interval for instructions %-change: -1.43% -1.37%
Instructions are helped.
total cycles in shared programs: 321221791 -> 321079870 (-0.04%)
cycles in affected programs: 126886055 -> 126744134 (-0.11%)
helped: 4674
HURT: 1729
helped stats (abs) min: 1 max: 23654 x̄: 56.47 x̃: 16
helped stats (rel) min: <.01% max: 53.22% x̄: 2.13% x̃: 1.05%
HURT stats (abs) min: 1 max: 3694 x̄: 70.58 x̃: 18
HURT stats (rel) min: <.01% max: 63.06% x̄: 2.48% x̃: 0.90%
95% mean confidence interval for cycles value: -33.31 -11.02
95% mean confidence interval for cycles %-change: -0.99% -0.78%
Cycles are helped.
total spills in shared programs: 19872 -> 19874 (0.01%)
spills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
total fills in shared programs: 20941 -> 20941 (0.00%)
fills in affected programs: 62 -> 62 (0.00%)
helped: 1
HURT: 1
LOST: 0
GAINED: 8
Ivy Bridge
total instructions in shared programs: 11875553 -> 11853839 (-0.18%)
instructions in affected programs: 1553112 -> 1531398 (-1.40%)
helped: 7304
HURT: 3
helped stats (abs) min: 1 max: 16 x̄: 2.97 x̃: 2
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.62% x̃: 1.15%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.05% max: 3.33% x̄: 2.44% x̃: 2.94%
95% mean confidence interval for instructions value: -3.04 -2.90
95% mean confidence interval for instructions %-change: -1.65% -1.59%
Instructions are helped.
total cycles in shared programs: 178246425 -> 178184484 (-0.03%)
cycles in affected programs: 13702146 -> 13640205 (-0.45%)
helped: 4409
HURT: 1566
helped stats (abs) min: 1 max: 531 x̄: 24.52 x̃: 13
helped stats (rel) min: <.01% max: 38.67% x̄: 2.14% x̃: 1.02%
HURT stats (abs) min: 1 max: 356 x̄: 29.48 x̃: 10
HURT stats (rel) min: <.01% max: 64.73% x̄: 1.87% x̃: 0.70%
95% mean confidence interval for cycles value: -11.60 -9.14
95% mean confidence interval for cycles %-change: -1.19% -0.99%
Cycles are helped.
LOST: 0
GAINED: 10
Sandy Bridge
total instructions in shared programs: 10695740 -> 10667483 (-0.26%)
instructions in affected programs: 2337607 -> 2309350 (-1.21%)
helped: 10720
HURT: 1
helped stats (abs) min: 1 max: 49 x̄: 2.64 x̃: 2
helped stats (rel) min: 0.07% max: 20.00% x̄: 1.54% x̃: 1.13%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.04% max: 1.04% x̄: 1.04% x̃: 1.04%
95% mean confidence interval for instructions value: -2.69 -2.58
95% mean confidence interval for instructions %-change: -1.57% -1.51%
Instructions are helped.
total cycles in shared programs: 153478839 -> 153416223 (-0.04%)
cycles in affected programs: 22050900 -> 21988284 (-0.28%)
helped: 5342
HURT: 2200
helped stats (abs) min: 1 max: 1020 x̄: 20.34 x̃: 16
helped stats (rel) min: <.01% max: 24.05% x̄: 1.51% x̃: 0.86%
HURT stats (abs) min: 1 max: 335 x̄: 20.93 x̃: 6
HURT stats (rel) min: <.01% max: 20.18% x̄: 1.03% x̃: 0.30%
95% mean confidence interval for cycles value: -9.18 -7.42
95% mean confidence interval for cycles %-change: -0.82% -0.71%
Cycles are helped.
Iron Lake
total instructions in shared programs: 8114882 -> 8105574 (-0.11%)
instructions in affected programs: 1232504 -> 1223196 (-0.76%)
helped: 4109
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.27 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 0.99% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.94% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.31 -2.21
95% mean confidence interval for instructions %-change: -1.01% -0.96%
Instructions are helped.
total cycles in shared programs: 188504036 -> 188466296 (-0.02%)
cycles in affected programs: 31203798 -> 31166058 (-0.12%)
helped: 3447
HURT: 36
helped stats (abs) min: 2 max: 92 x̄: 11.03 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.21% x̃: 0.13%
HURT stats (abs) min: 2 max: 30 x̄: 7.33 x̃: 6
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.18% x̃: 0.10%
95% mean confidence interval for cycles value: -11.16 -10.51
95% mean confidence interval for cycles %-change: -0.22% -0.20%
Cycles are helped.
LOST: 0
GAINED: 1
GM45
total instructions in shared programs: 4989697 -> 4984531 (-0.10%)
instructions in affected programs: 703952 -> 698786 (-0.73%)
helped: 2493
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.07 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 1.03% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.95% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.13 -2.01
95% mean confidence interval for instructions %-change: -1.07% -0.99%
Instructions are helped.
total cycles in shared programs: 128929136 -> 128903886 (-0.02%)
cycles in affected programs: 21583096 -> 21557846 (-0.12%)
helped: 2214
HURT: 17
helped stats (abs) min: 2 max: 92 x̄: 11.44 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.24% x̃: 0.13%
HURT stats (abs) min: 2 max: 8 x̄: 4.24 x̃: 4
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.20% x̃: 0.09%
95% mean confidence interval for cycles value: -11.75 -10.88
95% mean confidence interval for cycles %-change: -0.25% -0.22%
Cycles are helped.
LOST: 1
GAINED: 1
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1359>
2019-07-15 23:55:00 +01:00
|
|
|
(('fneg', ('ffma(is_used_once)', a, b, c)), ('ffma', ('fneg', a), b, ('fneg', c))),
|
|
|
|
(('fneg', ('flrp(is_used_once)', a, b, c)), ('flrp', ('fneg', a), ('fneg', b), c)),
|
|
|
|
(('fneg', ('fadd(is_used_once)', a, b)), ('fadd', ('fneg', a), ('fneg', b))),
|
|
|
|
|
|
|
|
# Note that fmin <-> fmax. I don't think there is a way to distribute
|
|
|
|
# fabs() into fmin or fmax.
|
|
|
|
(('fneg', ('fmin(is_used_once)', a, b)), ('fmax', ('fneg', a), ('fneg', b))),
|
|
|
|
(('fneg', ('fmax(is_used_once)', a, b)), ('fmin', ('fneg', a), ('fneg', b))),
|
|
|
|
|
2020-06-20 22:33:57 +01:00
|
|
|
(('fneg', ('fdot2_replicated(is_used_once)', a, b)), ('fdot2_replicated', ('fneg', a), b)),
|
|
|
|
(('fneg', ('fdot3_replicated(is_used_once)', a, b)), ('fdot3_replicated', ('fneg', a), b)),
|
|
|
|
(('fneg', ('fdot4_replicated(is_used_once)', a, b)), ('fdot4_replicated', ('fneg', a), b)),
|
2020-06-20 21:48:19 +01:00
|
|
|
|
nir/algebraic: Distribute source modifiers into instructions
There are three main classes of cases that are helped by this change:
1. When the negation is applied to a value being type converted (e.g.,
float(-x)). This could possibly also be handled with more clever
code generation.
2. When the negation is applied to a phi node source (e.g., x = -(...);
at the end of a basic block). This was the original case that caught
my attention while looking at shader-db dumps.
3. When the negation is applied to the source of an instruction that
cannot have source modifiers. This includes texture instructions and
math box instructions on pre-Gen7 platforms (see more details below).
In many these cases the negation can be propagated into the instructions
that generate the value (e.g., -(a*b) = (-a)*b).
In addition to the operations implemtned in this patch, I also tried:
- frcp - Helped 6 or fewer shaders on Gen7+, and hurt just as many on
pre-Gen7. On Gen6 and earlier, frcp is a math box instruction, and
math box instructions cannot have source modifiers.
I suspect this is why so many more shaders are helped on Gen6 than on
Gen5 or Gen7. Gen6 supports OpenGL 3.3, so a lot more shaders
compile on it. A lot of these shaders may have things like cos(-x)
or rcp(-x) that could result in an explicit negation instruction.
- bcsel - Hurt a few shaders with none helped. bcsel operates on
integer sources, so the fabs or fneg cannot be a source modifier in
the bcsel itself.
- Integer instructions - No changes on any Intel platform.
Some notes about the shader-db results below.
- On Tiger Lake, a single Deus Ex fragment shader is hurt for both
spills and fills.
- On Haswell, a different Deus Ex fragment shader is hurt for both
spills and fills.
- On GM45, the "LOST: 1" and "GAINED: 1" is a single Left4Dead 2
(very high graphics settings, lol) fragment shader that upgrades
from SIMD8 to SIMD16.
v2: Add support for fsign. Add some patterns that remove redundant
negations and redundant absolute value rather than trying to push them
down the tree.
Tiger Lake
total instructions in shared programs: 17611333 -> 17586465 (-0.14%)
instructions in affected programs: 3033734 -> 3008866 (-0.82%)
helped: 10310
HURT: 632
helped stats (abs) min: 1 max: 35 x̄: 2.61 x̃: 1
helped stats (rel) min: 0.04% max: 16.67% x̄: 1.43% x̃: 1.01%
HURT stats (abs) min: 1 max: 47 x̄: 3.21 x̃: 2
HURT stats (rel) min: 0.04% max: 5.08% x̄: 0.88% x̃: 0.63%
95% mean confidence interval for instructions value: -2.33 -2.21
95% mean confidence interval for instructions %-change: -1.32% -1.27%
Instructions are helped.
total cycles in shared programs: 338365223 -> 338262252 (-0.03%)
cycles in affected programs: 125291811 -> 125188840 (-0.08%)
helped: 5224
HURT: 2031
helped stats (abs) min: 1 max: 5670 x̄: 46.73 x̃: 12
helped stats (rel) min: <.01% max: 34.78% x̄: 1.91% x̃: 0.97%
HURT stats (abs) min: 1 max: 2882 x̄: 69.50 x̃: 14
HURT stats (rel) min: <.01% max: 44.93% x̄: 2.35% x̃: 0.74%
95% mean confidence interval for cycles value: -18.71 -9.68
95% mean confidence interval for cycles %-change: -0.80% -0.63%
Cycles are helped.
total spills in shared programs: 8942 -> 8946 (0.04%)
spills in affected programs: 8 -> 12 (50.00%)
helped: 0
HURT: 1
total fills in shared programs: 9399 -> 9401 (0.02%)
fills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
Ice Lake
total instructions in shared programs: 16124348 -> 16102258 (-0.14%)
instructions in affected programs: 2830928 -> 2808838 (-0.78%)
helped: 11294
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.96 x̃: 1
helped stats (rel) min: 0.07% max: 17.65% x̄: 1.32% x̃: 0.93%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 3.45% max: 4.00% x̄: 3.72% x̃: 3.72%
95% mean confidence interval for instructions value: -1.99 -1.93
95% mean confidence interval for instructions %-change: -1.34% -1.29%
Instructions are helped.
total cycles in shared programs: 335393932 -> 335325794 (-0.02%)
cycles in affected programs: 123834609 -> 123766471 (-0.06%)
helped: 5034
HURT: 2128
helped stats (abs) min: 1 max: 3256 x̄: 43.39 x̃: 11
helped stats (rel) min: <.01% max: 35.79% x̄: 1.98% x̃: 1.00%
HURT stats (abs) min: 1 max: 2634 x̄: 70.63 x̃: 16
HURT stats (rel) min: <.01% max: 49.49% x̄: 2.73% x̃: 0.62%
95% mean confidence interval for cycles value: -13.66 -5.37
95% mean confidence interval for cycles %-change: -0.69% -0.48%
Cycles are helped.
LOST: 0
GAINED: 2
Skylake
total instructions in shared programs: 14949240 -> 14927930 (-0.14%)
instructions in affected programs: 2594756 -> 2573446 (-0.82%)
helped: 11000
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.94 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.91
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 324829346 -> 324821596 (<.01%)
cycles in affected programs: 121566087 -> 121558337 (<.01%)
helped: 4611
HURT: 2147
helped stats (abs) min: 1 max: 3715 x̄: 33.29 x̃: 10
helped stats (rel) min: <.01% max: 36.08% x̄: 1.94% x̃: 1.00%
HURT stats (abs) min: 1 max: 2551 x̄: 67.88 x̃: 16
HURT stats (rel) min: <.01% max: 53.79% x̄: 3.69% x̃: 0.89%
95% mean confidence interval for cycles value: -4.25 1.96
95% mean confidence interval for cycles %-change: -0.28% -0.02%
Inconclusive result (value mean confidence interval includes 0).
Broadwell
total instructions in shared programs: 14971203 -> 14949957 (-0.14%)
instructions in affected programs: 2635699 -> 2614453 (-0.81%)
helped: 10982
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.93 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.90
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 336215033 -> 336086458 (-0.04%)
cycles in affected programs: 127383198 -> 127254623 (-0.10%)
helped: 4884
HURT: 1963
helped stats (abs) min: 1 max: 25696 x̄: 51.78 x̃: 12
helped stats (rel) min: <.01% max: 58.28% x̄: 2.00% x̃: 1.05%
HURT stats (abs) min: 1 max: 3401 x̄: 63.33 x̃: 16
HURT stats (rel) min: <.01% max: 39.95% x̄: 2.20% x̃: 0.70%
95% mean confidence interval for cycles value: -29.99 -7.57
95% mean confidence interval for cycles %-change: -0.89% -0.71%
Cycles are helped.
total fills in shared programs: 24905 -> 24901 (-0.02%)
fills in affected programs: 117 -> 113 (-3.42%)
helped: 4
HURT: 0
LOST: 0
GAINED: 16
Haswell
total instructions in shared programs: 13148927 -> 13131528 (-0.13%)
instructions in affected programs: 2220941 -> 2203542 (-0.78%)
helped: 8017
HURT: 4
helped stats (abs) min: 1 max: 12 x̄: 2.17 x̃: 1
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.40% x̃: 0.93%
HURT stats (abs) min: 1 max: 7 x̄: 2.50 x̃: 1
HURT stats (rel) min: 0.33% max: 4.76% x̄: 2.73% x̃: 2.91%
95% mean confidence interval for instructions value: -2.21 -2.13
95% mean confidence interval for instructions %-change: -1.43% -1.37%
Instructions are helped.
total cycles in shared programs: 321221791 -> 321079870 (-0.04%)
cycles in affected programs: 126886055 -> 126744134 (-0.11%)
helped: 4674
HURT: 1729
helped stats (abs) min: 1 max: 23654 x̄: 56.47 x̃: 16
helped stats (rel) min: <.01% max: 53.22% x̄: 2.13% x̃: 1.05%
HURT stats (abs) min: 1 max: 3694 x̄: 70.58 x̃: 18
HURT stats (rel) min: <.01% max: 63.06% x̄: 2.48% x̃: 0.90%
95% mean confidence interval for cycles value: -33.31 -11.02
95% mean confidence interval for cycles %-change: -0.99% -0.78%
Cycles are helped.
total spills in shared programs: 19872 -> 19874 (0.01%)
spills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
total fills in shared programs: 20941 -> 20941 (0.00%)
fills in affected programs: 62 -> 62 (0.00%)
helped: 1
HURT: 1
LOST: 0
GAINED: 8
Ivy Bridge
total instructions in shared programs: 11875553 -> 11853839 (-0.18%)
instructions in affected programs: 1553112 -> 1531398 (-1.40%)
helped: 7304
HURT: 3
helped stats (abs) min: 1 max: 16 x̄: 2.97 x̃: 2
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.62% x̃: 1.15%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.05% max: 3.33% x̄: 2.44% x̃: 2.94%
95% mean confidence interval for instructions value: -3.04 -2.90
95% mean confidence interval for instructions %-change: -1.65% -1.59%
Instructions are helped.
total cycles in shared programs: 178246425 -> 178184484 (-0.03%)
cycles in affected programs: 13702146 -> 13640205 (-0.45%)
helped: 4409
HURT: 1566
helped stats (abs) min: 1 max: 531 x̄: 24.52 x̃: 13
helped stats (rel) min: <.01% max: 38.67% x̄: 2.14% x̃: 1.02%
HURT stats (abs) min: 1 max: 356 x̄: 29.48 x̃: 10
HURT stats (rel) min: <.01% max: 64.73% x̄: 1.87% x̃: 0.70%
95% mean confidence interval for cycles value: -11.60 -9.14
95% mean confidence interval for cycles %-change: -1.19% -0.99%
Cycles are helped.
LOST: 0
GAINED: 10
Sandy Bridge
total instructions in shared programs: 10695740 -> 10667483 (-0.26%)
instructions in affected programs: 2337607 -> 2309350 (-1.21%)
helped: 10720
HURT: 1
helped stats (abs) min: 1 max: 49 x̄: 2.64 x̃: 2
helped stats (rel) min: 0.07% max: 20.00% x̄: 1.54% x̃: 1.13%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.04% max: 1.04% x̄: 1.04% x̃: 1.04%
95% mean confidence interval for instructions value: -2.69 -2.58
95% mean confidence interval for instructions %-change: -1.57% -1.51%
Instructions are helped.
total cycles in shared programs: 153478839 -> 153416223 (-0.04%)
cycles in affected programs: 22050900 -> 21988284 (-0.28%)
helped: 5342
HURT: 2200
helped stats (abs) min: 1 max: 1020 x̄: 20.34 x̃: 16
helped stats (rel) min: <.01% max: 24.05% x̄: 1.51% x̃: 0.86%
HURT stats (abs) min: 1 max: 335 x̄: 20.93 x̃: 6
HURT stats (rel) min: <.01% max: 20.18% x̄: 1.03% x̃: 0.30%
95% mean confidence interval for cycles value: -9.18 -7.42
95% mean confidence interval for cycles %-change: -0.82% -0.71%
Cycles are helped.
Iron Lake
total instructions in shared programs: 8114882 -> 8105574 (-0.11%)
instructions in affected programs: 1232504 -> 1223196 (-0.76%)
helped: 4109
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.27 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 0.99% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.94% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.31 -2.21
95% mean confidence interval for instructions %-change: -1.01% -0.96%
Instructions are helped.
total cycles in shared programs: 188504036 -> 188466296 (-0.02%)
cycles in affected programs: 31203798 -> 31166058 (-0.12%)
helped: 3447
HURT: 36
helped stats (abs) min: 2 max: 92 x̄: 11.03 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.21% x̃: 0.13%
HURT stats (abs) min: 2 max: 30 x̄: 7.33 x̃: 6
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.18% x̃: 0.10%
95% mean confidence interval for cycles value: -11.16 -10.51
95% mean confidence interval for cycles %-change: -0.22% -0.20%
Cycles are helped.
LOST: 0
GAINED: 1
GM45
total instructions in shared programs: 4989697 -> 4984531 (-0.10%)
instructions in affected programs: 703952 -> 698786 (-0.73%)
helped: 2493
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.07 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 1.03% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.95% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.13 -2.01
95% mean confidence interval for instructions %-change: -1.07% -0.99%
Instructions are helped.
total cycles in shared programs: 128929136 -> 128903886 (-0.02%)
cycles in affected programs: 21583096 -> 21557846 (-0.12%)
helped: 2214
HURT: 17
helped stats (abs) min: 2 max: 92 x̄: 11.44 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.24% x̃: 0.13%
HURT stats (abs) min: 2 max: 8 x̄: 4.24 x̃: 4
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.20% x̃: 0.09%
95% mean confidence interval for cycles value: -11.75 -10.88
95% mean confidence interval for cycles %-change: -0.25% -0.22%
Cycles are helped.
LOST: 1
GAINED: 1
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1359>
2019-07-15 23:55:00 +01:00
|
|
|
# fdph works mostly like fdot, but to get the correct result, the negation
|
|
|
|
# must be applied to the second source.
|
|
|
|
(('fneg', ('fdph_replicated(is_used_once)', a, b)), ('fdph_replicated', a, ('fneg', b))),
|
|
|
|
|
|
|
|
(('fneg', ('fsign(is_used_once)', a)), ('fsign', ('fneg', a))),
|
|
|
|
(('fabs', ('fsign(is_used_once)', a)), ('fsign', ('fabs', a))),
|
|
|
|
]
|
|
|
|
|
2018-07-05 14:17:32 +01:00
|
|
|
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render())
|
|
|
|
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_before_ffma",
|
|
|
|
before_ffma_optimizations).render())
|
|
|
|
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_late",
|
|
|
|
late_optimizations).render())
|
nir/algebraic: Distribute source modifiers into instructions
There are three main classes of cases that are helped by this change:
1. When the negation is applied to a value being type converted (e.g.,
float(-x)). This could possibly also be handled with more clever
code generation.
2. When the negation is applied to a phi node source (e.g., x = -(...);
at the end of a basic block). This was the original case that caught
my attention while looking at shader-db dumps.
3. When the negation is applied to the source of an instruction that
cannot have source modifiers. This includes texture instructions and
math box instructions on pre-Gen7 platforms (see more details below).
In many these cases the negation can be propagated into the instructions
that generate the value (e.g., -(a*b) = (-a)*b).
In addition to the operations implemtned in this patch, I also tried:
- frcp - Helped 6 or fewer shaders on Gen7+, and hurt just as many on
pre-Gen7. On Gen6 and earlier, frcp is a math box instruction, and
math box instructions cannot have source modifiers.
I suspect this is why so many more shaders are helped on Gen6 than on
Gen5 or Gen7. Gen6 supports OpenGL 3.3, so a lot more shaders
compile on it. A lot of these shaders may have things like cos(-x)
or rcp(-x) that could result in an explicit negation instruction.
- bcsel - Hurt a few shaders with none helped. bcsel operates on
integer sources, so the fabs or fneg cannot be a source modifier in
the bcsel itself.
- Integer instructions - No changes on any Intel platform.
Some notes about the shader-db results below.
- On Tiger Lake, a single Deus Ex fragment shader is hurt for both
spills and fills.
- On Haswell, a different Deus Ex fragment shader is hurt for both
spills and fills.
- On GM45, the "LOST: 1" and "GAINED: 1" is a single Left4Dead 2
(very high graphics settings, lol) fragment shader that upgrades
from SIMD8 to SIMD16.
v2: Add support for fsign. Add some patterns that remove redundant
negations and redundant absolute value rather than trying to push them
down the tree.
Tiger Lake
total instructions in shared programs: 17611333 -> 17586465 (-0.14%)
instructions in affected programs: 3033734 -> 3008866 (-0.82%)
helped: 10310
HURT: 632
helped stats (abs) min: 1 max: 35 x̄: 2.61 x̃: 1
helped stats (rel) min: 0.04% max: 16.67% x̄: 1.43% x̃: 1.01%
HURT stats (abs) min: 1 max: 47 x̄: 3.21 x̃: 2
HURT stats (rel) min: 0.04% max: 5.08% x̄: 0.88% x̃: 0.63%
95% mean confidence interval for instructions value: -2.33 -2.21
95% mean confidence interval for instructions %-change: -1.32% -1.27%
Instructions are helped.
total cycles in shared programs: 338365223 -> 338262252 (-0.03%)
cycles in affected programs: 125291811 -> 125188840 (-0.08%)
helped: 5224
HURT: 2031
helped stats (abs) min: 1 max: 5670 x̄: 46.73 x̃: 12
helped stats (rel) min: <.01% max: 34.78% x̄: 1.91% x̃: 0.97%
HURT stats (abs) min: 1 max: 2882 x̄: 69.50 x̃: 14
HURT stats (rel) min: <.01% max: 44.93% x̄: 2.35% x̃: 0.74%
95% mean confidence interval for cycles value: -18.71 -9.68
95% mean confidence interval for cycles %-change: -0.80% -0.63%
Cycles are helped.
total spills in shared programs: 8942 -> 8946 (0.04%)
spills in affected programs: 8 -> 12 (50.00%)
helped: 0
HURT: 1
total fills in shared programs: 9399 -> 9401 (0.02%)
fills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
Ice Lake
total instructions in shared programs: 16124348 -> 16102258 (-0.14%)
instructions in affected programs: 2830928 -> 2808838 (-0.78%)
helped: 11294
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.96 x̃: 1
helped stats (rel) min: 0.07% max: 17.65% x̄: 1.32% x̃: 0.93%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 3.45% max: 4.00% x̄: 3.72% x̃: 3.72%
95% mean confidence interval for instructions value: -1.99 -1.93
95% mean confidence interval for instructions %-change: -1.34% -1.29%
Instructions are helped.
total cycles in shared programs: 335393932 -> 335325794 (-0.02%)
cycles in affected programs: 123834609 -> 123766471 (-0.06%)
helped: 5034
HURT: 2128
helped stats (abs) min: 1 max: 3256 x̄: 43.39 x̃: 11
helped stats (rel) min: <.01% max: 35.79% x̄: 1.98% x̃: 1.00%
HURT stats (abs) min: 1 max: 2634 x̄: 70.63 x̃: 16
HURT stats (rel) min: <.01% max: 49.49% x̄: 2.73% x̃: 0.62%
95% mean confidence interval for cycles value: -13.66 -5.37
95% mean confidence interval for cycles %-change: -0.69% -0.48%
Cycles are helped.
LOST: 0
GAINED: 2
Skylake
total instructions in shared programs: 14949240 -> 14927930 (-0.14%)
instructions in affected programs: 2594756 -> 2573446 (-0.82%)
helped: 11000
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.94 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.91
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 324829346 -> 324821596 (<.01%)
cycles in affected programs: 121566087 -> 121558337 (<.01%)
helped: 4611
HURT: 2147
helped stats (abs) min: 1 max: 3715 x̄: 33.29 x̃: 10
helped stats (rel) min: <.01% max: 36.08% x̄: 1.94% x̃: 1.00%
HURT stats (abs) min: 1 max: 2551 x̄: 67.88 x̃: 16
HURT stats (rel) min: <.01% max: 53.79% x̄: 3.69% x̃: 0.89%
95% mean confidence interval for cycles value: -4.25 1.96
95% mean confidence interval for cycles %-change: -0.28% -0.02%
Inconclusive result (value mean confidence interval includes 0).
Broadwell
total instructions in shared programs: 14971203 -> 14949957 (-0.14%)
instructions in affected programs: 2635699 -> 2614453 (-0.81%)
helped: 10982
HURT: 2
helped stats (abs) min: 1 max: 12 x̄: 1.93 x̃: 1
helped stats (rel) min: 0.07% max: 18.75% x̄: 1.39% x̃: 0.94%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 4.76% max: 4.76% x̄: 4.76% x̃: 4.76%
95% mean confidence interval for instructions value: -1.97 -1.90
95% mean confidence interval for instructions %-change: -1.42% -1.37%
Instructions are helped.
total cycles in shared programs: 336215033 -> 336086458 (-0.04%)
cycles in affected programs: 127383198 -> 127254623 (-0.10%)
helped: 4884
HURT: 1963
helped stats (abs) min: 1 max: 25696 x̄: 51.78 x̃: 12
helped stats (rel) min: <.01% max: 58.28% x̄: 2.00% x̃: 1.05%
HURT stats (abs) min: 1 max: 3401 x̄: 63.33 x̃: 16
HURT stats (rel) min: <.01% max: 39.95% x̄: 2.20% x̃: 0.70%
95% mean confidence interval for cycles value: -29.99 -7.57
95% mean confidence interval for cycles %-change: -0.89% -0.71%
Cycles are helped.
total fills in shared programs: 24905 -> 24901 (-0.02%)
fills in affected programs: 117 -> 113 (-3.42%)
helped: 4
HURT: 0
LOST: 0
GAINED: 16
Haswell
total instructions in shared programs: 13148927 -> 13131528 (-0.13%)
instructions in affected programs: 2220941 -> 2203542 (-0.78%)
helped: 8017
HURT: 4
helped stats (abs) min: 1 max: 12 x̄: 2.17 x̃: 1
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.40% x̃: 0.93%
HURT stats (abs) min: 1 max: 7 x̄: 2.50 x̃: 1
HURT stats (rel) min: 0.33% max: 4.76% x̄: 2.73% x̃: 2.91%
95% mean confidence interval for instructions value: -2.21 -2.13
95% mean confidence interval for instructions %-change: -1.43% -1.37%
Instructions are helped.
total cycles in shared programs: 321221791 -> 321079870 (-0.04%)
cycles in affected programs: 126886055 -> 126744134 (-0.11%)
helped: 4674
HURT: 1729
helped stats (abs) min: 1 max: 23654 x̄: 56.47 x̃: 16
helped stats (rel) min: <.01% max: 53.22% x̄: 2.13% x̃: 1.05%
HURT stats (abs) min: 1 max: 3694 x̄: 70.58 x̃: 18
HURT stats (rel) min: <.01% max: 63.06% x̄: 2.48% x̃: 0.90%
95% mean confidence interval for cycles value: -33.31 -11.02
95% mean confidence interval for cycles %-change: -0.99% -0.78%
Cycles are helped.
total spills in shared programs: 19872 -> 19874 (0.01%)
spills in affected programs: 21 -> 23 (9.52%)
helped: 0
HURT: 1
total fills in shared programs: 20941 -> 20941 (0.00%)
fills in affected programs: 62 -> 62 (0.00%)
helped: 1
HURT: 1
LOST: 0
GAINED: 8
Ivy Bridge
total instructions in shared programs: 11875553 -> 11853839 (-0.18%)
instructions in affected programs: 1553112 -> 1531398 (-1.40%)
helped: 7304
HURT: 3
helped stats (abs) min: 1 max: 16 x̄: 2.97 x̃: 2
helped stats (rel) min: 0.07% max: 15.25% x̄: 1.62% x̃: 1.15%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.05% max: 3.33% x̄: 2.44% x̃: 2.94%
95% mean confidence interval for instructions value: -3.04 -2.90
95% mean confidence interval for instructions %-change: -1.65% -1.59%
Instructions are helped.
total cycles in shared programs: 178246425 -> 178184484 (-0.03%)
cycles in affected programs: 13702146 -> 13640205 (-0.45%)
helped: 4409
HURT: 1566
helped stats (abs) min: 1 max: 531 x̄: 24.52 x̃: 13
helped stats (rel) min: <.01% max: 38.67% x̄: 2.14% x̃: 1.02%
HURT stats (abs) min: 1 max: 356 x̄: 29.48 x̃: 10
HURT stats (rel) min: <.01% max: 64.73% x̄: 1.87% x̃: 0.70%
95% mean confidence interval for cycles value: -11.60 -9.14
95% mean confidence interval for cycles %-change: -1.19% -0.99%
Cycles are helped.
LOST: 0
GAINED: 10
Sandy Bridge
total instructions in shared programs: 10695740 -> 10667483 (-0.26%)
instructions in affected programs: 2337607 -> 2309350 (-1.21%)
helped: 10720
HURT: 1
helped stats (abs) min: 1 max: 49 x̄: 2.64 x̃: 2
helped stats (rel) min: 0.07% max: 20.00% x̄: 1.54% x̃: 1.13%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 1.04% max: 1.04% x̄: 1.04% x̃: 1.04%
95% mean confidence interval for instructions value: -2.69 -2.58
95% mean confidence interval for instructions %-change: -1.57% -1.51%
Instructions are helped.
total cycles in shared programs: 153478839 -> 153416223 (-0.04%)
cycles in affected programs: 22050900 -> 21988284 (-0.28%)
helped: 5342
HURT: 2200
helped stats (abs) min: 1 max: 1020 x̄: 20.34 x̃: 16
helped stats (rel) min: <.01% max: 24.05% x̄: 1.51% x̃: 0.86%
HURT stats (abs) min: 1 max: 335 x̄: 20.93 x̃: 6
HURT stats (rel) min: <.01% max: 20.18% x̄: 1.03% x̃: 0.30%
95% mean confidence interval for cycles value: -9.18 -7.42
95% mean confidence interval for cycles %-change: -0.82% -0.71%
Cycles are helped.
Iron Lake
total instructions in shared programs: 8114882 -> 8105574 (-0.11%)
instructions in affected programs: 1232504 -> 1223196 (-0.76%)
helped: 4109
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.27 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 0.99% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.94% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.31 -2.21
95% mean confidence interval for instructions %-change: -1.01% -0.96%
Instructions are helped.
total cycles in shared programs: 188504036 -> 188466296 (-0.02%)
cycles in affected programs: 31203798 -> 31166058 (-0.12%)
helped: 3447
HURT: 36
helped stats (abs) min: 2 max: 92 x̄: 11.03 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.21% x̃: 0.13%
HURT stats (abs) min: 2 max: 30 x̄: 7.33 x̃: 6
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.18% x̃: 0.10%
95% mean confidence interval for cycles value: -11.16 -10.51
95% mean confidence interval for cycles %-change: -0.22% -0.20%
Cycles are helped.
LOST: 0
GAINED: 1
GM45
total instructions in shared programs: 4989697 -> 4984531 (-0.10%)
instructions in affected programs: 703952 -> 698786 (-0.73%)
helped: 2493
HURT: 2
helped stats (abs) min: 1 max: 6 x̄: 2.07 x̃: 1
helped stats (rel) min: 0.05% max: 8.33% x̄: 1.03% x̃: 0.66%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.95% max: 4.35% x̄: 2.65% x̃: 2.65%
95% mean confidence interval for instructions value: -2.13 -2.01
95% mean confidence interval for instructions %-change: -1.07% -0.99%
Instructions are helped.
total cycles in shared programs: 128929136 -> 128903886 (-0.02%)
cycles in affected programs: 21583096 -> 21557846 (-0.12%)
helped: 2214
HURT: 17
helped stats (abs) min: 2 max: 92 x̄: 11.44 x̃: 8
helped stats (rel) min: <.01% max: 5.41% x̄: 0.24% x̃: 0.13%
HURT stats (abs) min: 2 max: 8 x̄: 4.24 x̃: 4
HURT stats (rel) min: 0.01% max: 1.65% x̄: 0.20% x̃: 0.09%
95% mean confidence interval for cycles value: -11.75 -10.88
95% mean confidence interval for cycles %-change: -0.25% -0.22%
Cycles are helped.
LOST: 1
GAINED: 1
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1359>
2019-07-15 23:55:00 +01:00
|
|
|
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_distribute_src_mods",
|
|
|
|
distribute_src_mods).render())
|