<div dir="ltr"><div>Ian,</div><div><br></div><div>This patch demonstrates the need for patch 2. Without patch 2, it fails a number of tests as one would expect. I'm not really sure why you didn't see fails without this but I didn't either.<br></div><div><br></div><div>--Jason<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Oct 11, 2018 at 10:38 AM Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The b2f and b2i conversions always produce zero or one which are both<br>
representable in every type and size. Since b2i and b2f support all bit<br>
sizes, we can just get rid of the conversion opcode.<br>
<br>
total instructions in shared programs: 15089335 -> 15084368 (-0.03%)<br>
instructions in affected programs: 212564 -> 207597 (-2.34%)<br>
helped: 896<br>
HURT: 0<br>
<br>
total cycles in shared programs: 369831123 -> 369826267 (<.01%)<br>
cycles in affected programs: 2008647 -> 2003791 (-0.24%)<br>
helped: 693<br>
HURT: 216<br>
---<br>
src/compiler/nir/nir_opt_algebraic.py | 17 +++++++++++++++++<br>
1 file changed, 17 insertions(+)<br>
<br>
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py<br>
index 422a8794d38..cc747250ba5 100644<br>
--- a/src/compiler/nir/nir_opt_algebraic.py<br>
+++ b/src/compiler/nir/nir_opt_algebraic.py<br>
@@ -751,6 +751,23 @@ for left, right in itertools.combinations_with_replacement(invert.keys(), 2):<br>
optimizations.append((('inot', ('iand(is_used_once)', (left, a, b), (right, c, d))),<br>
('ior', (invert[left], a, b), (invert[right], c, d))))<br>
<br>
+# Optimize x2yN(b2x(x)) -> b2y<br>
+optimizations.append((('f2b', ('b2f', a)), a))<br>
+optimizations.append((('i2b', ('b2i', a)), a))<br>
+for x, y in itertools.product(['f', 'u', 'i'], ['f', 'u', 'i']):<br>
+ if x != 'f' and y != 'f' and x != y:<br>
+ continue<br>
+<br>
+ b2x = 'b2f' if x == 'f' else 'b2i'<br>
+ b2y = 'b2f' if y == 'f' else 'b2i'<br>
+<br>
+ for N in [8, 16, 32, 64]:<br>
+ if y == 'f' and N == 8:<br>
+ continue<br>
+<br>
+ x2yN = '{}2{}{}'.format(x, y, N)<br>
+ optimizations.append(((x2yN, (b2x, a)), (b2y, a)))<br>
+<br>
def fexp2i(exp, bits):<br>
# We assume that exp is already in the right range.<br>
if bits == 32:<br>
-- <br>
2.19.1<br>
<br>
</blockquote></div>