From 095f5b204ffafd65c919f5bf35d869a08d97e3d1 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Fri, 22 Jul 2016 20:47:55 +0000 Subject: [SCEV] Extract out a helper function; NFC The helper will get smarter in a later change, but right now this is just code reorganization. llvm-svn: 276467 --- llvm/lib/Analysis/ScalarEvolution.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Analysis') diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 32eda3f00a4..ce99f82cc06 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -8578,6 +8578,16 @@ ScalarEvolution::isImpliedCondOperandsHelper(ICmpInst::Predicate Pred, return false; } +Optional ScalarEvolution::getConstantDifference(const SCEV *LHS, + const SCEV *RHS) { + if (const SCEVAddExpr *AddLHS = dyn_cast(LHS)) + if (AddLHS->getOperand(1) == RHS) + if (auto *Addend = dyn_cast(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::isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred, // reduce the compile time impact of this optimization. return false; - const SCEVAddExpr *AddLHS = dyn_cast(LHS); - if (!AddLHS || AddLHS->getOperand(1) != FoundLHS || - !isa(AddLHS->getOperand(0))) + Optional Addend = getConstantDifference(LHS, FoundLHS); + if (!Addend) return false; APInt ConstFoundRHS = cast(FoundRHS)->getAPInt(); @@ -8600,10 +8609,8 @@ bool ScalarEvolution::isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred, ConstantRange FoundLHSRange = ConstantRange::makeAllowedICmpRegion(Pred, ConstFoundRHS); - // Since `LHS` is `FoundLHS` + `AddLHS->getOperand(0)`, we can compute a range - // for `LHS`: - APInt Addend = cast(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`": -- cgit v1.2.3