From a333f3b339b6971759609424a6fd59244d50a8ee Mon Sep 17 00:00:00 2001 From: Z Stern Date: Fri, 23 Sep 2022 21:21:02 +0000 Subject: [PATCH 1/4] Make it possible to call intrinsics returning void via CodeGenn_LLVM::call_intrin. --- src/CodeGen_LLVM.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index 9721a1c2ad80..5b95ad6b889f 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -4508,7 +4508,9 @@ Value *CodeGen_LLVM::call_intrin(const llvm::Type *result_type, int intrin_lanes llvm::Type *intrinsic_result_type = result_type->getScalarType(); if (intrin_lanes > 1) { - if (scalable_vector_result && effective_vscale != 0) { + if (result_type == void_t) { + intrinsic_result_type = void_t; + } else if (scalable_vector_result && effective_vscale != 0) { intrinsic_result_type = get_vector_type(result_type->getScalarType(), intrin_lanes / effective_vscale, VectorTypeConstraint::VScale); } else { @@ -4528,7 +4530,9 @@ Value *CodeGen_LLVM::call_intrin(const llvm::Type *result_type, int intrin_lanes llvm::Function *intrin, vector arg_values) { internal_assert(intrin); int arg_lanes = 1; - if (result_type->isVectorTy()) { + if (result_type == void_t) { + arg_lanes = intrin_lanes; + } else if (result_type->isVectorTy()) { arg_lanes = get_vector_num_elements(result_type); } @@ -4567,7 +4571,7 @@ Value *CodeGen_LLVM::call_intrin(const llvm::Type *result_type, int intrin_lanes } } - llvm::Type *result_slice_type = + llvm::Type *result_slice_type = (result_type == void_t) ? void_t : get_vector_type(result_type->getScalarType(), intrin_lanes); results.push_back(call_intrin(result_slice_type, intrin_lanes, intrin, args)); From cf78c8579b7ee4001f232ef0c78bc04adb65044a Mon Sep 17 00:00:00 2001 From: Z Stern Date: Fri, 23 Sep 2022 23:43:16 +0000 Subject: [PATCH 2/4] Handle case by making get_vector_type always return a void type if passed one as the scalar base type. --- src/CodeGen_LLVM.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index 5b95ad6b889f..6e5cf89fbb0f 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -4508,9 +4508,7 @@ Value *CodeGen_LLVM::call_intrin(const llvm::Type *result_type, int intrin_lanes llvm::Type *intrinsic_result_type = result_type->getScalarType(); if (intrin_lanes > 1) { - if (result_type == void_t) { - intrinsic_result_type = void_t; - } else if (scalable_vector_result && effective_vscale != 0) { + if (scalable_vector_result && effective_vscale != 0) { intrinsic_result_type = get_vector_type(result_type->getScalarType(), intrin_lanes / effective_vscale, VectorTypeConstraint::VScale); } else { @@ -4571,7 +4569,7 @@ Value *CodeGen_LLVM::call_intrin(const llvm::Type *result_type, int intrin_lanes } } - llvm::Type *result_slice_type = (result_type == void_t) ? void_t : + llvm::Type *result_slice_type = get_vector_type(result_type->getScalarType(), intrin_lanes); results.push_back(call_intrin(result_slice_type, intrin_lanes, intrin, args)); @@ -4917,6 +4915,10 @@ llvm::Type *CodeGen_LLVM::get_vector_type(llvm::Type *t, int n, VectorTypeConstraint type_constraint) const { bool scalable; + if (t->isVoidTy()) { + return t; + } + switch (type_constraint) { case VectorTypeConstraint::None: scalable = effective_vscale != 0 && From 3ded27980aa9d47a21cf0f4576aa6264d26fc225 Mon Sep 17 00:00:00 2001 From: Z Stern Date: Fri, 23 Sep 2022 23:46:32 +0000 Subject: [PATCH 3/4] Test for void type in a consistent fashion. --- src/CodeGen_LLVM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index 6e5cf89fbb0f..ed380ef8626b 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -4528,7 +4528,7 @@ Value *CodeGen_LLVM::call_intrin(const llvm::Type *result_type, int intrin_lanes llvm::Function *intrin, vector arg_values) { internal_assert(intrin); int arg_lanes = 1; - if (result_type == void_t) { + if (result_type->isVoidTy()) { arg_lanes = intrin_lanes; } else if (result_type->isVectorTy()) { arg_lanes = get_vector_num_elements(result_type); From fb96bef332a5f517ccda361a188497366ed0ae55 Mon Sep 17 00:00:00 2001 From: Z Stern Date: Fri, 23 Sep 2022 23:48:24 +0000 Subject: [PATCH 4/4] Formatting. --- src/CodeGen_LLVM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index ed380ef8626b..ff1bd682aca0 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -4918,7 +4918,7 @@ llvm::Type *CodeGen_LLVM::get_vector_type(llvm::Type *t, int n, if (t->isVoidTy()) { return t; } - + switch (type_constraint) { case VectorTypeConstraint::None: scalable = effective_vscale != 0 &&