diff --git a/llvm/include/llvm/ADT/Sequence.h b/llvm/include/llvm/ADT/Sequence.h --- a/llvm/include/llvm/ADT/Sequence.h +++ b/llvm/include/llvm/ADT/Sequence.h @@ -306,6 +306,16 @@ return iota_range(Begin, End, false); } +/// Iterate over an integral type from 0 up to - but not including - Size. +/// Note: Size value has to be within [INTMAX_MIN, INTMAX_MAX - 1] for +/// forward iteration (resp. [INTMAX_MIN + 1, INTMAX_MAX - 1] for reverse +/// iteration). +template ::value && + !std::is_enum::value>> +auto seq(T Size) { + return seq(0, Size); +} + /// Iterate over an integral type from Begin to End inclusive. /// Note: Begin and End values have to be within [INTMAX_MIN, INTMAX_MAX - 1] /// for forward iteration (resp. [INTMAX_MIN + 1, INTMAX_MAX - 1] for reverse diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -652,7 +652,7 @@ if (LNumOps != RNumOps) return (int)LNumOps - (int)RNumOps; - for (unsigned Idx : seq(0u, LNumOps)) { + for (unsigned Idx : seq(LNumOps)) { int Result = CompareValueComplexity(EqCacheValue, LI, LInst->getOperand(Idx), RInst->getOperand(Idx), Depth + 1); diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -2607,7 +2607,7 @@ assert(Mask.size() == (unsigned)ReplicationFactor * VF && "Unexpected mask size."); - for (int CurrElt : seq(0, VF)) { + for (int CurrElt : seq(VF)) { ArrayRef CurrSubMask = Mask.take_front(ReplicationFactor); assert(CurrSubMask.size() == (unsigned)ReplicationFactor && "Run out of mask?"); diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1303,7 +1303,7 @@ } for (const std::pair &NewSuccessor : NewSuccessors) { - for (auto I : seq(0, NewSuccessor.second)) { + for (auto I : seq(NewSuccessor.second)) { (void)I; AddPredecessorToBlock(NewSuccessor.first, Pred, BB); } diff --git a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp --- a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp +++ b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp @@ -106,7 +106,7 @@ for (const auto &LiveIn : Entry.MBB->liveins()) Loop.MBB->addLiveIn(LiveIn); } - for (auto _ : seq(0U, LoopUnrollFactor)) { + for (auto _ : seq(LoopUnrollFactor)) { (void)_; Loop.addInstructions(Instructions); } diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp @@ -55,7 +55,7 @@ OperandBundlesToKeepIndexes.reserve(Call.getNumOperandBundles()); // Enumerate every operand bundle on this call. - for (unsigned BundleIndex : seq(0U, Call.getNumOperandBundles())) + for (unsigned BundleIndex : seq(Call.getNumOperandBundles())) if (O.shouldKeep()) // Should we keep this one? OperandBundlesToKeepIndexes.emplace_back(BundleIndex); } diff --git a/llvm/unittests/ADT/SequenceTest.cpp b/llvm/unittests/ADT/SequenceTest.cpp --- a/llvm/unittests/ADT/SequenceTest.cpp +++ b/llvm/unittests/ADT/SequenceTest.cpp @@ -182,6 +182,8 @@ } TEST(SequenceTest, Iteration) { + EXPECT_THAT(seq(5), ElementsAre(0, 1, 2, 3, 4)); + EXPECT_THAT(seq(-4, 5), ElementsAre(-4, -3, -2, -1, 0, 1, 2, 3, 4)); EXPECT_THAT(reverse(seq(-4, 5)), ElementsAre(4, 3, 2, 1, 0, -1, -2, -3, -4));