[llvm] [LV] Fix crash when vectorizing function calls with linear args. (PR #76274)
Alexandros Lamprineas via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 22 15:16:07 PST 2023
https://github.com/labrinea created https://github.com/llvm/llvm-project/pull/76274
llvm/lib/IR/Type.cpp:694:
Assertion `isValidElementType(ElementType) && "Element type of a
VectorType must be an integer, floating point, or pointer type."'
failed.
Stack dump:
llvm::FixedVectorType::get(llvm::Type*, unsigned int)
llvm::VPWidenCallRecipe::execute(llvm::VPTransformState&)
llvm::VPBasicBlock::execute(llvm::VPTransformState*)
llvm::VPRegionBlock::execute(llvm::VPTransformState*)
llvm::VPlan::execute(llvm::VPTransformState*)
...
Happens with function calls of void return type.
>From d919a650a5d6a5ba072b932a3d1b10e0ba12ddda Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas <alexandros.lamprineas at arm.com>
Date: Fri, 22 Dec 2023 22:54:46 +0000
Subject: [PATCH] [LV] Fix crash when vectorizing function calls with linear
args.
llvm/lib/IR/Type.cpp:694:
Assertion `isValidElementType(ElementType) && "Element type of a
VectorType must be an integer, floating point, or pointer type."'
failed.
Stack dump:
llvm::FixedVectorType::get(llvm::Type*, unsigned int)
llvm::VPWidenCallRecipe::execute(llvm::VPTransformState&)
llvm::VPBasicBlock::execute(llvm::VPTransformState*)
llvm::VPRegionBlock::execute(llvm::VPTransformState*)
llvm::VPlan::execute(llvm::VPTransformState*)
...
Happens with function calls of void return type.
---
.../lib/Transforms/Vectorize/VPlanRecipes.cpp | 3 +-
.../LoopVectorize/vector-call-linear-args.ll | 31 +++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Transforms/LoopVectorize/vector-call-linear-args.ll
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 02e400d590bed4..1ca9556adad6ac 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -504,7 +504,8 @@ void VPWidenCallRecipe::execute(VPTransformState &State) {
for (unsigned Part = 0; Part < State.UF; ++Part) {
SmallVector<Type *, 2> TysForDecl;
// Add return type if intrinsic is overloaded on it.
- if (isVectorIntrinsicWithOverloadTypeAtArg(VectorIntrinsicID, -1)) {
+ if (isVectorIntrinsicWithOverloadTypeAtArg(VectorIntrinsicID, -1) &&
+ VectorIntrinsicID != Intrinsic::not_intrinsic) {
TysForDecl.push_back(
VectorType::get(CI.getType()->getScalarType(), State.VF));
}
diff --git a/llvm/test/Transforms/LoopVectorize/vector-call-linear-args.ll b/llvm/test/Transforms/LoopVectorize/vector-call-linear-args.ll
new file mode 100644
index 00000000000000..e84326d5d402aa
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/vector-call-linear-args.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --filter "call.*foo" --version 4
+; RUN: opt -passes=loop-vectorize,simplifycfg -force-vector-interleave=1 -force-vector-width=2 -S < %s | FileCheck %s
+
+; Make sure the vectorizer does not crash.
+
+define void @test_foo(ptr noalias %in, ptr noalias %out) {
+; CHECK-LABEL: define void @test_foo(
+; CHECK-SAME: ptr noalias [[IN:%.*]], ptr noalias [[OUT:%.*]]) {
+; CHECK: call void @vec_foo(<2 x i64> [[WIDE_LOAD:%.*]], ptr [[TMP4:%.*]])
+;
+entry:
+ br label %for.body
+
+for.body:
+ %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+ %gep.in = getelementptr i64, ptr %in, i64 %indvars.iv
+ %num = load i64, ptr %gep.in, align 8
+ %gep.out = getelementptr i64, ptr %out, i64 %indvars.iv
+ call void @foo(i64 %num, ptr %gep.out) #0
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+ %exitcond = icmp eq i64 %indvars.iv.next, 1000
+ br i1 %exitcond, label %for.cond.cleanup, label %for.body
+
+for.cond.cleanup:
+ ret void
+}
+
+declare void @foo(i64, ptr)
+declare void @vec_foo(<2 x i64>, ptr)
+
+attributes #0 = { "vector-function-abi-variant"="_ZGV_LLVM_N2vl8_foo(vec_foo)" }
More information about the llvm-commits
mailing list