[llvm] [IR] Change getParamIndexForOptionalMask to assume masked parameter is last (PR #180558)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 02:18:27 PST 2026
https://github.com/david-arm updated https://github.com/llvm/llvm-project/pull/180558
>From eb476e16baa583ab53e085cdf55edaa2bb383865 Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Mon, 9 Feb 2026 16:52:46 +0000
Subject: [PATCH 1/2] [IR] Change getParamIndexForOptionalMask to assume masked
parameter is last
At the moment all code in LLVM seems to explicitly assume that the masked
parameter passed to vector math functions always lives at the end of the
parameter list. See VFShape::get as an example. It seems odd then for
getParamIndexForOptionalMask to walk the parameter list looking for the
mask. Indeed, the loop vectoriser would break if the mask was passed in
any other argument position. For example, if the masked parameter
position was 1 for a vector version of powf it would end up over-writing
the exponent.
---
llvm/include/llvm/IR/VFABIDemangler.h | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/IR/VFABIDemangler.h b/llvm/include/llvm/IR/VFABIDemangler.h
index 0b287987665ec..b4aa4c47877bb 100644
--- a/llvm/include/llvm/IR/VFABIDemangler.h
+++ b/llvm/include/llvm/IR/VFABIDemangler.h
@@ -132,11 +132,10 @@ struct VFInfo {
/// if any exist.
std::optional<unsigned> getParamIndexForOptionalMask() const {
unsigned ParamCount = Shape.Parameters.size();
- for (unsigned i = 0; i < ParamCount; ++i)
- if (Shape.Parameters[i].ParamKind == VFParamKind::GlobalPredicate)
- return i;
-
- return std::nullopt;
+ if (!ParamCount || Shape.Parameters[ParamCount - 1].ParamKind !=
+ VFParamKind::GlobalPredicate)
+ return std::nullopt;
+ return ParamCount - 1;
}
/// Returns true if at least one of the operands to the vectorized function
>From 11879fdf2590ff7a73d36d23f33625e839e48ebe Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Tue, 10 Feb 2026 10:15:04 +0000
Subject: [PATCH 2/2] Address review comment
---
llvm/include/llvm/IR/VFABIDemangler.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/llvm/include/llvm/IR/VFABIDemangler.h b/llvm/include/llvm/IR/VFABIDemangler.h
index b4aa4c47877bb..f5ef20103804f 100644
--- a/llvm/include/llvm/IR/VFABIDemangler.h
+++ b/llvm/include/llvm/IR/VFABIDemangler.h
@@ -132,6 +132,20 @@ struct VFInfo {
/// if any exist.
std::optional<unsigned> getParamIndexForOptionalMask() const {
unsigned ParamCount = Shape.Parameters.size();
+
+#ifndef NDEBUG
+ unsigned NumMaskParams = 0, MaskIdx = 0;
+ for (unsigned I = 0; I < ParamCount; I++) {
+ if (Shape.Parameters[I].ParamKind == VFParamKind::GlobalPredicate) {
+ NumMaskParams++;
+ MaskIdx = I;
+ }
+ }
+ assert(NumMaskParams <= 1 && "Unexpected number of mask parameters");
+ assert((!NumMaskParams || MaskIdx == (ParamCount - 1)) &&
+ "Mask parameter in unexpected position");
+#endif
+
if (!ParamCount || Shape.Parameters[ParamCount - 1].ParamKind !=
VFParamKind::GlobalPredicate)
return std::nullopt;
More information about the llvm-commits
mailing list