nir: Make boolean conversions sized just like the others
Instead of a single i2b and b2i, we now have i2b32 and b2iN where N is one if 8, 16, 32, or 64. This leads to having a few more opcodes but now everything is consistent and booleans aren't a weird special case anymore. Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:
@@ -440,7 +440,7 @@ optimizations = [
|
||||
(('fsat', ('fadd', ('b2f', 'a@32'), ('b2f', 'b@32'))), ('b2f', ('ior', a, b))),
|
||||
(('iand', 'a@bool', 1.0), ('b2f', a), '!options->lower_b2f'),
|
||||
# True/False are ~0 and 0 in NIR. b2i of True is 1, and -1 is ~0 (True).
|
||||
(('ineg', ('b2i@32', 'a@32')), a),
|
||||
(('ineg', ('b2i32', 'a@32')), a),
|
||||
(('flt', ('fneg', ('b2f', 'a@32')), 0), a), # Generated by TGSI KILL_IF.
|
||||
(('flt', ('fsub', 0.0, ('b2f', 'a@32')), 0), a), # Generated by TGSI KILL_IF.
|
||||
# Comparison with the same args. Note that these are not done for
|
||||
@@ -532,15 +532,15 @@ optimizations = [
|
||||
(('fcsel', a, b, b), b),
|
||||
|
||||
# Conversions
|
||||
(('i2b', ('b2i', 'a@32')), a),
|
||||
(('i2b', 'a@bool'), a),
|
||||
(('i2b32', ('b2i', 'a@32')), a),
|
||||
(('i2b32', 'a@bool'), a),
|
||||
(('f2i', ('ftrunc', a)), ('f2i', a)),
|
||||
(('f2u', ('ftrunc', a)), ('f2u', a)),
|
||||
(('i2b', ('ineg', a)), ('i2b', a)),
|
||||
(('i2b', ('iabs', a)), ('i2b', a)),
|
||||
(('fabs', ('b2f', a)), ('b2f', a)),
|
||||
(('iabs', ('b2i', a)), ('b2i', a)),
|
||||
(('inot', ('f2b', a)), ('feq', a, 0.0)),
|
||||
(('inot', ('f2b32', a)), ('feq', a, 0.0)),
|
||||
|
||||
# Ironically, mark these as imprecise because removing the conversions may
|
||||
# preserve more precision than doing the conversions (e.g.,
|
||||
@@ -754,8 +754,8 @@ for left, right in itertools.combinations_with_replacement(invert.keys(), 2):
|
||||
('ior', (invert[left], a, b), (invert[right], c, d))))
|
||||
|
||||
# Optimize x2yN(b2x(x)) -> b2y
|
||||
optimizations.append((('f2b', ('b2f', 'a@32')), a))
|
||||
optimizations.append((('i2b', ('b2i', 'a@32')), a))
|
||||
optimizations.append((('f2b32', ('b2f', 'a@32')), a))
|
||||
optimizations.append((('i2b32', ('b2i', 'a@32')), a))
|
||||
for x, y in itertools.product(['f', 'u', 'i'], ['f', 'u', 'i']):
|
||||
if x != 'f' and y != 'f' and x != y:
|
||||
continue
|
||||
@@ -916,7 +916,7 @@ late_optimizations = [
|
||||
(('fmax', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmax', a, b))),
|
||||
|
||||
# Lowered for backends without a dedicated b2f instruction
|
||||
(('b2f@32', 'a@32'), ('iand', a, 1.0), 'options->lower_b2f'),
|
||||
(('b2f32', 'a@32'), ('iand', a, 1.0), 'options->lower_b2f'),
|
||||
]
|
||||
|
||||
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render())
|
||||
|
||||
Reference in New Issue
Block a user