diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp index af5fd87a898e..7d2b40a02859 100644 --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -316,6 +316,21 @@ adderGenerator(const int32_t From, const int32_t To, const int32_t StepSize) { }; } +// Move to the next generator if it is exhausted allowing to chain generators +std::function()> concatGenerators( + std::vector()>> Generators) { + auto GeneratorIterator = Generators.cbegin(); + + return [GeneratorIterator, Generators]() mutable { + std::optional GenValue = (*GeneratorIterator)(); + if (!GenValue.has_value() && GeneratorIterator != Generators.cend()) { + GeneratorIterator++; + GenValue = (*GeneratorIterator)(); + } + return GenValue; + }; +} + Register CombinerHelper::createUnmergeValue(MachineInstr &MI, const Register SrcReg, const Register DstReg,