From: Ian Romanick Date: Thu, 22 Feb 2018 02:30:20 +0000 (-0800) Subject: nir/algebraic: Recognize open-coded copysign(1.0, a) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=25bfba3335d0fb2822dac02822d096dd75b3ef4d;p=mesa.git nir/algebraic: Recognize open-coded copysign(1.0, a) All of the affected shaders are in Mad Max. The inner part of the pattern is itself an open-coded sign(a). I tried using that as a pattern, but the results were not good. A bunch of shaders were helped for instructions, but overall cycles, spill, and fills were hurt. v2: Rebase on 1-bit Boolean changes. v3: Fix order of copysign() parameters in comments and commit message. Noticed by Matt. All Gen7+ platforms had similar results. (Skylake shown) total instructions in shared programs: 15282141 -> 15282073 (<.01%) instructions in affected programs: 6106 -> 6038 (-1.11%) helped: 17 HURT: 0 helped stats (abs) min: 4 max: 4 x̄: 4.00 x̃: 4 helped stats (rel) min: 1.02% max: 2.20% x̄: 1.15% x̃: 1.06% 95% mean confidence interval for instructions value: -4.00 -4.00 95% mean confidence interval for instructions %-change: -1.30% -1.00% Instructions are helped. total cycles in shared programs: 372597886 -> 372595954 (<.01%) cycles in affected programs: 32701 -> 30769 (-5.91%) helped: 17 HURT: 0 helped stats (abs) min: 6 max: 216 x̄: 113.65 x̃: 118 helped stats (rel) min: 0.40% max: 21.86% x̄: 6.20% x̃: 5.83% 95% mean confidence interval for cycles value: -152.84 -74.45 95% mean confidence interval for cycles %-change: -8.89% -3.51% Cycles are helped. No changes on any Gen6 or earlier platforms. Reviewed-by: Matt Turner --- diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index e8696abaf52..f275d70d276 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -394,6 +394,12 @@ optimizations = [ (('ior', ('uge', 1, a), ('ieq', a, 2)), ('uge', 2, a)), (('ior', ('uge', 2, a), ('ieq', a, 3)), ('uge', 3, a)), + # The (i2f32, ...) part is an open-coded fsign. When that is combined with + # the bcsel, it's basically copysign(1.0, a). There is no copysign in NIR, + # so emit an open-coded version of that. + (('bcsel@32', ('feq', a, 0.0), 1.0, ('i2f32', ('iadd', ('b2i32', ('flt', 0.0, 'a@32')), ('ineg', ('b2i32', ('flt', 'a@32', 0.0)))))), + ('ior', 0x3f800000, ('iand', a, 0x80000000))), + (('ior', a, ('ieq', a, False)), True), (('ior', a, ('inot', a)), -1),