[llvm] [CodeGen] ReplaceWithVeclib assertion failure with invalid intrinsic (PR #211352)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 22 11:58:36 PDT 2026
https://github.com/rlougher created https://github.com/llvm/llvm-project/pull/211352
Commit f6a359f (#194639) removed an intrinsic ID check against Intrinsic::not_intrinsic.
This check is needed because a call instruction can be cast to an intrinsic instruction if the called function's name starts with "llvm." (see llvm::Function::isIntrinsic).
This means if ReplaceWithVeclib is given an invalid intrinsic, it will fail with an assertion failure.
>From 6f61b855e9299866355c2cd4cbd9a782d5b09667 Mon Sep 17 00:00:00 2001
From: Robert Lougher <robert.lougher at sony.com>
Date: Wed, 22 Jul 2026 19:38:32 +0100
Subject: [PATCH] [CodeGen] ReplaceWithVeclib assertion failure with invalid
intrinsic
Commit f6a359f (#194639) removed an intrinsic ID check against
Intrinsic::not_intrinsic.
This check is needed because a call instruction can be cast to an
intrinsic instruction if the called function's name starts with "llvm."
(see llvm::Function::isIntrinsic).
This means if ReplaceWithVeclib is given an invalid intrinsic, it will
fail with an assertion failure.
---
llvm/lib/CodeGen/ReplaceWithVeclib.cpp | 2 +-
llvm/test/CodeGen/X86/veclib-invalid-intrinsic.ll | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/X86/veclib-invalid-intrinsic.ll
diff --git a/llvm/lib/CodeGen/ReplaceWithVeclib.cpp b/llvm/lib/CodeGen/ReplaceWithVeclib.cpp
index 4a240c914a252..c2a7835504e67 100644
--- a/llvm/lib/CodeGen/ReplaceWithVeclib.cpp
+++ b/llvm/lib/CodeGen/ReplaceWithVeclib.cpp
@@ -300,7 +300,7 @@ static bool runImpl(const TargetLibraryInfo &TLI, Function &F) {
SmallVector<Instruction *> ReplacedCalls;
for (auto &I : instructions(F)) {
auto *II = dyn_cast<IntrinsicInst>(&I);
- if (!II)
+ if (!II || II->getIntrinsicID() == Intrinsic::not_intrinsic)
continue;
// Vector llvm.sincos returns a struct so it does not fit the generic
diff --git a/llvm/test/CodeGen/X86/veclib-invalid-intrinsic.ll b/llvm/test/CodeGen/X86/veclib-invalid-intrinsic.ll
new file mode 100644
index 0000000000000..59fa43d37a3a8
--- /dev/null
+++ b/llvm/test/CodeGen/X86/veclib-invalid-intrinsic.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -mtriple=x86_64-unknown-linux-gnu -passes=replace-with-veclib -S < %s | FileCheck %s
+
+declare <4 x float> @llvm.invalid.intrinsic(<4 x float>)
+
+define <4 x float> @test(<4 x float> %v) {
+; CHECK-LABEL: define <4 x float> @test(
+; CHECK-SAME: <4 x float> [[V:%.*]]) {
+; CHECK-NEXT: [[R:%.*]] = call <4 x float> @llvm.invalid.intrinsic(<4 x float> [[V]])
+; CHECK-NEXT: ret <4 x float> [[R]]
+;
+ %r = call <4 x float> @llvm.invalid.intrinsic(<4 x float> %v)
+ ret <4 x float> %r
+}
More information about the llvm-commits
mailing list