ac: add 8-bit and 16-bit supports to ac_build_optimization_barrier()
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 8 Nov 2019 16:12:39 +0000 (17:12 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 19 Nov 2019 18:01:13 +0000 (18:01 +0000)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/llvm/ac_llvm_build.c

index b397f3461de0adf0d943a0eece7038ab5ce57d5c..d97dd36480a9afd1836402f10210d277fbeedd88 100644 (file)
@@ -432,11 +432,19 @@ ac_build_optimization_barrier(struct ac_llvm_context *ctx,
        } else {
                LLVMTypeRef ftype = LLVMFunctionType(ctx->i32, &ctx->i32, 1, false);
                LLVMValueRef inlineasm = LLVMConstInlineAsm(ftype, code, "=v,0", true, false);
+               LLVMTypeRef type = LLVMTypeOf(*pvgpr);
+               unsigned bitsize = ac_get_elem_bits(ctx, type);
                LLVMValueRef vgpr = *pvgpr;
-               LLVMTypeRef vgpr_type = LLVMTypeOf(vgpr);
-               unsigned vgpr_size = ac_get_type_size(vgpr_type);
+               LLVMTypeRef vgpr_type;
+               unsigned vgpr_size;
                LLVMValueRef vgpr0;
 
+               if (bitsize < 32)
+                       vgpr = LLVMBuildZExt(ctx->builder, vgpr, ctx->i32, "");
+
+               vgpr_type = LLVMTypeOf(vgpr);
+               vgpr_size = ac_get_type_size(vgpr_type);
+
                assert(vgpr_size % 4 == 0);
 
                vgpr = LLVMBuildBitCast(builder, vgpr, LLVMVectorType(ctx->i32, vgpr_size / 4), "");
@@ -445,6 +453,9 @@ ac_build_optimization_barrier(struct ac_llvm_context *ctx,
                vgpr = LLVMBuildInsertElement(builder, vgpr, vgpr0, ctx->i32_0, "");
                vgpr = LLVMBuildBitCast(builder, vgpr, vgpr_type, "");
 
+               if (bitsize < 32)
+                       vgpr = LLVMBuildTrunc(builder, vgpr, type, "");
+
                *pvgpr = vgpr;
        }
 }