nir: Add new rules to optimize NOOP pack/unpack pairs
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 19 Jun 2020 15:24:44 +0000 (17:24 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Mon, 29 Jun 2020 07:18:26 +0000 (09:18 +0200)
nir_load_store_vectorize_test.ssbo_load_adjacent_32_32_64_64 expectations
need to be fixed accordingly.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5589>

src/compiler/nir/nir_opt_algebraic.py
src/compiler/nir/tests/load_store_vectorizer_tests.cpp

index a822813605b95e718fea9a39702cbdf89f213c61..f4b621cbd654afb710d9d61e717b3ca84a0d2d94 100644 (file)
@@ -991,8 +991,13 @@ optimizations.extend([
    # Packing and then unpacking does nothing
    (('unpack_64_2x32_split_x', ('pack_64_2x32_split', a, b)), a),
    (('unpack_64_2x32_split_y', ('pack_64_2x32_split', a, b)), b),
+   (('unpack_64_2x32', ('pack_64_2x32_split', a, b)), ('vec2', a, b)),
+   (('unpack_64_2x32', ('pack_64_2x32', a)), a),
    (('pack_64_2x32_split', ('unpack_64_2x32_split_x', a),
                            ('unpack_64_2x32_split_y', a)), a),
+   (('pack_64_2x32', ('vec2', ('unpack_64_2x32_split_x', a),
+                              ('unpack_64_2x32_split_y', a))), a),
+   (('pack_64_2x32', ('unpack_64_2x32', a)), a),
 
    # Comparing two halves of an unpack separately.  While this optimization
    # should be correct for non-constant values, it's less obvious that it's
index 4001b8d192c9897f6346a89b24bafe0fa833395b..1d1a9e0a055b09388a4f070e0d08cd5991c14adb 100644 (file)
@@ -902,23 +902,19 @@ TEST_F(nir_load_store_vectorize_test, ssbo_load_adjacent_32_32_64_64)
    ASSERT_EQ(loads[0x3]->src.ssa, &load->dest.ssa);
    ASSERT_EQ(loads[0x3]->swizzle[0], 2);
 
-   /* pack_64_2x32(unpack_64_2x32()) is created because the 32-bit and first
-    * 64-bit loads are combined before the second 64-bit load is even considered. */
    nir_ssa_def *val = loads[0x2]->src.ssa;
    ASSERT_EQ(val->bit_size, 64);
    ASSERT_EQ(val->num_components, 1);
-   ASSERT_TRUE(test_alu(val->parent_instr, nir_op_pack_64_2x32));
-   nir_alu_instr *pack = nir_instr_as_alu(val->parent_instr);
-   ASSERT_TRUE(test_alu(pack->src[0].src.ssa->parent_instr, nir_op_unpack_64_2x32));
-   nir_alu_instr *unpack = nir_instr_as_alu(pack->src[0].src.ssa->parent_instr);
-   ASSERT_EQ(unpack->src[0].src.ssa, &load->dest.ssa);
-   ASSERT_EQ(unpack->src[0].swizzle[0], 1);
+   ASSERT_TRUE(test_alu(val->parent_instr, nir_op_mov));
+   nir_alu_instr *mov = nir_instr_as_alu(val->parent_instr);
+   ASSERT_EQ(mov->src[0].src.ssa, &load->dest.ssa);
+   ASSERT_EQ(mov->src[0].swizzle[0], 1);
 
    val = loads[0x1]->src.ssa;
    ASSERT_EQ(val->bit_size, 32);
    ASSERT_EQ(val->num_components, 2);
    ASSERT_TRUE(test_alu(val->parent_instr, nir_op_unpack_64_2x32));
-   unpack = nir_instr_as_alu(val->parent_instr);
+   nir_alu_instr *unpack = nir_instr_as_alu(val->parent_instr);
    ASSERT_EQ(unpack->src[0].src.ssa, &load->dest.ssa);
    ASSERT_EQ(unpack->src[0].swizzle[0], 0);
 }