ac: fix 16-bit shifts
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 21 Mar 2019 10:59:37 +0000 (11:59 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 21 Mar 2019 13:01:58 +0000 (14:01 +0100)
This fixes the following LLVM error when ckeckir is set:
Type too small for ZExt

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

index 82def9ab20f8d1fd4defcf45f85b87bb6a078b81..37ef50fabaf3905b9a684217b04a4bf91ec81d0b 100644 (file)
@@ -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 if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[1])) > ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])))
+                       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 if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[1])) > ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])))
+                       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 if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[1])) > ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])))
+                       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]);