OSDN Git Service

nir: Add partial redundancy elimination for compares
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 23 May 2018 01:19:16 +0000 (18:19 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 28 Mar 2019 22:35:53 +0000 (15:35 -0700)
commit2cf59861a8128a91bfdd6fe62bf69cb4593373e3
tree33daec3329c0ccb028e108649ffbdc6dc5881879
parentc6ee46a7532291fc8583400e174e77b1833daf23
nir: Add partial redundancy elimination for compares

This pass attempts to dectect code sequences like

    if (x < y) {
        z = y - x;
...
    }

and replace them with sequences like

    t = x - y;
    if (t < 0) {
        z = -t;
...
    }

On architectures where the subtract can generate the flags used by the
if-statement, this saves an instruction.  It's also possible that moving
an instruction out of the if-statement will allow
nir_opt_peephole_select to convert the whole thing to a bcsel.

Currently only floating point compares and adds are supported.  Adding
support for integer will be a challenge due to integer overflow.  There
are a couple possible solutions, but they may not apply to all
architectures.

v2: Fix a typo in the commit message and a couple typos in comments.
Fix possible NULL pointer deref from result of push_block().  Add
missing (-A + B) case.  Suggested by Caio.

v3: Fix is_not_const_zero to work correctly with types other than
nir_type_float32.  Suggested by Ken.

v4: Add some comments explaining how this works.  Suggested by Ken.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/Makefile.sources
src/compiler/nir/meson.build
src/compiler/nir/nir.h
src/compiler/nir/nir_opt_comparison_pre.c [new file with mode: 0644]
src/compiler/nir/nir_search_helpers.h