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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 12 05:50:38 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
----------------
david-arm wrote:

Yep, it's 2 less lines so slightly better. I've used `count_if` instead - thanks!

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


More information about the llvm-commits mailing list