OSDN Git Service

nir/dead_cf: also remove useless ifs
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Mon, 19 Mar 2018 23:34:17 +0000 (16:34 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 21 Mar 2018 16:36:09 +0000 (09:36 -0700)
commit8571c577aa02be048826f8667b93709c3c620fc5
treeaf67178e827d1ed6316e49780256972217340b23
parent470056d37b88070b630c1e95c8590c282dff82fd
nir/dead_cf: also remove useless ifs

Generalize the code for remove dead loops to also remove dead if
nodes. The conditions are the same in both cases, if the node (and
it's children) don't have side-effects AND the nodes after it don't
use the values produced by the node.

The only difference is when evaluating side effects: loops consider
only return jumps as a side-effect -- they can stop execution of nodes
after it; 'if' nodes outside loops should consider all kinds of
jumps (return, break, continue) since all of them can cause execution
of nodes after it to be skipped.

After this patch, empty ifs (those which both then and else blocks are
empty) will be removed by nir_opt_dead_cf.

It caused no change to shader-db, in part because the removal of empty
ifs is currently covered by nir_opt_peephole_select.

v2: Improve the identification of cases where break/continue can cause
    side-effects. (Jason)

v3: Move code comment changes to a different patch. (Jason)

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