Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
lib/Analysis/ScalarEvolution.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 3,945 Lines • ▼ Show 20 Lines | if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(BEValue)) { | ||||
// This is not a valid addrec if the step amount is varying each | // This is not a valid addrec if the step amount is varying each | ||||
// loop iteration, but is not itself an addrec in this loop. | // loop iteration, but is not itself an addrec in this loop. | ||||
if (isLoopInvariant(Accum, L) || | if (isLoopInvariant(Accum, L) || | ||||
(isa<SCEVAddRecExpr>(Accum) && | (isa<SCEVAddRecExpr>(Accum) && | ||||
cast<SCEVAddRecExpr>(Accum)->getLoop() == L)) { | cast<SCEVAddRecExpr>(Accum)->getLoop() == L)) { | ||||
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap; | SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap; | ||||
// If the increment doesn't overflow, then neither the addrec nor | |||||
// the post-increment will overflow. | |||||
if (auto BO = MatchBinaryOp(BEValueV)) { | if (auto BO = MatchBinaryOp(BEValueV)) { | ||||
if (BO->Opcode == Instruction::Add && BO->LHS == PN) { | if (BO->Opcode == Instruction::Add && BO->LHS == PN) { | ||||
if (BO->IsNUW) | if (BO->IsNUW) | ||||
Flags = setFlags(Flags, SCEV::FlagNUW); | Flags = setFlags(Flags, SCEV::FlagNUW); | ||||
if (BO->IsNSW) | if (BO->IsNSW) | ||||
Flags = setFlags(Flags, SCEV::FlagNSW); | Flags = setFlags(Flags, SCEV::FlagNSW); | ||||
} | } | ||||
} else if (GEPOperator *GEP = dyn_cast<GEPOperator>(BEValueV)) { | } else if (GEPOperator *GEP = dyn_cast<GEPOperator>(BEValueV)) { | ||||
Show All 14 Lines | if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(BEValue)) { | ||||
// We cannot transfer nuw and nsw flags from subtraction | // We cannot transfer nuw and nsw flags from subtraction | ||||
// operations -- sub nuw X, Y is not the same as add nuw X, -Y | // operations -- sub nuw X, Y is not the same as add nuw X, -Y | ||||
// for instance. | // for instance. | ||||
} | } | ||||
const SCEV *StartVal = getSCEV(StartValueV); | const SCEV *StartVal = getSCEV(StartValueV); | ||||
const SCEV *PHISCEV = getAddRecExpr(StartVal, Accum, L, Flags); | const SCEV *PHISCEV = getAddRecExpr(StartVal, Accum, L, Flags); | ||||
// Since the no-wrap flags are on the increment, they apply to the | |||||
// post-incremented value as well. | |||||
if (isLoopInvariant(Accum, L)) | |||||
(void)getAddRecExpr(getAddExpr(StartVal, Accum), Accum, L, Flags); | |||||
// Okay, for the entire analysis of this edge we assumed the PHI | // Okay, for the entire analysis of this edge we assumed the PHI | ||||
// to be symbolic. We now need to go back and purge all of the | // to be symbolic. We now need to go back and purge all of the | ||||
// entries for the scalars that use the symbolic expression. | // entries for the scalars that use the symbolic expression. | ||||
forgetSymbolicName(PN, SymbolicName); | forgetSymbolicName(PN, SymbolicName); | ||||
ValueExprMap[SCEVCallbackVH(PN, this)] = PHISCEV; | ValueExprMap[SCEVCallbackVH(PN, this)] = PHISCEV; | ||||
// We can add Flags to the post-inc expression only if we | |||||
hfinkel: Indentation looks odd here. | |||||
// know that it us *undefined behavior* for BEValueV to | |||||
// overflow. | |||||
if (auto *BEInst = dyn_cast<Instruction>(BEValueV)) | |||||
if (isLoopInvariant(Accum, L) && isSCEVExprNeverPoison(BEInst)) | |||||
(void)getAddRecExpr(getAddExpr(StartVal, Accum), Accum, L, Flags); | |||||
return PHISCEV; | return PHISCEV; | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
// Otherwise, this could be a loop like this: | // Otherwise, this could be a loop like this: | ||||
// i = 0; for (j = 1; ..; ++j) { .... i = j; } | // i = 0; for (j = 1; ..; ++j) { .... i = j; } | ||||
// In this case, j = {1,+,1} and BEValue is j. | // In this case, j = {1,+,1} and BEValue is j. | ||||
// Because the other in-value of i (0) fits the evolution of BEValue | // Because the other in-value of i (0) fits the evolution of BEValue | ||||
▲ Show 20 Lines • Show All 6,393 Lines • Show Last 20 Lines |
Indentation looks odd here.