[Mesa-dev] [PATCH] ac: fix 16-bit shifts
Bas Nieuwenhuizen
bas at basnieuwenhuizen.nl
Thu Mar 21 11:10:58 UTC 2019
On Thu, Mar 21, 2019 at 11:59 AM Samuel Pitoiset
<samuel.pitoiset at gmail.com> wrote:
>
> This fixes the following LLVM error when ckeckir is set:
> Type too small for ZExt
>
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
> ---
> src/amd/common/ac_nir_to_llvm.c | 33 +++++++++++++++++++++------------
> 1 file changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
> index 3681c07c364..925073efb85 100644
> --- a/src/amd/common/ac_nir_to_llvm.c
> +++ b/src/amd/common/ac_nir_to_llvm.c
> @@ -671,22 +671,31 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
> result = LLVMBuildXor(ctx->ac.builder, src[0], src[1], "");
> break;
> case nir_op_ishl:
> - result = LLVMBuildShl(ctx->ac.builder, src[0],
> - LLVMBuildZExt(ctx->ac.builder, src[1],
> - LLVMTypeOf(src[0]), ""),
> - "");
> + if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[1])) < ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])))
> + src[1] = LLVMBuildZExt(ctx->ac.builder, src[1],
> + LLVMTypeOf(src[0]), "");
> + else
Maybe make this an "else if" with the reverse check so we don't do
anything in the == case, for all three instructions?
Otherwise, r-b
> + src[1] = LLVMBuildTrunc(ctx->ac.builder, src[1],
> + LLVMTypeOf(src[0]), "");
> + result = LLVMBuildShl(ctx->ac.builder, src[0], src[1], "");
> break;
> case nir_op_ishr:
> - result = LLVMBuildAShr(ctx->ac.builder, src[0],
> - LLVMBuildZExt(ctx->ac.builder, src[1],
> - LLVMTypeOf(src[0]), ""),
> - "");
> + if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[1])) < ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])))
> + src[1] = LLVMBuildZExt(ctx->ac.builder, src[1],
> + LLVMTypeOf(src[0]), "");
> + else
> + src[1] = LLVMBuildTrunc(ctx->ac.builder, src[1],
> + LLVMTypeOf(src[0]), "");
> + result = LLVMBuildAShr(ctx->ac.builder, src[0], src[1], "");
> break;
> case nir_op_ushr:
> - result = LLVMBuildLShr(ctx->ac.builder, src[0],
> - LLVMBuildZExt(ctx->ac.builder, src[1],
> - LLVMTypeOf(src[0]), ""),
> - "");
> + if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[1])) < ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])))
> + src[1] = LLVMBuildZExt(ctx->ac.builder, src[1],
> + LLVMTypeOf(src[0]), "");
> + else
> + src[1] = LLVMBuildTrunc(ctx->ac.builder, src[1],
> + LLVMTypeOf(src[0]), "");
> + result = LLVMBuildLShr(ctx->ac.builder, src[0], src[1], "");
> break;
> case nir_op_ilt32:
> result = emit_int_cmp(&ctx->ac, LLVMIntSLT, src[0], src[1]);
> --
> 2.21.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list