llvmpipe: add missing NIR alu-op handling
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Wed, 6 Oct 2021 12:50:09 +0000 (14:50 +0200)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Thu, 4 Nov 2021 12:59:00 +0000 (13:59 +0100)
nir_op_bcsel implemented based on ac_nir_to_llvm.c emit_bcsel function.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13246>

src/gallium/auxiliary/gallivm/lp_bld_nir.c

index ca56330..6dbb840 100644 (file)
@@ -719,6 +719,7 @@ static LLVMValueRef do_alu_action(struct lp_build_nir_context *bld_base,
       result = lp_build_sub(flt_bld, src[0], tmp);
       break;
    }
+   case nir_op_fge:
    case nir_op_fge32:
       result = fcmp32(bld_base, PIPE_FUNC_GEQUAL, src_bit_size[0], src);
       break;
@@ -1044,6 +1045,26 @@ static LLVMValueRef do_alu_action(struct lp_build_nir_context *bld_base,
       result = lp_build_shr(uint_bld, src[0], src[1]);
       break;
    }
+   case nir_op_bcsel: {
+      LLVMTypeRef src1_type = LLVMTypeOf(src[1]);
+      LLVMTypeRef src2_type = LLVMTypeOf(src[2]);
+
+      if (LLVMGetTypeKind(src1_type) == LLVMPointerTypeKind &&
+          LLVMGetTypeKind(src2_type) != LLVMPointerTypeKind) {
+         src[2] = LLVMBuildIntToPtr(builder, src[2], src1_type, "");
+      } else if (LLVMGetTypeKind(src2_type) == LLVMPointerTypeKind &&
+                 LLVMGetTypeKind(src1_type) != LLVMPointerTypeKind) {
+         src[1] = LLVMBuildIntToPtr(builder, src[1], src2_type, "");
+      }
+
+      for (int i = 1; i <= 2; i++) {
+         LLVMTypeRef type = LLVMTypeOf(src[i]);
+         if (LLVMGetTypeKind(type) == LLVMPointerTypeKind)
+            break;
+         src[i] = LLVMBuildBitCast(builder, src[i], get_int_bld(bld_base, true, src_bit_size[i])->vec_type, "");
+      }
+      return LLVMBuildSelect(builder, src[0], src[1], src[2], "");
+   }
    default:
       assert(0);
       break;