ac: use new LLVM 8 intrinsic when storing 16-bit values
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 13 Mar 2019 13:52:27 +0000 (14:52 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 20 Mar 2019 21:19:14 +0000 (22:19 +0100)
vindex is always 0.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c

index f8cc3523bb97ecd13034bd05ac8063e8666c0c73..73dd0230785b11a23cb3b2fb31454e5e89fe77e0 100644 (file)
@@ -1741,6 +1741,26 @@ ac_build_raw_tbuffer_store(struct ac_llvm_context *ctx,
                               writeonly_memory, false);
 }
 
+void
+ac_build_tbuffer_store_short(struct ac_llvm_context *ctx,
+                            LLVMValueRef rsrc,
+                            LLVMValueRef vdata,
+                            LLVMValueRef voffset,
+                            LLVMValueRef soffset,
+                            bool glc,
+                            bool writeonly_memory)
+{
+       unsigned dfmt = V_008F0C_BUF_DATA_FORMAT_16;
+       unsigned nfmt = V_008F0C_BUF_NUM_FORMAT_UINT;
+
+       vdata = LLVMBuildBitCast(ctx->builder, vdata, ctx->i16, "");
+       vdata = LLVMBuildZExt(ctx->builder, vdata, ctx->i32, "");
+
+       ac_build_raw_tbuffer_store(ctx, rsrc, vdata, voffset, soffset,
+                                  ctx->i32_0, 1, dfmt, nfmt, glc, false,
+                                  writeonly_memory);
+}
+
 /**
  * Set range metadata on an instruction.  This can only be used on load and
  * call instructions.  If you know an instruction can only produce the values
index ae0bdbcfd1c327fc300118833d515820c9b9da52..723aec53cbe1254f953a6042916d83db05c3c9b2 100644 (file)
@@ -343,6 +343,15 @@ ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx,
                          bool slc,
                          bool can_speculate);
 
+void
+ac_build_tbuffer_store_short(struct ac_llvm_context *ctx,
+                            LLVMValueRef rsrc,
+                            LLVMValueRef vdata,
+                            LLVMValueRef voffset,
+                            LLVMValueRef soffset,
+                            bool glc,
+                            bool writeonly_memory);
+
 void
 ac_build_struct_tbuffer_store(struct ac_llvm_context *ctx,
                              LLVMValueRef rsrc,
index 530cf7a0212cb403fa9bbb18c6b5a250bec88714..fd6dbcce530ce9cf73837a54deb4909d547c1392 100644 (file)
@@ -1523,14 +1523,12 @@ static unsigned get_cache_policy(struct ac_nir_context *ctx,
 static void visit_store_ssbo(struct ac_nir_context *ctx,
                              nir_intrinsic_instr *instr)
 {
-       const char *store_name;
        LLVMValueRef src_data = get_src(ctx, instr->src[0]);
        int elem_size_bytes = ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src_data)) / 8;
        unsigned writemask = nir_intrinsic_write_mask(instr);
        enum gl_access_qualifier access = nir_intrinsic_access(instr);
        bool writeonly_memory = access & ACCESS_NON_READABLE;
        unsigned cache_policy = get_cache_policy(ctx, access, false, writeonly_memory);
-       LLVMValueRef glc = (cache_policy & ac_glc) ? ctx->ac.i1true : ctx->ac.i1false;
 
        LLVMValueRef rsrc = ctx->abi->load_ssbo(ctx->abi,
                                        get_src(ctx, instr->src[1]), true);
@@ -1573,25 +1571,10 @@ static void visit_store_ssbo(struct ac_nir_context *ctx,
                                      LLVMConstInt(ctx->ac.i32, start * elem_size_bytes, false), "");
 
                if (num_bytes == 2) {
-                       store_name = "llvm.amdgcn.tbuffer.store.i32";
-                       data_type = ctx->ac.i32;
-                       data = LLVMBuildBitCast(ctx->ac.builder, data, ctx->ac.i16, "");
-                       data = LLVMBuildZExt(ctx->ac.builder, data, data_type, "");
-                       LLVMValueRef tbuffer_params[] = {
-                               data,
-                               rsrc,
-                               ctx->ac.i32_0, /* vindex */
-                               offset,        /* voffset */
-                               ctx->ac.i32_0,
-                               ctx->ac.i32_0,
-                               LLVMConstInt(ctx->ac.i32, 2, false), // dfmt (= 16bit)
-                               LLVMConstInt(ctx->ac.i32, 4, false), // nfmt (= uint)
-                               glc,
-                               ctx->ac.i1false,
-                       };
-                       ac_build_intrinsic(&ctx->ac, store_name,
-                                          ctx->ac.voidt, tbuffer_params, 10,
-                                          ac_get_store_intr_attribs(writeonly_memory));
+                       ac_build_tbuffer_store_short(&ctx->ac, rsrc, data,
+                                                    offset, ctx->ac.i32_0,
+                                                    cache_policy & ac_glc,
+                                                    writeonly_memory);
                } else {
                        int num_channels = num_bytes / 4;