Skip to content

Commit

Permalink
[SCEV] Modernize code style of isSCEVExprNeverPoison [NFC]
Browse files Browse the repository at this point in the history
Use for-range and all_of to make code easier to read in advance of other changes.
  • Loading branch information
preames committed Sep 30, 2021
1 parent 0d8bdc1 commit c5e491e
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit c5e491e

Please sign in to comment.