From 9342c14eeb4a751fce7bd413aca56bc46036ed22 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 15 Feb 2022 15:29:42 -0800 Subject: [PATCH] nir/builder: Emit x != 0 for nir_i2b MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit There are a lot of optimizations in opt_algebraic that match ('ine', a, 0), but there are almost none that match i2b. Instead of adding a huge pile of additional patterns (including variation that include both ine and i2b), just emit a != 0 instead of i2b(a). I think that the changes to the unit tests weaken them slightly, but perhaps that's okay? No shader-db changes on any Intel platform. The GLSL paths use other means to generate i2b operations, but the SPIR-V paths use nir_i2b. Presumably since 4676b3d3dd9 (nir: Use nir_test_mask instead of i2b(iand)), no fossil-db changes either. v2: Use nir_ine_imm. Suggested by Jesse. Acked-by: Jesse Natalie Acked-by: Alyssa Rosenzweig Tested-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_builder.h | 2 +- src/compiler/nir/tests/load_store_vectorizer_tests.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 4419d38..9fad861 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -413,7 +413,7 @@ nir_f2b(nir_builder *b, nir_ssa_def *src) static inline nir_ssa_def * nir_i2b(nir_builder *b, nir_ssa_def *src) { - return nir_type_convert(b, src, nir_type_int, nir_type_bool1); + return nir_ine(b, src, nir_imm_intN_t(b, 0, src->bit_size)); } static inline nir_ssa_def * diff --git a/src/compiler/nir/tests/load_store_vectorizer_tests.cpp b/src/compiler/nir/tests/load_store_vectorizer_tests.cpp index efe1993..e0d1ed9 100644 --- a/src/compiler/nir/tests/load_store_vectorizer_tests.cpp +++ b/src/compiler/nir/tests/load_store_vectorizer_tests.cpp @@ -1461,8 +1461,9 @@ TEST_F(nir_load_store_vectorize_test, shared_load_bool) ASSERT_EQ(deref->deref_type, nir_deref_type_var); ASSERT_EQ(deref->var, var); - ASSERT_TRUE(test_alu(loads[0x1]->src.ssa->parent_instr, nir_op_i2b1)); - ASSERT_TRUE(test_alu(loads[0x2]->src.ssa->parent_instr, nir_op_i2b1)); + /* The loaded value is converted to Boolean by (loaded != 0). */ + ASSERT_TRUE(test_alu(loads[0x1]->src.ssa->parent_instr, nir_op_ine)); + ASSERT_TRUE(test_alu(loads[0x2]->src.ssa->parent_instr, nir_op_ine)); ASSERT_TRUE(test_alu_def(loads[0x1]->src.ssa->parent_instr, 0, &load->dest.ssa, 0)); ASSERT_TRUE(test_alu_def(loads[0x2]->src.ssa->parent_instr, 0, &load->dest.ssa, 1)); } @@ -1500,7 +1501,8 @@ TEST_F(nir_load_store_vectorize_test, shared_load_bool_mixed) ASSERT_EQ(deref->deref_type, nir_deref_type_var); ASSERT_EQ(deref->var, var); - ASSERT_TRUE(test_alu(loads[0x1]->src.ssa->parent_instr, nir_op_i2b1)); + /* The loaded value is converted to Boolean by (loaded != 0). */ + ASSERT_TRUE(test_alu(loads[0x1]->src.ssa->parent_instr, nir_op_ine)); ASSERT_TRUE(test_alu_def(loads[0x1]->src.ssa->parent_instr, 0, &load->dest.ssa, 0)); EXPECT_INSTR_SWIZZLES(movs[0x2], load, "y"); -- 2.7.4