mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-25 05:22:04 +00:00
[SCEV] Improve Scalar Evolution's use of no {un,}signed wrap flags
In a case where we have a no {un,}signed wrap flag on the increment, if
RHS - Start is constant then we can avoid inserting a max operation bewteen
the two, since we can statically determine which is greater.
This allows us to unroll loops such as:
void testcase3(int v) {
for (int i=v; i<=v+1; ++i)
f(i);
}
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220960 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -6964,9 +6964,19 @@ ScalarEvolution::HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
|
||||
: ICmpInst::ICMP_ULT;
|
||||
const SCEV *Start = IV->getStart();
|
||||
const SCEV *End = RHS;
|
||||
if (!isLoopEntryGuardedByCond(L, Cond, getMinusSCEV(Start, Stride), RHS))
|
||||
End = IsSigned ? getSMaxExpr(RHS, Start)
|
||||
: getUMaxExpr(RHS, Start);
|
||||
if (!isLoopEntryGuardedByCond(L, Cond, getMinusSCEV(Start, Stride), RHS)) {
|
||||
const SCEV *Diff = getMinusSCEV(RHS, Start);
|
||||
// If we have NoWrap set, then we can assume that the increment won't
|
||||
// overflow, in which case if RHS - Start is a constant, we don't need to
|
||||
// do a max operation since we can just figure it out statically
|
||||
if (NoWrap && isa<SCEVConstant>(Diff)) {
|
||||
APInt D = dyn_cast<const SCEVConstant>(Diff)->getValue()->getValue();
|
||||
if (D.isNegative())
|
||||
End = Start;
|
||||
} else
|
||||
End = IsSigned ? getSMaxExpr(RHS, Start)
|
||||
: getUMaxExpr(RHS, Start);
|
||||
}
|
||||
|
||||
const SCEV *BECount = computeBECount(getMinusSCEV(End, Start), Stride, false);
|
||||
|
||||
@@ -7035,9 +7045,19 @@ ScalarEvolution::HowManyGreaterThans(const SCEV *LHS, const SCEV *RHS,
|
||||
|
||||
const SCEV *Start = IV->getStart();
|
||||
const SCEV *End = RHS;
|
||||
if (!isLoopEntryGuardedByCond(L, Cond, getAddExpr(Start, Stride), RHS))
|
||||
End = IsSigned ? getSMinExpr(RHS, Start)
|
||||
: getUMinExpr(RHS, Start);
|
||||
if (!isLoopEntryGuardedByCond(L, Cond, getAddExpr(Start, Stride), RHS)) {
|
||||
const SCEV *Diff = getMinusSCEV(RHS, Start);
|
||||
// If we have NoWrap set, then we can assume that the increment won't
|
||||
// overflow, in which case if RHS - Start is a constant, we don't need to
|
||||
// do a max operation since we can just figure it out statically
|
||||
if (NoWrap && isa<SCEVConstant>(Diff)) {
|
||||
APInt D = dyn_cast<const SCEVConstant>(Diff)->getValue()->getValue();
|
||||
if (!D.isNegative())
|
||||
End = Start;
|
||||
} else
|
||||
End = IsSigned ? getSMinExpr(RHS, Start)
|
||||
: getUMinExpr(RHS, Start);
|
||||
}
|
||||
|
||||
const SCEV *BECount = computeBECount(getMinusSCEV(Start, End), Stride, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user