nir: Use SM5 properties to optimize shift(a@32, iand(31, b))
authorDaniel Schürmann <daniel.schuermann@campus.tu-berlin.de>
Fri, 22 Feb 2019 21:05:07 +0000 (22:05 +0100)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 25 Feb 2019 18:59:44 +0000 (12:59 -0600)
This is a common pattern from HLSL->SPIRV translation
and supported in HW by all current NIR backends.

vkpipeline-db results anv (SKL):

    total instructions in shared programs: 6403130 -> 6402380 (-0.01%)
    instructions in affected programs: 204084 -> 203334 (-0.37%)
    helped: 208
    HURT: 0

    total cycles in shared programs: 1915629582 -> 1918198408 (0.13%)
    cycles in affected programs: 1158892682 -> 1161461508 (0.22%)
    helped: 107
    HURT: 86

shader-db results on i965 (KBL):

    total instructions in shared programs: 15284592 -> 15284568 (<.01%)
    instructions in affected programs: 81683 -> 81659 (-0.03%)
    helped: 24
    HURT: 0

    total cycles in shared programs: 375013622 -> 375013932 (<.01%)
    cycles in affected programs: 40169618 -> 40169928 (<.01%)
    helped: 13
    HURT: 9

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_opt_algebraic.py

index ba27d702b5db63abcc274632f4992ac5850e2f25..4d01f110f80399c99b2240e2a0a6ae8fc82443ff 100644 (file)
@@ -552,6 +552,11 @@ optimizations = [
    (('ine', ('ineg', ('b2i', 'a@1')), -1), ('inot', a)),
    (('iand', ('ineg', ('b2i', a)), 1.0), ('b2f', a)),
 
+   # SM5 32-bit shifts are defined to use the 5 least significant bits
+   (('ishl', 'a@32', ('iand', 31, b)), ('ishl', a, b)),
+   (('ishr', 'a@32', ('iand', 31, b)), ('ishr', a, b)),
+   (('ushr', 'a@32', ('iand', 31, b)), ('ushr', a, b)),
+
    # Conversions
    (('i2b32', ('b2i', 'a@32')), a),
    (('f2i', ('ftrunc', a)), ('f2i', a)),