From 0cbf442ebd6c0649be2406ecd7941884e1968ac5 Mon Sep 17 00:00:00 2001 From: Zalman Stern Date: Fri, 23 Sep 2022 17:16:33 -0700 Subject: [PATCH] Allow call_intrin to call an LLVM intrinsic with void return type. (#7048) Have ```CodeGen_LLVM::get_vector_type``` return the void type if passed the void type as a scalar base. This makes it possible to call intrinsics returning void via ```CodeGenn_LLVM::call_intrin```. Should be very safe as currently this anything doing this would fail inside the routine. The change breaks the invariant that any thing returned from get_vector_type is a vector type, but propagating void for function return types is a pretty standard behavior and if this was not intended, it will very likely fail just outside this instead of having failed inside the use. I.e. very low chance of spurious errors from this. --- src/CodeGen_LLVM.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index 9721a1c2ad80..ff1bd682aca0 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -4528,7 +4528,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->isVoidTy()) { + arg_lanes = intrin_lanes; + } else if (result_type->isVectorTy()) { arg_lanes = get_vector_num_elements(result_type); } @@ -4913,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 &&