amd/common: lower bitfield_extract to ubfe/ibfe.
authorDaniel Schürmann <daniel.schuermann@campus.tu-berlin.de>
Fri, 25 Jan 2019 15:24:55 +0000 (16:24 +0100)
committerDaniel Schürmann <daniel@schuermann.dev>
Mon, 24 Jun 2019 16:42:20 +0000 (18:42 +0200)
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_nir_to_llvm.c
src/amd/vulkan/radv_shader.c
src/gallium/drivers/radeonsi/si_get.c

index 1e6247ad72e11db342e25fc8e1f0b233869046fb..edadd56cc7b11f374bc88ae6a12ec303a74a1a8a 100644 (file)
@@ -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,
index 9b6e65db8b9ee72cd7134628f6901ec2562591ea..636fd4035c8274a7ba7dec5579a46611a4e8a517 100644 (file)
@@ -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]);
index 3452a0b2ad2b968e20273fe536a95bd0aae19b50..c8dc9daf1bc686bd43c6060379e1aba8595713fd 100644 (file)
@@ -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,
index b7c7f1aa78c66e67d5f508287679844dc0fc449f..5c2806341b3f5bb29c1c3ee2f54da0e80613a7ee 100644 (file)
@@ -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,