[SCEV] Modernize code style of isSCEVExprNeverPoison [NFC]

Use for-range and all_of to make code easier to read in advance of other changes.
This commit is contained in:
Philip Reames 2021-09-30 15:13:00 -07:00
parent 0d8bdc1786
commit c5e491e6ee
1 changed files with 12 additions and 16 deletions

View File

@ -6591,26 +6591,22 @@ bool ScalarEvolution::isSCEVExprNeverPoison(const Instruction *I) {
// We check isLoopInvariant to disambiguate in case we are adding recurrences
// from different loops, so that we know which loop to prove that I is
// executed in.
for (unsigned OpIndex = 0; OpIndex < I->getNumOperands(); ++OpIndex) {
for (const Use &Op : I->operands()) {
// I could be an extractvalue from a call to an overflow intrinsic.
// TODO: We can do better here in some cases.
if (!isSCEVable(I->getOperand(OpIndex)->getType()))
if (!isSCEVable(Op->getType()))
return false;
const SCEV *Op = getSCEV(I->getOperand(OpIndex));
if (auto *AddRec = dyn_cast<SCEVAddRecExpr>(Op)) {
bool AllOtherOpsLoopInvariant = true;
for (unsigned OtherOpIndex = 0; OtherOpIndex < I->getNumOperands();
++OtherOpIndex) {
if (OtherOpIndex != OpIndex) {
const SCEV *OtherOp = getSCEV(I->getOperand(OtherOpIndex));
if (!isLoopInvariant(OtherOp, AddRec->getLoop())) {
AllOtherOpsLoopInvariant = false;
break;
}
}
}
const SCEV *OpS = getSCEV(Op);
if (auto *AddRecS = dyn_cast<SCEVAddRecExpr>(OpS)) {
const bool AllOtherOpsLoopInvariant =
llvm::all_of(I->operands(), [&](const Use &Op2) -> bool {
if (Op.getOperandNo() == Op2.getOperandNo())
return true;
const SCEV *OtherOp = getSCEV(Op2);
return isLoopInvariant(OtherOp, AddRecS->getLoop());
});
if (AllOtherOpsLoopInvariant &&
isGuaranteedToExecuteForEveryIteration(I, AddRec->getLoop()))
isGuaranteedToExecuteForEveryIteration(I, AddRecS->getLoop()))
return true;
}
}