[llvm] [IR] Change getParamIndexForOptionalMask to assume masked parameter is last (PR #180558)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 9 08:54:57 PST 2026
https://github.com/david-arm created https://github.com/llvm/llvm-project/pull/180558
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.
>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] [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
More information about the llvm-commits
mailing list