From b0fd4ef7f8b972460fb2e59cefe2fae20e601d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 9 May 2026 18:34:06 +0200 Subject: [PATCH] nir,panfrost: remove 8-bit and 16-bit booleans We can use integers instead. Reviewed-by: Lorenzo Rossi Reviewed-by: Alyssa Rosenzweig Part-of: --- src/amd/llvm/ac_nir_to_llvm.c | 3 --- src/asahi/compiler/agx_nir_algebraic.py | 2 +- src/asahi/compiler/agx_nir_opt_preamble.c | 2 -- src/compiler/nir/nir_constant_expressions.py | 3 --- src/compiler/nir/nir_defines.h | 2 -- src/compiler/nir/nir_opcodes.py | 10 ++++------ src/compiler/nir/nir_opt_algebraic.py | 4 ++-- src/compiler/nir/nir_opt_phi_to_bool.c | 2 -- src/freedreno/ir3/ir3_compiler_nir.c | 1 - src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 2 -- src/intel/compiler/jay/jay_nir_algebraic.py | 2 +- src/kosmickrisp/compiler/msl_iomap.c | 2 -- 12 files changed, 8 insertions(+), 27 deletions(-) diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index 9fe24288fd6..00d1eff75ad 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -931,9 +931,6 @@ static bool visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr) case nir_op_b2b1: /* after loads */ result = emit_i2b(&ctx->ac, src[0]); break; - case nir_op_b2b16: /* before stores */ - result = LLVMBuildZExt(ctx->ac.builder, src[0], ctx->ac.i16, ""); - break; case nir_op_b2b32: /* before stores */ result = LLVMBuildZExt(ctx->ac.builder, src[0], ctx->ac.i32, ""); break; diff --git a/src/asahi/compiler/agx_nir_algebraic.py b/src/asahi/compiler/agx_nir_algebraic.py index 5efb5b82d62..b1e036459d2 100644 --- a/src/asahi/compiler/agx_nir_algebraic.py +++ b/src/asahi/compiler/agx_nir_algebraic.py @@ -88,7 +88,7 @@ lower_pack = [ lower_selects = [] for T, sizes, one in [('f', [16, 32], 1.0), ('i', [8, 16, 32], 1), - ('b', [16, 32], -1)]: + ('b', [32], -1)]: for size in sizes: lower_selects.extend([ ((f'b2{T}{size}', ('inot', 'a@1')), ('bcsel', a, 0, one)), diff --git a/src/asahi/compiler/agx_nir_opt_preamble.c b/src/asahi/compiler/agx_nir_opt_preamble.c index fe6c07bc6aa..3eb80e95f7f 100644 --- a/src/asahi/compiler/agx_nir_opt_preamble.c +++ b/src/asahi/compiler/agx_nir_opt_preamble.c @@ -115,8 +115,6 @@ alu_cost(nir_alu_instr *alu) case nir_op_ineg: case nir_op_bcsel: case nir_op_b2b1: - case nir_op_b2b8: - case nir_op_b2b16: case nir_op_b2b32: case nir_op_b2i8: case nir_op_b2i16: diff --git a/src/compiler/nir/nir_constant_expressions.py b/src/compiler/nir/nir_constant_expressions.py index 8422ebe2b56..dcc9e2677c2 100644 --- a/src/compiler/nir/nir_constant_expressions.py +++ b/src/compiler/nir/nir_constant_expressions.py @@ -425,10 +425,7 @@ typedef float float16_t; typedef float float32_t; typedef double float64_t; typedef bool bool1_t; -typedef bool bool8_t; -typedef bool bool16_t; typedef bool bool32_t; -typedef bool bool64_t; static inline bool util_add_check_overflow_int1_t(int1_t a, int1_t b) diff --git a/src/compiler/nir/nir_defines.h b/src/compiler/nir/nir_defines.h index c220974f2fc..43b3ef3b492 100644 --- a/src/compiler/nir/nir_defines.h +++ b/src/compiler/nir/nir_defines.h @@ -136,8 +136,6 @@ typedef enum ENUM_PACKED { nir_type_bool = 6, nir_type_float = 128, nir_type_bool1 = 1 | nir_type_bool, - nir_type_bool8 = 8 | nir_type_bool, - nir_type_bool16 = 16 | nir_type_bool, nir_type_bool32 = 32 | nir_type_bool, nir_type_int1 = 1 | nir_type_int, nir_type_int8 = 8 | nir_type_int, diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 872afdd6a66..d863dc8745c 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -128,8 +128,6 @@ tfloat = "float" tint = "int" tbool = "bool" tbool1 = "bool1" -tbool8 = "bool8" -tbool16 = "bool16" tbool32 = "bool32" tuint = "uint" tuint8 = "uint8" @@ -161,7 +159,7 @@ def type_sizes(type_): if type_has_size(type_): return [type_size(type_)] elif type_ == 'bool': - return [1, 8, 16, 32] + return [1, 32] elif type_ == 'float': return [16, 32, 64] else: @@ -655,7 +653,7 @@ def binop_compare32(name, ty, alg_props, const_expr, description = "", ty2=None, def binop_compare_pan(name, ty, alg_props, const_expr, description = "", ty2=None, valid_fp_math_ctrl=None): - binop_convert(name, tbool, ty, alg_props, const_expr, description, ty2, False, valid_fp_math_ctrl) + binop_convert(name, tuint, ty, alg_props, const_expr, description, ty2, False, valid_fp_math_ctrl) def binop_compare_all_sizes(name, ty, alg_props, const_expr, description = "", ty2=None): valid_fp_math_ctrl = None @@ -663,7 +661,7 @@ def binop_compare_all_sizes(name, ty, alg_props, const_expr, description = "", t valid_fp_math_ctrl = preserve_inf + preserve_nan binop_compare(name, ty, alg_props, const_expr, description, ty2, valid_fp_math_ctrl) binop_compare32(name + "32", ty, alg_props, const_expr, description, ty2, valid_fp_math_ctrl) - binop_compare_pan(name + "_pan", ty, alg_props, const_expr, description, ty2, valid_fp_math_ctrl) + binop_compare_pan(name + "_pan", ty, alg_props, const_expr + " ? -1 : 0", description, ty2, valid_fp_math_ctrl) def binop_horiz(name, out_size, out_type, src1_size, src1_type, src2_size, src2_type, const_expr, description = ""): @@ -1244,7 +1242,7 @@ opcode("b32csel", 0, tuint, [0, 0, 0], [tbool32, tuint, tuint], False, selection, "src0 ? src1 : src2", description = csel_description.format("a 32-bit", "0 vs ~0")) opcode("bcsel_pan", 0, tuint, [0, 0, 0], - [tbool, tuint, tuint], False, selection, "src0 ? src1 : src2", + [tuint, tuint, tuint], False, selection, "src0 ? src1 : src2", description = csel_description.format("a same-sized", "0 vs ~0")) triop("icsel_eqz", tint, selection, "(src0 == 0) ? src1 : src2") diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 259bd5b07c5..d3750794b39 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1272,7 +1272,7 @@ for s in [16, 32, 64]: (('i2f{}'.format(s), ('f2i', ('fsign', 'a@{}'.format(s)))), ('fsign', a)), ]) - if s < 64: + if s == 32: optimizations.extend([(('bcsel', a, ('b2f(is_used_once)', 'b@{}'.format(s)), ('b2f', 'c@{}'.format(s))), ('b2f', ('bcsel', a, b, c)))]) for B in [32, 64]: @@ -1417,7 +1417,7 @@ for s in [8, 16, 32, 64]: ]) # There are no 64bit booleans in NIR - if s < 64: + if s == 32: # True/False are ~0 and 0 in NIR. b2i of True is 1, and -1 is ~0 (True). optimizations.extend([(('ineg', ('b2i{}'.format(s), 'a@{}'.format(s))), a)]) diff --git a/src/compiler/nir/nir_opt_phi_to_bool.c b/src/compiler/nir/nir_opt_phi_to_bool.c index 1fcdb00aabf..98463d6f239 100644 --- a/src/compiler/nir/nir_opt_phi_to_bool.c +++ b/src/compiler/nir/nir_opt_phi_to_bool.c @@ -95,8 +95,6 @@ get_bool_types_alu(nir_alu_instr *alu) case nir_op_b2i32: case nir_op_b2i64: return bool_type_single_bit; - case nir_op_b2b8: - case nir_op_b2b16: case nir_op_b2b32: return bool_type_all_bits; case nir_op_b2f16: diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c index 238c398ef16..a06d6f85bbf 100644 --- a/src/freedreno/ir3/ir3_compiler_nir.c +++ b/src/freedreno/ir3/ir3_compiler_nir.c @@ -3609,7 +3609,6 @@ get_tex_dest_type(nir_tex_instr *tex) case nir_type_bool32: case nir_type_uint32: return TYPE_U32; - case nir_type_bool16: case nir_type_uint16: return TYPE_U16; case nir_type_invalid: diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 53f50966cc8..e55bac3a35f 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -3219,8 +3219,6 @@ do_alu_action(struct lp_build_nir_soa_context *bld, case nir_op_b2b1: result = LLVMBuildICmp(builder, LLVMIntNE, src[0], int_bld->zero, ""); break; - case nir_op_b2b8: - case nir_op_b2b16: case nir_op_b2b32: if (src_bit_size[0] > instr->def.bit_size) { result = LLVMBuildTrunc(builder, src[0], dst_uint_bld->vec_type, ""); diff --git a/src/intel/compiler/jay/jay_nir_algebraic.py b/src/intel/compiler/jay/jay_nir_algebraic.py index 209f9585172..4675afe296a 100644 --- a/src/intel/compiler/jay/jay_nir_algebraic.py +++ b/src/intel/compiler/jay/jay_nir_algebraic.py @@ -47,7 +47,7 @@ lower_bool = [ for T, sizes, one in [('f', [16, 32], 1.0), ('i', [8, 16, 32], 1), - ('b', [8, 16, 32], -1)]: + ('b', [32], -1)]: for sz in sizes: if T in ['f', 'i']: lower_bool.extend([ diff --git a/src/kosmickrisp/compiler/msl_iomap.c b/src/kosmickrisp/compiler/msl_iomap.c index 174195a7fa8..fbd61265c3b 100644 --- a/src/kosmickrisp/compiler/msl_iomap.c +++ b/src/kosmickrisp/compiler/msl_iomap.c @@ -36,8 +36,6 @@ alu_type_to_string(nir_alu_type type) return "half"; case nir_type_float32: return "float"; - case nir_type_bool8: - return "bool"; default: UNREACHABLE("Unsupported nir_alu_type"); }