aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Brezillon <[email protected]>2020-06-19 17:24:44 +0200
committerBoris Brezillon <[email protected]>2020-06-29 09:18:26 +0200
commitcff418cc4caba78117986a31ce3852f2c137a95b (patch)
treea6b79825193be755db8e1cd18360b75aae0b3fdc
parent237d72841805a6964b8ebef17c044020e34b1141 (diff)
nir: Add new rules to optimize NOOP pack/unpack pairs
nir_load_store_vectorize_test.ssbo_load_adjacent_32_32_64_64 expectations need to be fixed accordingly. Signed-off-by: Boris Brezillon <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5589>
-rw-r--r--src/compiler/nir/nir_opt_algebraic.py5
-rw-r--r--src/compiler/nir/tests/load_store_vectorizer_tests.cpp14
2 files changed, 10 insertions, 9 deletions
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index a822813605b..f4b621cbd65 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -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
diff --git a/src/compiler/nir/tests/load_store_vectorizer_tests.cpp b/src/compiler/nir/tests/load_store_vectorizer_tests.cpp
index 4001b8d192c..1d1a9e0a055 100644
--- a/src/compiler/nir/tests/load_store_vectorizer_tests.cpp
+++ b/src/compiler/nir/tests/load_store_vectorizer_tests.cpp
@@ -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);
}