Maybe just zero-extend the 32-bit value? (or truncate for 16-bit?) I
don't know what generates better machinecode.

On Fri, Jan 12, 2018 at 2:34 AM, Timothy Arceri <tarc...@itsqueeze.com> wrote:
> ---
>
>  Open to suggestions for better ways to do this.
>
>  src/amd/common/ac_nir_to_llvm.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
> index b0a8a94a2d..f013b4b387 100644
> --- a/src/amd/common/ac_nir_to_llvm.c
> +++ b/src/amd/common/ac_nir_to_llvm.c
> @@ -1422,9 +1422,16 @@ static LLVMValueRef emit_f2b(struct ac_llvm_context 
> *ctx,
>  }
>
>  static LLVMValueRef emit_b2i(struct ac_llvm_context *ctx,
> -                            LLVMValueRef src0)
> +                            LLVMValueRef src0,
> +                            unsigned bitsize)
>  {
> -       return LLVMBuildAnd(ctx->builder, src0, ctx->i32_1, "");
> +       LLVMValueRef result = LLVMBuildAnd(ctx->builder, src0, ctx->i32_1, 
> "");
> +
> +       if (bitsize == 32)
> +               return result;
> +
> +       LLVMValueRef icond = LLVMBuildICmp(ctx->builder, LLVMIntEQ, result, 
> ctx->i32_1, "");
> +       return LLVMBuildSelect(ctx->builder, icond, ctx->i64_1, ctx->i64_0, 
> "");
>  }
>
>  static LLVMValueRef emit_i2b(struct ac_llvm_context *ctx,
> @@ -1979,7 +1986,7 @@ static void visit_alu(struct ac_nir_context *ctx, const 
> nir_alu_instr *instr)
>                 result = emit_f2b(&ctx->ac, src[0]);
>                 break;
>         case nir_op_b2i:
> -               result = emit_b2i(&ctx->ac, src[0]);
> +               result = emit_b2i(&ctx->ac, src[0], 
> instr->dest.dest.ssa.bit_size);
>                 break;
>         case nir_op_i2b:
>                 src[0] = ac_to_integer(&ctx->ac, src[0]);
> --
> 2.14.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to