[llvm] 8a2255f - [IR] Change getParamIndexForOptionalMask to assume masked parameter is last (#180558)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 12 06:37:00 PST 2026


Author: David Sherwood
Date: 2026-02-12T14:36:55Z
New Revision: 8a2255fc420621e7a4bfa4ebce50a58c0fb99cf5

URL: https://github.com/llvm/llvm-project/commit/8a2255fc420621e7a4bfa4ebce50a58c0fb99cf5
DIFF: https://github.com/llvm/llvm-project/commit/8a2255fc420621e7a4bfa4ebce50a58c0fb99cf5.diff

LOG: [IR] Change getParamIndexForOptionalMask to assume masked parameter is last (#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.

Added: 
    

Modified: 
    llvm/include/llvm/IR/VFABIDemangler.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/VFABIDemangler.h b/llvm/include/llvm/IR/VFABIDemangler.h
index 0b287987665ec..7576b0f706eb3 100644
--- a/llvm/include/llvm/IR/VFABIDemangler.h
+++ b/llvm/include/llvm/IR/VFABIDemangler.h
@@ -132,11 +132,22 @@ 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;
+#ifndef NDEBUG
+    unsigned NumMaskParams =
+        llvm::count_if(Shape.Parameters, [](const VFParameter &I) {
+          return I.ParamKind == VFParamKind::GlobalPredicate;
+        });
+    assert(NumMaskParams <= 1 && "Unexpected number of mask parameters");
+    assert((!NumMaskParams || Shape.Parameters[ParamCount - 1].ParamKind ==
+                                  VFParamKind::GlobalPredicate) &&
+           "Mask parameter in unexpected position");
+#endif
+
+    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