mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 22:28:18 +00:00
[IRCE] Fix how IRCE checks for no-sign-overflow.
IRCE requires the induction variables it handles to not sign-overflow. The current scheme of checking if sext({X,+,S}) == {sext(X),+,sext(S)} fails when SCEV simplifies sext(X) too. After this change we //also// check no-signed-wrap by looking at the flags set on the SCEVAddRecExpr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233102 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -707,22 +707,17 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, BranchProbabilityInfo &BP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto IsInductionVar = [&SE](const SCEVAddRecExpr *AR, bool &IsIncreasing) {
|
auto HasNoSignedWrap = [&](const SCEVAddRecExpr *AR) {
|
||||||
if (!AR->isAffine())
|
if (AR->getNoWrapFlags(SCEV::FlagNSW))
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
IntegerType *Ty = cast<IntegerType>(AR->getType());
|
IntegerType *Ty = cast<IntegerType>(AR->getType());
|
||||||
IntegerType *WideTy =
|
IntegerType *WideTy =
|
||||||
IntegerType::get(Ty->getContext(), Ty->getBitWidth() * 2);
|
IntegerType::get(Ty->getContext(), Ty->getBitWidth() * 2);
|
||||||
|
|
||||||
// Currently we only work with induction variables that have been proved to
|
|
||||||
// not wrap. This restriction can potentially be lifted in the future.
|
|
||||||
|
|
||||||
const SCEVAddRecExpr *ExtendAfterOp =
|
const SCEVAddRecExpr *ExtendAfterOp =
|
||||||
dyn_cast<SCEVAddRecExpr>(SE.getSignExtendExpr(AR, WideTy));
|
dyn_cast<SCEVAddRecExpr>(SE.getSignExtendExpr(AR, WideTy));
|
||||||
if (!ExtendAfterOp)
|
if (ExtendAfterOp) {
|
||||||
return false;
|
|
||||||
|
|
||||||
const SCEV *ExtendedStart = SE.getSignExtendExpr(AR->getStart(), WideTy);
|
const SCEV *ExtendedStart = SE.getSignExtendExpr(AR->getStart(), WideTy);
|
||||||
const SCEV *ExtendedStep =
|
const SCEV *ExtendedStep =
|
||||||
SE.getSignExtendExpr(AR->getStepRecurrence(SE), WideTy);
|
SE.getSignExtendExpr(AR->getStepRecurrence(SE), WideTy);
|
||||||
@@ -730,7 +725,22 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, BranchProbabilityInfo &BP
|
|||||||
bool NoSignedWrap = ExtendAfterOp->getStart() == ExtendedStart &&
|
bool NoSignedWrap = ExtendAfterOp->getStart() == ExtendedStart &&
|
||||||
ExtendAfterOp->getStepRecurrence(SE) == ExtendedStep;
|
ExtendAfterOp->getStepRecurrence(SE) == ExtendedStep;
|
||||||
|
|
||||||
if (!NoSignedWrap)
|
if (NoSignedWrap)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We may have proved this when computing the sign extension above.
|
||||||
|
return AR->getNoWrapFlags(SCEV::FlagNSW) != SCEV::FlagAnyWrap;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto IsInductionVar = [&](const SCEVAddRecExpr *AR, bool &IsIncreasing) {
|
||||||
|
if (!AR->isAffine())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Currently we only work with induction variables that have been proved to
|
||||||
|
// not wrap. This restriction can potentially be lifted in the future.
|
||||||
|
|
||||||
|
if (!HasNoSignedWrap(AR))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (const SCEVConstant *StepExpr =
|
if (const SCEVConstant *StepExpr =
|
||||||
|
Reference in New Issue
Block a user