[llvm] [Intrinsics]Handle invalid return type gracefully instead of crashing (PR #177103)
Kshitij Paranjape via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 20 23:19:18 PST 2026
https://github.com/kshitijvp updated https://github.com/llvm/llvm-project/pull/177103
>From ceb44e483d85a61f3239f818116e031d24c15924 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Wed, 21 Jan 2026 12:05:26 +0530
Subject: [PATCH 1/3] Handle invalid return type gracefully instead of crashing
When an invalid return type is passed to llvm.aarch64.neon.smull
intrinsic it must gracefully reject the invalid return type.
However for Vector types with odd bit-widths this results in a
assertion failure as the getTruncatedElementVectorType() function
asserts the bit-width to be only even using the EltBits & 1 == 0
condition. Add checks to ensure that getTruncatedElementVectorType()
doesn't get called with odd bit-width vector types.
---
llvm/lib/IR/Intrinsics.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index f46d3e5063e43..19fdd43cdd2af 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -965,8 +965,12 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
return IsDeferredCheck || DeferCheck(Ty);
Type *NewTy = ArgTys[D.getArgumentNumber()];
- if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
- NewTy = VectorType::getTruncatedElementVectorType(VTy);
+ if (VectorType *VTy = dyn_cast<VectorType>(NewTy)) {
+ unsigned EltBits =
+ VTy->getElementType()->getPrimitiveSizeInBits().getFixedValue();
+ if (EltBits & 1 == 0)
+ NewTy = VectorType::getTruncatedElementVectorType(VTy);
+ }
else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
else
>From 9db9711baa14efeba74433a37d8a61235bcda5da Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Wed, 21 Jan 2026 12:21:34 +0530
Subject: [PATCH 2/3] Nitpick
---
llvm/lib/IR/Intrinsics.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index 19fdd43cdd2af..adb2bd6673654 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -970,8 +970,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
VTy->getElementType()->getPrimitiveSizeInBits().getFixedValue();
if (EltBits & 1 == 0)
NewTy = VectorType::getTruncatedElementVectorType(VTy);
- }
- else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
+ } else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
else
return true;
>From 4b681b8bb9da721c5251f10598db542af73559b0 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Wed, 21 Jan 2026 12:49:05 +0530
Subject: [PATCH 3/3] Add parantheses
---
llvm/lib/IR/Intrinsics.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index adb2bd6673654..c338d3b2a53f1 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -968,7 +968,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
if (VectorType *VTy = dyn_cast<VectorType>(NewTy)) {
unsigned EltBits =
VTy->getElementType()->getPrimitiveSizeInBits().getFixedValue();
- if (EltBits & 1 == 0)
+ if ((EltBits & 1) == 0)
NewTy = VectorType::getTruncatedElementVectorType(VTy);
} else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
More information about the llvm-commits
mailing list