mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-21 13:40:16 +01:00
All of the helped shaders are in Deus Ex. I looked at a couple shaders,
and they have a pattern like:
vec1 32 ssa_373 = i2b32 ssa_345.w
vec1 32 ssa_374 = bcsel ssa_373, ssa_20, ssa_0
...
vec1 32 ssa_377 = ine ssa_345.w, ssa_0
if ssa_377 {
...
vec1 32 ssa_416 = i2b32 ssa_385.w
vec1 32 ssa_417 = bcsel ssa_416, ssa_386, ssa_374
...
}
The massive help occurs because the i2b32 is removed, then other passes
determine that ssa_374 must be ssa_20 inside the if-statement allowing
the first bcsel to also be deleted.
v2: Rebase on 1-bit Boolean changes.
v3: Fix i2b32 vs ine problem in if-statement replacement. Noticed by
Bas.
Skylake
total instructions in shared programs: 15241394 -> 15186287 (-0.36%)
instructions in affected programs: 890583 -> 835476 (-6.19%)
helped: 355
HURT: 0
helped stats (abs) min: 1 max: 497 x̄: 155.23 x̃: 149
helped stats (rel) min: 0.09% max: 16.49% x̄: 6.10% x̃: 6.59%
95% mean confidence interval for instructions value: -165.07 -145.39
95% mean confidence interval for instructions %-change: -6.42% -5.77%
Instructions are helped.
total cycles in shared programs: 373846583 -> 371023357 (-0.76%)
cycles in affected programs: 118972102 -> 116148876 (-2.37%)
helped: 343
HURT: 14
helped stats (abs) min: 45 max: 118284 x̄: 8332.32 x̃: 6089
helped stats (rel) min: 0.03% max: 38.19% x̄: 2.48% x̃: 1.77%
HURT stats (abs) min: 120 max: 4126 x̄: 2482.79 x̃: 3019
HURT stats (rel) min: 0.16% max: 17.37% x̄: 2.13% x̃: 1.11%
95% mean confidence interval for cycles value: -8723.28 -7093.12
95% mean confidence interval for cycles %-change: -2.57% -2.02%
Cycles are helped.
total spills in shared programs: 32401 -> 23465 (-27.58%)
spills in affected programs: 24457 -> 15521 (-36.54%)
helped: 343
HURT: 0
total fills in shared programs: 37866 -> 31765 (-16.11%)
fills in affected programs: 18889 -> 12788 (-32.30%)
helped: 343
HURT: 0
Broadwell and Haswell had similar results. (Haswell shown)
Haswell
total instructions in shared programs: 13764783 -> 13750679 (-0.10%)
instructions in affected programs: 1176256 -> 1162152 (-1.20%)
helped: 334
HURT: 21
helped stats (abs) min: 1 max: 358 x̄: 42.59 x̃: 47
helped stats (rel) min: 0.09% max: 11.81% x̄: 1.30% x̃: 1.37%
HURT stats (abs) min: 1 max: 61 x̄: 5.76 x̃: 1
HURT stats (rel) min: 0.03% max: 1.84% x̄: 0.17% x̃: 0.03%
95% mean confidence interval for instructions value: -43.99 -35.47
95% mean confidence interval for instructions %-change: -1.35% -1.08%
Instructions are helped.
total cycles in shared programs: 386511910 -> 385402528 (-0.29%)
cycles in affected programs: 143831110 -> 142721728 (-0.77%)
helped: 327
HURT: 39
helped stats (abs) min: 16 max: 25219 x̄: 3519.74 x̃: 3570
helped stats (rel) min: <.01% max: 10.26% x̄: 0.95% x̃: 0.96%
HURT stats (abs) min: 16 max: 4881 x̄: 1065.95 x̃: 997
HURT stats (rel) min: <.01% max: 16.67% x̄: 0.70% x̃: 0.24%
95% mean confidence interval for cycles value: -3375.59 -2686.60
95% mean confidence interval for cycles %-change: -0.92% -0.64%
Cycles are helped.
total spills in shared programs: 100480 -> 97846 (-2.62%)
spills in affected programs: 84702 -> 82068 (-3.11%)
helped: 316
HURT: 21
total fills in shared programs: 96877 -> 94369 (-2.59%)
fills in affected programs: 69167 -> 66659 (-3.63%)
helped: 316
HURT: 9
No changes on Ivy Bridge or earlier platforms.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
169 lines
4.8 KiB
C
169 lines
4.8 KiB
C
/*
|
|
* Copyright © 2016 Red Hat
|
|
*
|
|
* 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:
|
|
* Rob Clark <robclark@freedesktop.org>
|
|
*/
|
|
|
|
#ifndef _NIR_SEARCH_HELPERS_
|
|
#define _NIR_SEARCH_HELPERS_
|
|
|
|
#include "nir.h"
|
|
#include "util/bitscan.h"
|
|
#include <math.h>
|
|
|
|
static inline bool
|
|
is_pos_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
|
|
const uint8_t *swizzle)
|
|
{
|
|
/* only constant srcs: */
|
|
if (!nir_src_is_const(instr->src[src].src))
|
|
return false;
|
|
|
|
for (unsigned i = 0; i < num_components; i++) {
|
|
switch (nir_op_infos[instr->op].input_types[src]) {
|
|
case nir_type_int: {
|
|
int64_t val = nir_src_comp_as_int(instr->src[src].src, swizzle[i]);
|
|
if (val <= 0 || !util_is_power_of_two_or_zero64(val))
|
|
return false;
|
|
break;
|
|
}
|
|
case nir_type_uint: {
|
|
uint64_t val = nir_src_comp_as_uint(instr->src[src].src, swizzle[i]);
|
|
if (val == 0 || !util_is_power_of_two_or_zero64(val))
|
|
return false;
|
|
break;
|
|
}
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static inline bool
|
|
is_neg_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
|
|
const uint8_t *swizzle)
|
|
{
|
|
/* only constant srcs: */
|
|
if (!nir_src_is_const(instr->src[src].src))
|
|
return false;
|
|
|
|
for (unsigned i = 0; i < num_components; i++) {
|
|
switch (nir_op_infos[instr->op].input_types[src]) {
|
|
case nir_type_int: {
|
|
int64_t val = nir_src_comp_as_int(instr->src[src].src, swizzle[i]);
|
|
if (val >= 0 || !util_is_power_of_two_or_zero64(-val))
|
|
return false;
|
|
break;
|
|
}
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static inline bool
|
|
is_zero_to_one(nir_alu_instr *instr, unsigned src, unsigned num_components,
|
|
const uint8_t *swizzle)
|
|
{
|
|
/* only constant srcs: */
|
|
if (!nir_src_is_const(instr->src[src].src))
|
|
return false;
|
|
|
|
for (unsigned i = 0; i < num_components; i++) {
|
|
switch (nir_op_infos[instr->op].input_types[src]) {
|
|
case nir_type_float: {
|
|
double val = nir_src_comp_as_float(instr->src[src].src, swizzle[i]);
|
|
if (isnan(val) || val < 0.0f || val > 1.0f)
|
|
return false;
|
|
break;
|
|
}
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static inline bool
|
|
is_not_const(nir_alu_instr *instr, unsigned src, UNUSED unsigned num_components,
|
|
UNUSED const uint8_t *swizzle)
|
|
{
|
|
return !nir_src_is_const(instr->src[src].src);
|
|
}
|
|
|
|
static inline bool
|
|
is_used_more_than_once(nir_alu_instr *instr)
|
|
{
|
|
bool zero_if_use = list_empty(&instr->dest.dest.ssa.if_uses);
|
|
bool zero_use = list_empty(&instr->dest.dest.ssa.uses);
|
|
|
|
if (zero_use && zero_if_use)
|
|
return false;
|
|
else if (zero_use && list_is_singular(&instr->dest.dest.ssa.if_uses))
|
|
return false;
|
|
else if (zero_if_use && list_is_singular(&instr->dest.dest.ssa.uses))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static inline bool
|
|
is_used_once(nir_alu_instr *instr)
|
|
{
|
|
bool zero_if_use = list_empty(&instr->dest.dest.ssa.if_uses);
|
|
bool zero_use = list_empty(&instr->dest.dest.ssa.uses);
|
|
|
|
if (zero_if_use && zero_use)
|
|
return false;
|
|
|
|
if (!zero_if_use && list_is_singular(&instr->dest.dest.ssa.uses))
|
|
return false;
|
|
|
|
if (!zero_use && list_is_singular(&instr->dest.dest.ssa.if_uses))
|
|
return false;
|
|
|
|
if (!list_is_singular(&instr->dest.dest.ssa.if_uses) &&
|
|
!list_is_singular(&instr->dest.dest.ssa.uses))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static inline bool
|
|
is_used_by_if(nir_alu_instr *instr)
|
|
{
|
|
return !list_empty(&instr->dest.dest.ssa.if_uses);
|
|
}
|
|
|
|
static inline bool
|
|
is_not_used_by_if(nir_alu_instr *instr)
|
|
{
|
|
return list_empty(&instr->dest.dest.ssa.if_uses);
|
|
}
|
|
|
|
#endif /* _NIR_SEARCH_ */
|