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