nir: add lower_bitshift option
Add a "lower_bitshift" option, which disables optimizations introducing bitshifts and lowers ishl by constant to a multiply, so that we don't have to deal with bitshifts in int_to_float lowering. Signed-off-by: Jonathan Marek <jonathan@marek.ca> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
@@ -2272,6 +2272,9 @@ typedef struct nir_shader_compiler_options {
|
||||
/** enables rules to lower idiv by power-of-two: */
|
||||
bool lower_idiv;
|
||||
|
||||
/** enable rules to avoid bit shifts */
|
||||
bool lower_bitshift;
|
||||
|
||||
/** enables rules to lower isign to imin+imax */
|
||||
bool lower_isign;
|
||||
|
||||
|
@@ -69,8 +69,10 @@ e = 'e'
|
||||
|
||||
optimizations = [
|
||||
|
||||
(('imul', a, '#b@32(is_pos_power_of_two)'), ('ishl', a, ('find_lsb', b))),
|
||||
(('imul', a, '#b@32(is_neg_power_of_two)'), ('ineg', ('ishl', a, ('find_lsb', ('iabs', b))))),
|
||||
(('imul', a, '#b@32(is_pos_power_of_two)'), ('ishl', a, ('find_lsb', b)), '!options->lower_bitshift'),
|
||||
(('imul', a, '#b@32(is_neg_power_of_two)'), ('ineg', ('ishl', a, ('find_lsb', ('iabs', b)))), '!options->lower_bitshift'),
|
||||
(('ishl', a, '#b@32'), ('imul', a, ('ishl', 1, b)), 'options->lower_bitshift'),
|
||||
|
||||
(('unpack_64_2x32_split_x', ('imul_2x32_64(is_used_once)', a, b)), ('imul', a, b)),
|
||||
(('unpack_64_2x32_split_x', ('umul_2x32_64(is_used_once)', a, b)), ('imul', a, b)),
|
||||
(('imul_2x32_64', a, b), ('pack_64_2x32_split', ('imul', a, b), ('imul_high', a, b)), 'options->lower_mul_2x32_64'),
|
||||
@@ -79,7 +81,7 @@ optimizations = [
|
||||
(('idiv', a, 1), a),
|
||||
(('umod', a, 1), 0),
|
||||
(('imod', a, 1), 0),
|
||||
(('udiv', a, '#b@32(is_pos_power_of_two)'), ('ushr', a, ('find_lsb', b))),
|
||||
(('udiv', a, '#b@32(is_pos_power_of_two)'), ('ushr', a, ('find_lsb', b)), '!options->lower_bitshift'),
|
||||
(('idiv', a, '#b@32(is_pos_power_of_two)'), ('imul', ('isign', a), ('ushr', ('iabs', a), ('find_lsb', b))), 'options->lower_idiv'),
|
||||
(('idiv', a, '#b@32(is_neg_power_of_two)'), ('ineg', ('imul', ('isign', a), ('ushr', ('iabs', a), ('find_lsb', ('iabs', b))))), 'options->lower_idiv'),
|
||||
(('umod', a, '#b(is_pos_power_of_two)'), ('iand', a, ('isub', b, 1))),
|
||||
|
@@ -39,6 +39,7 @@ static const nir_shader_compiler_options options = {
|
||||
/* .fdot_replicates = true, it is replicated, but it makes things worse */
|
||||
.lower_all_io_to_temps = true,
|
||||
.vertex_id_zero_based = true, /* its not implemented anyway */
|
||||
.lower_bitshift = true,
|
||||
};
|
||||
|
||||
const nir_shader_compiler_options *
|
||||
|
@@ -50,6 +50,7 @@ static const nir_shader_compiler_options vs_nir_options = {
|
||||
.lower_ftrunc = true,
|
||||
/* could be implemented by clamp */
|
||||
.lower_fsat = true,
|
||||
.lower_bitshift = true,
|
||||
};
|
||||
|
||||
static const nir_shader_compiler_options fs_nir_options = {
|
||||
|
Reference in New Issue
Block a user