aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2016-07-23 00:28:56 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2016-07-23 00:28:56 +0000
commit0b1af85cc2aef712f532677a4bc2d7843590d518 (patch)
tree07071a9c58654f29d7200e83e73fb65b98662d46 /llvm/lib/Analysis/ScalarEvolution.cpp
parent6ebd5857c8f63d5167aa06fa9cecddd54a5832be (diff)
downloadllvm-0b1af85cc2aef712f532677a4bc2d7843590d518.zip
llvm-0b1af85cc2aef712f532677a4bc2d7843590d518.tar.gz
llvm-0b1af85cc2aef712f532677a4bc2d7843590d518.tar.bz2
[SCEV] Change the interface of computeConstantDifference; NFC
This is in preparation of s/getConstantDifference/computeConstantDifference/ in a later change. llvm-svn: 276503
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp41
1 files changed, 17 insertions, 24 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index ce99f82..89c09a8 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8275,9 +8275,8 @@ bool ScalarEvolution::splitBinaryAdd(const SCEV *Expr,
return true;
}
-bool ScalarEvolution::computeConstantDifference(const SCEV *Less,
- const SCEV *More,
- APInt &C) {
+Optional<APInt> ScalarEvolution::computeConstantDifference(const SCEV *More,
+ const SCEV *Less) {
// We avoid subtracting expressions here because this function is usually
// fairly deep in the call stack (i.e. is called many times).
@@ -8286,15 +8285,15 @@ bool ScalarEvolution::computeConstantDifference(const SCEV *Less,
const auto *MAR = cast<SCEVAddRecExpr>(More);
if (LAR->getLoop() != MAR->getLoop())
- return false;
+ return None;
// We look at affine expressions only; not for correctness but to keep
// getStepRecurrence cheap.
if (!LAR->isAffine() || !MAR->isAffine())
- return false;
+ return None;
if (LAR->getStepRecurrence(*this) != MAR->getStepRecurrence(*this))
- return false;
+ return None;
Less = LAR->getStart();
More = MAR->getStart();
@@ -8305,27 +8304,22 @@ bool ScalarEvolution::computeConstantDifference(const SCEV *Less,
if (isa<SCEVConstant>(Less) && isa<SCEVConstant>(More)) {
const auto &M = cast<SCEVConstant>(More)->getAPInt();
const auto &L = cast<SCEVConstant>(Less)->getAPInt();
- C = M - L;
- return true;
+ return M - L;
}
const SCEV *L, *R;
SCEV::NoWrapFlags Flags;
if (splitBinaryAdd(Less, L, R, Flags))
if (const auto *LC = dyn_cast<SCEVConstant>(L))
- if (R == More) {
- C = -(LC->getAPInt());
- return true;
- }
+ if (R == More)
+ return -(LC->getAPInt());
if (splitBinaryAdd(More, L, R, Flags))
if (const auto *LC = dyn_cast<SCEVConstant>(L))
- if (R == Less) {
- C = LC->getAPInt();
- return true;
- }
+ if (R == Less)
+ return LC->getAPInt();
- return false;
+ return None;
}
bool ScalarEvolution::isImpliedCondOperandsViaNoOverflow(
@@ -8382,22 +8376,21 @@ bool ScalarEvolution::isImpliedCondOperandsViaNoOverflow(
// neither necessary nor sufficient to prove "(FoundLHS + C) s< (FoundRHS +
// C)".
- APInt LDiff, RDiff;
- if (!computeConstantDifference(FoundLHS, LHS, LDiff) ||
- !computeConstantDifference(FoundRHS, RHS, RDiff) ||
- LDiff != RDiff)
+ Optional<APInt> LDiff = computeConstantDifference(LHS, FoundLHS);
+ Optional<APInt> RDiff = computeConstantDifference(RHS, FoundRHS);
+ if (!LDiff || !RDiff || *LDiff != *RDiff)
return false;
- if (LDiff == 0)
+ if (LDiff->isMinValue())
return true;
APInt FoundRHSLimit;
if (Pred == CmpInst::ICMP_ULT) {
- FoundRHSLimit = -RDiff;
+ FoundRHSLimit = -(*RDiff);
} else {
assert(Pred == CmpInst::ICMP_SLT && "Checked above!");
- FoundRHSLimit = APInt::getSignedMinValue(getTypeSizeInBits(RHS->getType())) - RDiff;
+ FoundRHSLimit = APInt::getSignedMinValue(getTypeSizeInBits(RHS->getType())) - *RDiff;
}
// Try to prove (1) or (2), as needed.