Module: Mesa Branch: main Commit: d74606d440476ae3a766062828e83e94c72de400 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d74606d440476ae3a766062828e83e94c72de400
Author: Emma Anholt <[email protected]> Date: Thu Feb 10 14:47:42 2022 -0800 gallivm/nir: Refactor out some repeated code to generate 0 values. Reviewed-by: Dave Airlie <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14999> --- src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 35 ++++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 0213aac69ec..de9565a9072 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -91,6 +91,19 @@ invocation_0_must_be_active(struct lp_build_nir_context *bld_base) return true; } +static LLVMValueRef +lp_build_zero_bits(struct gallivm_state *gallivm, int bit_size) +{ + if (bit_size == 64) + return LLVMConstInt(LLVMInt64TypeInContext(gallivm->context), 0, 0); + else if (bit_size == 16) + return LLVMConstInt(LLVMInt16TypeInContext(gallivm->context), 0, 0); + else if (bit_size == 8) + return LLVMConstInt(LLVMInt8TypeInContext(gallivm->context), 0, 0); + else + return lp_build_const_int32(gallivm, 0); +} + static LLVMValueRef emit_fetch_64bit( struct lp_build_nir_context * bld_base, @@ -1170,15 +1183,7 @@ static void emit_load_mem(struct lp_build_nir_context *bld_base, LLVMBuildStore(builder, temp_res, result[c]); lp_build_else(&ifthen); temp_res = LLVMBuildLoad(builder, result[c], ""); - LLVMValueRef zero; - if (bit_size == 64) - zero = LLVMConstInt(LLVMInt64TypeInContext(gallivm->context), 0, 0); - else if (bit_size == 16) - zero = LLVMConstInt(LLVMInt16TypeInContext(gallivm->context), 0, 0); - else if (bit_size == 8) - zero = LLVMConstInt(LLVMInt8TypeInContext(gallivm->context), 0, 0); - else - zero = lp_build_const_int32(gallivm, 0); + LLVMValueRef zero = lp_build_zero_bits(gallivm, bit_size); temp_res = LLVMBuildInsertElement(builder, temp_res, zero, loop_state.counter, ""); LLVMBuildStore(builder, temp_res, result[c]); lp_build_endif(&ifthen); @@ -1368,7 +1373,7 @@ static void emit_atomic_mem(struct lp_build_nir_context *bld_base, LLVMBuildStore(builder, temp_res, atom_res); lp_build_else(&ifthen); temp_res = LLVMBuildLoad(builder, atom_res, ""); - LLVMValueRef zero = bit_size == 64 ? lp_build_const_int64(gallivm, 0) : lp_build_const_int32(gallivm, 0); + LLVMValueRef zero = lp_build_zero_bits(gallivm, bit_size); temp_res = LLVMBuildInsertElement(builder, temp_res, zero, loop_state.counter, ""); LLVMBuildStore(builder, temp_res, atom_res); lp_build_endif(&ifthen); @@ -2390,15 +2395,7 @@ emit_load_scratch(struct lp_build_nir_context *bld_base, LLVMBuildStore(builder, temp_res, result); lp_build_else(&ifthen); temp_res = LLVMBuildLoad(builder, result, ""); - LLVMValueRef zero; - if (bit_size == 64) - zero = LLVMConstInt(LLVMInt64TypeInContext(gallivm->context), 0, 0); - else if (bit_size == 16) - zero = LLVMConstInt(LLVMInt16TypeInContext(gallivm->context), 0, 0); - else if (bit_size == 8) - zero = LLVMConstInt(LLVMInt8TypeInContext(gallivm->context), 0, 0); - else - zero = lp_build_const_int32(gallivm, 0); + LLVMValueRef zero = lp_build_zero_bits(gallivm, bit_size); temp_res = LLVMBuildInsertElement(builder, temp_res, zero, loop_state.counter, ""); LLVMBuildStore(builder, temp_res, result); lp_build_endif(&ifthen);
