/// Check whether all operands are loop invariant. static bool hasLoopInvariantOperands(SILInstruction *I, SILLoop *L, llvm::DenseSet<SILInstruction *> &Inv) { auto Opds = I->getAllOperands(); return std::all_of(Opds.begin(), Opds.end(), [=](Operand &Op) { ValueBase *Def = Op.get(); // Operand is outside the loop or marked invariant. if (auto *Inst = Def->getDefiningInstruction()) return !L->contains(Inst->getParent()) || Inv.count(Inst); if (auto *Arg = dyn_cast<SILArgument>(Def)) return !L->contains(Arg->getParent()); return false; }); }