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>
This commit is contained in:
@@ -160,6 +160,7 @@ files_libnir = files(
|
||||
'nir_move_vec_src_uses_to_dest.c',
|
||||
'nir_normalize_cubemap_coords.c',
|
||||
'nir_opt_combine_stores.c',
|
||||
'nir_opt_comparison_pre.c',
|
||||
'nir_opt_conditional_discard.c',
|
||||
'nir_opt_constant_folding.c',
|
||||
'nir_opt_copy_prop_vars.c',
|
||||
|
Reference in New Issue
Block a user