[llvm] r276467 - [SCEV] Extract out a helper function; NFC
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 22 13:47:57 PDT 2016
Author: sanjoy
Date: Fri Jul 22 15:47:55 2016
New Revision: 276467
URL: http://llvm.org/viewvc/llvm-project?rev=276467&view=rev
Log:
[SCEV] Extract out a helper function; NFC
The helper will get smarter in a later change, but right now this is
just code reorganization.
Modified:
llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=276467&r1=276466&r2=276467&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Fri Jul 22 15:47:55 2016
@@ -1171,6 +1171,15 @@ namespace llvm {
/// add recurrence on the loop \p L.
bool isAddRecNeverPoison(const Instruction *I, const Loop *L);
+ /// Compute \p LHS - \p RHS and returns the result as an APInt if it is a
+ /// constant, and None if it isn't.
+ ///
+ /// This is intended to be a cheaper version of getMinusSCEV. We can be
+ /// frugal here since we just bail out of actually constructing and
+ /// canonicalizing an expression in the cases where the result isn't going
+ /// to be a constant.
+ Optional<APInt> getConstantDifference(const SCEV *LHS, const SCEV *RHS);
+
public:
ScalarEvolution(Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC,
DominatorTree &DT, LoopInfo &LI);
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=276467&r1=276466&r2=276467&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Fri Jul 22 15:47:55 2016
@@ -8578,6 +8578,16 @@ ScalarEvolution::isImpliedCondOperandsHe
return false;
}
+Optional<APInt> ScalarEvolution::getConstantDifference(const SCEV *LHS,
+ const SCEV *RHS) {
+ if (const SCEVAddExpr *AddLHS = dyn_cast<SCEVAddExpr>(LHS))
+ if (AddLHS->getOperand(1) == RHS)
+ if (auto *Addend = dyn_cast<SCEVConstant>(AddLHS->getOperand(0)))
+ return Addend->getAPInt();
+
+ return None;
+}
+
bool ScalarEvolution::isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred,
const SCEV *LHS,
const SCEV *RHS,
@@ -8588,9 +8598,8 @@ bool ScalarEvolution::isImpliedCondOpera
// reduce the compile time impact of this optimization.
return false;
- const SCEVAddExpr *AddLHS = dyn_cast<SCEVAddExpr>(LHS);
- if (!AddLHS || AddLHS->getOperand(1) != FoundLHS ||
- !isa<SCEVConstant>(AddLHS->getOperand(0)))
+ Optional<APInt> Addend = getConstantDifference(LHS, FoundLHS);
+ if (!Addend)
return false;
APInt ConstFoundRHS = cast<SCEVConstant>(FoundRHS)->getAPInt();
@@ -8600,10 +8609,8 @@ bool ScalarEvolution::isImpliedCondOpera
ConstantRange FoundLHSRange =
ConstantRange::makeAllowedICmpRegion(Pred, ConstFoundRHS);
- // Since `LHS` is `FoundLHS` + `AddLHS->getOperand(0)`, we can compute a range
- // for `LHS`:
- APInt Addend = cast<SCEVConstant>(AddLHS->getOperand(0))->getAPInt();
- ConstantRange LHSRange = FoundLHSRange.add(ConstantRange(Addend));
+ // Since `LHS` is `FoundLHS` + `Addend`, we can compute a range for `LHS`:
+ ConstantRange LHSRange = FoundLHSRange.add(ConstantRange(*Addend));
// We can also compute the range of values for `LHS` that satisfy the
// consequent, "`LHS` `Pred` `RHS`":
More information about the llvm-commits
mailing list