diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -2487,19 +2487,14 @@ } template -static void preAssignMask(const ArgTy &Args, - Optional &FirstMaskArgument, - CCState &CCInfo) { - unsigned NumArgs = Args.size(); - for (unsigned I = 0; I != NumArgs; ++I) { - MVT ArgVT = Args[I].VT; - if (!ArgVT.isScalableVector() || - ArgVT.getVectorElementType().SimpleTy != MVT::i1) - continue; - - FirstMaskArgument = I; - break; +static Optional preAssignMask(const ArgTy &Args) { + for (const auto &ArgIdx : enumerate(Args)) { + MVT ArgVT = ArgIdx.value().VT; + if (ArgVT.isScalableVector() && + ArgVT.getVectorElementType().SimpleTy == MVT::i1) + return ArgIdx.index(); } + return None; } void RISCVTargetLowering::analyzeInputArgs( @@ -2510,7 +2505,7 @@ Optional FirstMaskArgument; if (Subtarget.hasStdExtV()) - preAssignMask(Ins, FirstMaskArgument, CCInfo); + FirstMaskArgument = preAssignMask(Ins); for (unsigned i = 0; i != NumArgs; ++i) { MVT ArgVT = Ins[i].VT; @@ -2541,7 +2536,7 @@ Optional FirstMaskArgument; if (Subtarget.hasStdExtV()) - preAssignMask(Outs, FirstMaskArgument, CCInfo); + FirstMaskArgument = preAssignMask(Outs); for (unsigned i = 0; i != NumArgs; i++) { MVT ArgVT = Outs[i].VT; @@ -3312,7 +3307,7 @@ Optional FirstMaskArgument; if (Subtarget.hasStdExtV()) - preAssignMask(Outs, FirstMaskArgument, CCInfo); + FirstMaskArgument = preAssignMask(Outs); for (unsigned i = 0, e = Outs.size(); i != e; ++i) { MVT VT = Outs[i].VT;