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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 12 04:42:40 PST 2026


================
@@ -132,11 +132,24 @@ 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 = 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
----------------
fhahn wrote:

nit: not sure if it might be more compact to use `count_if` + checking the last parameter if count > 1.

https://github.com/llvm/llvm-project/pull/180558


More information about the llvm-commits mailing list