diff options
author | Daniel Schürmann <[email protected]> | 2019-01-25 16:24:55 +0100 |
---|---|---|
committer | Daniel Schürmann <[email protected]> | 2019-06-24 18:42:20 +0200 |
commit | 0daeb1d127987c8e70afe22cb30f676fb4631813 (patch) | |
tree | 1f8fccca3b639f872615340587cef7ce815318de /src | |
parent | 48a75e7af096f07d3d1984124bb29694c14ff61f (diff) |
amd/common: lower bitfield_extract to ubfe/ibfe.
Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/amd/common/ac_llvm_build.c | 21 | ||||
-rw-r--r-- | src/amd/common/ac_nir_to_llvm.c | 34 | ||||
-rw-r--r-- | src/amd/vulkan/radv_shader.c | 1 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_get.c | 1 |
4 files changed, 22 insertions, 35 deletions
diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c index 1e6247ad72e..edadd56cc7b 100644 --- a/src/amd/common/ac_llvm_build.c +++ b/src/amd/common/ac_llvm_build.c @@ -2798,11 +2798,22 @@ LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input, width, }; - return ac_build_intrinsic(ctx, - is_signed ? "llvm.amdgcn.sbfe.i32" : - "llvm.amdgcn.ubfe.i32", - ctx->i32, args, 3, - AC_FUNC_ATTR_READNONE); + LLVMValueRef result = ac_build_intrinsic(ctx, + is_signed ? "llvm.amdgcn.sbfe.i32" : + "llvm.amdgcn.ubfe.i32", + ctx->i32, args, 3, + AC_FUNC_ATTR_READNONE); + + if (HAVE_LLVM < 0x0800) { + /* FIXME: LLVM 7+ returns incorrect result when count is 0. + * https://bugs.freedesktop.org/show_bug.cgi?id=107276 + */ + LLVMValueRef zero = ctx->i32_0; + LLVMValueRef icond = LLVMBuildICmp(ctx->builder, LLVMIntEQ, width, zero, ""); + result = LLVMBuildSelect(ctx->builder, icond, zero, result, ""); + } + + return result; } LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0, diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index 9b6e65db8b9..636fd4035c8 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -429,32 +429,6 @@ static LLVMValueRef emit_imul_high(struct ac_llvm_context *ctx, return result; } -static LLVMValueRef emit_bitfield_extract(struct ac_llvm_context *ctx, - bool is_signed, - const LLVMValueRef srcs[3]) -{ - LLVMValueRef result; - - if (HAVE_LLVM >= 0x0800) { - LLVMValueRef icond = LLVMBuildICmp(ctx->builder, LLVMIntEQ, srcs[2], LLVMConstInt(ctx->i32, 32, false), ""); - result = ac_build_bfe(ctx, srcs[0], srcs[1], srcs[2], is_signed); - result = LLVMBuildSelect(ctx->builder, icond, srcs[0], result, ""); - } else { - /* FIXME: LLVM 7+ returns incorrect result when count is 0. - * https://bugs.freedesktop.org/show_bug.cgi?id=107276 - */ - LLVMValueRef zero = ctx->i32_0; - LLVMValueRef icond1 = LLVMBuildICmp(ctx->builder, LLVMIntEQ, srcs[2], LLVMConstInt(ctx->i32, 32, false), ""); - LLVMValueRef icond2 = LLVMBuildICmp(ctx->builder, LLVMIntEQ, srcs[2], zero, ""); - - result = ac_build_bfe(ctx, srcs[0], srcs[1], srcs[2], is_signed); - result = LLVMBuildSelect(ctx->builder, icond1, srcs[0], result, ""); - result = LLVMBuildSelect(ctx->builder, icond2, zero, result, ""); - } - - return result; -} - static LLVMValueRef emit_bfm(struct ac_llvm_context *ctx, LLVMValueRef bits, LLVMValueRef offset) { @@ -837,11 +811,11 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr) case nir_op_bitfield_select: result = emit_bitfield_select(&ctx->ac, src[0], src[1], src[2]); break; - case nir_op_ibitfield_extract: - result = emit_bitfield_extract(&ctx->ac, true, src); + case nir_op_ubfe: + result = ac_build_bfe(&ctx->ac, src[0], src[1], src[2], false); break; - case nir_op_ubitfield_extract: - result = emit_bitfield_extract(&ctx->ac, false, src); + case nir_op_ibfe: + result = ac_build_bfe(&ctx->ac, src[0], src[1], src[2], true); break; case nir_op_bitfield_reverse: result = ac_build_bitfield_reverse(&ctx->ac, src[0]); diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 3452a0b2ad2..c8dc9daf1bc 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -59,6 +59,7 @@ static const struct nir_shader_compiler_options nir_options = { .lower_fsat = true, .lower_fdiv = true, .lower_bitfield_insert_to_bitfield_select = true, + .lower_bitfield_extract = true, .lower_sub = true, .lower_pack_snorm_2x16 = true, .lower_pack_snorm_4x8 = true, diff --git a/src/gallium/drivers/radeonsi/si_get.c b/src/gallium/drivers/radeonsi/si_get.c index b7c7f1aa78c..5c2806341b3 100644 --- a/src/gallium/drivers/radeonsi/si_get.c +++ b/src/gallium/drivers/radeonsi/si_get.c @@ -488,6 +488,7 @@ static const struct nir_shader_compiler_options nir_options = { .lower_fsat = true, .lower_fdiv = true, .lower_bitfield_insert_to_bitfield_select = true, + .lower_bitfield_extract = true, .lower_sub = true, .lower_ffma = true, .lower_fmod = true, |