ac,radeonsi: use ac_build_gather_values more
authorMarek Olšák <marek.olsak@amd.com>
Thu, 16 Aug 2018 01:06:54 +0000 (21:06 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 22 Aug 2018 00:50:37 +0000 (20:50 -0400)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/common/ac_nir_to_llvm.c
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c

index 537ac33c0444095489f24e890cdb2818e1b4f41c..700e48e14b7afadc51f19254457b6bde18f9152b 100644 (file)
@@ -486,7 +486,7 @@ static LLVMValueRef emit_unpack_half_2x16(struct ac_llvm_context *ctx,
                                          LLVMValueRef src0)
 {
        LLVMValueRef const16 = LLVMConstInt(ctx->i32, 16, false);
-       LLVMValueRef temps[2], result, val;
+       LLVMValueRef temps[2], val;
        int i;
 
        for (i = 0; i < 2; i++) {
@@ -495,12 +495,7 @@ static LLVMValueRef emit_unpack_half_2x16(struct ac_llvm_context *ctx,
                val = LLVMBuildBitCast(ctx->builder, val, ctx->f16, "");
                temps[i] = LLVMBuildFPExt(ctx->builder, val, ctx->f32, "");
        }
-
-       result = LLVMBuildInsertElement(ctx->builder, LLVMGetUndef(ctx->v2f32), temps[0],
-                                       ctx->i32_0, "");
-       result = LLVMBuildInsertElement(ctx->builder, result, temps[1],
-                                       ctx->i32_1, "");
-       return result;
+       return ac_build_gather_values(ctx, temps, 2);
 }
 
 static LLVMValueRef emit_ddxy(struct ac_nir_context *ctx,
@@ -1004,10 +999,7 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
 
        case nir_op_pack_64_2x32_split: {
                LLVMValueRef tmp = LLVMGetUndef(ctx->ac.v2i32);
-               tmp = LLVMBuildInsertElement(ctx->ac.builder, tmp,
-                                            src[0], ctx->ac.i32_0, "");
-               tmp = LLVMBuildInsertElement(ctx->ac.builder, tmp,
-                                            src[1], ctx->ac.i32_1, "");
+               tmp = ac_build_gather_values(&ctx->ac, src, 2);
                result = LLVMBuildBitCast(ctx->ac.builder, tmp, ctx->ac.i64, "");
                break;
        }
index 66fe5fad2185a52f1571bef593f2d6144365d588..cfd99b61601bb5ad522c7b4d5d8bec2ca38839c2 100644 (file)
@@ -2724,12 +2724,10 @@ static void emit_streamout_output(struct si_shader_context *ctx,
                break;
        case 2: /* as v2i32 */
        case 3: /* as v4i32 (aligned to 4) */
+               out[3] = LLVMGetUndef(ctx->i32);
+               /* fall through */
        case 4: /* as v4i32 */
-               vdata = LLVMGetUndef(LLVMVectorType(ctx->i32, util_next_power_of_two(num_comps)));
-               for (int j = 0; j < num_comps; j++) {
-                       vdata = LLVMBuildInsertElement(ctx->ac.builder, vdata, out[j],
-                                                      LLVMConstInt(ctx->i32, j, 0), "");
-               }
+               vdata = ac_build_gather_values(&ctx->ac, out, util_next_power_of_two(num_comps));
                break;
        }
 
index 54a0413e4642cc935d43a14c6ecbf5476b1f066b..8e0578b4d5e1d5a9367cf84800828390f2885e95 100644 (file)
@@ -553,7 +553,7 @@ static void store_emit_buffer(struct si_shader_context *ctx,
        while (writemask) {
                int start, count;
                const char *intrinsic_name;
-               LLVMValueRef data, voff, tmp;
+               LLVMValueRef data, voff;
 
                u_bit_scan_consecutive_range(&writemask, &start, &count);
 
@@ -568,21 +568,14 @@ static void store_emit_buffer(struct si_shader_context *ctx,
                        data = base_data;
                        intrinsic_name = "llvm.amdgcn.buffer.store.v4f32";
                } else if (count == 2) {
-                       LLVMTypeRef v2f32 = LLVMVectorType(ctx->f32, 2);
-
-                       tmp = LLVMBuildExtractElement(
-                               builder, base_data,
-                               LLVMConstInt(ctx->i32, start, 0), "");
-                       data = LLVMBuildInsertElement(
-                               builder, LLVMGetUndef(v2f32), tmp,
-                               ctx->i32_0, "");
-
-                       tmp = LLVMBuildExtractElement(
-                               builder, base_data,
-                               LLVMConstInt(ctx->i32, start + 1, 0), "");
-                       data = LLVMBuildInsertElement(
-                               builder, data, tmp, ctx->i32_1, "");
-
+                       LLVMValueRef values[2] = {
+                               LLVMBuildExtractElement(builder, base_data,
+                                                       LLVMConstInt(ctx->i32, start, 0), ""),
+                               LLVMBuildExtractElement(builder, base_data,
+                                                       LLVMConstInt(ctx->i32, start + 1, 0), ""),
+                       };
+
+                       data = ac_build_gather_values(&ctx->ac, values, 2);
                        intrinsic_name = "llvm.amdgcn.buffer.store.v2f32";
                } else {
                        assert(count == 1);
index 1f37b0ba37d6712c8da8c66585d10e0c836e7d59..20164939cb762d5ea39468d503d4774920c3ffe8 100644 (file)
@@ -305,18 +305,11 @@ si_llvm_emit_fetch_64bit(struct lp_build_tgsi_context *bld_base,
                         LLVMValueRef ptr2)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
-       LLVMValueRef result;
-
-       result = LLVMGetUndef(LLVMVectorType(ctx->i32, 2));
-
-       result = LLVMBuildInsertElement(ctx->ac.builder,
-                                       result,
-                                       ac_to_integer(&ctx->ac, ptr),
-                                       ctx->i32_0, "");
-       result = LLVMBuildInsertElement(ctx->ac.builder,
-                                       result,
-                                       ac_to_integer(&ctx->ac, ptr2),
-                                       ctx->i32_1, "");
+       LLVMValueRef values[2] = {
+               ac_to_integer(&ctx->ac, ptr),
+               ac_to_integer(&ctx->ac, ptr2),
+       };
+       LLVMValueRef result = ac_build_gather_values(&ctx->ac, values, 2);
        return LLVMBuildBitCast(ctx->ac.builder, result, type, "");
 }