summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index a56a37a618b..2c31e4aa6cd 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -64,7 +64,7 @@ STATISTIC(NumAShrs, "Number of ashr converted to lshr");
STATISTIC(NumSRems, "Number of srem converted to urem");
STATISTIC(NumOverflows, "Number of overflow checks removed");
-static cl::opt<bool> DontProcessAdds("cvp-dont-process-adds", cl::init(true));
+static cl::opt<bool> DontAddNoWrapFlags("cvp-dont-add-nowrap-flags", cl::init(true));
namespace {
@@ -607,53 +607,53 @@ static bool processAShr(BinaryOperator *SDI, LazyValueInfo *LVI) {
return true;
}
-static bool processAdd(BinaryOperator *AddOp, LazyValueInfo *LVI) {
+static bool processBinOp(BinaryOperator *BinOp, LazyValueInfo *LVI) {
using OBO = OverflowingBinaryOperator;
- if (DontProcessAdds)
+ if (DontAddNoWrapFlags)
return false;
- if (AddOp->getType()->isVectorTy())
+ if (BinOp->getType()->isVectorTy())
return false;
- bool NSW = AddOp->hasNoSignedWrap();
- bool NUW = AddOp->hasNoUnsignedWrap();
+ bool NSW = BinOp->hasNoSignedWrap();
+ bool NUW = BinOp->hasNoUnsignedWrap();
if (NSW && NUW)
return false;
- BasicBlock *BB = AddOp->getParent();
+ BasicBlock *BB = BinOp->getParent();
- Value *LHS = AddOp->getOperand(0);
- Value *RHS = AddOp->getOperand(1);
+ Value *LHS = BinOp->getOperand(0);
+ Value *RHS = BinOp->getOperand(1);
- ConstantRange LRange = LVI->getConstantRange(LHS, BB, AddOp);
+ ConstantRange RRange = LVI->getConstantRange(RHS, BB, BinOp);
- // Initialize RRange only if we need it. If we know that guaranteed no wrap
- // range for the given LHS range is empty don't spend time calculating the
- // range for the RHS.
- Optional<ConstantRange> RRange;
- auto LazyRRange = [&] () {
- if (!RRange)
- RRange = LVI->getConstantRange(RHS, BB, AddOp);
- return RRange.getValue();
+ // Initialize LRange only if we need it. If we know that guaranteed no wrap
+ // range for the given RHS range is empty don't spend time calculating the
+ // range for the LHS.
+ Optional<ConstantRange> LRange;
+ auto LazyLRange = [&] () {
+ if (!LRange)
+ LRange = LVI->getConstantRange(LHS, BB, BinOp);
+ return LRange.getValue();
};
bool Changed = false;
if (!NUW) {
ConstantRange NUWRange = ConstantRange::makeGuaranteedNoWrapRegion(
- BinaryOperator::Add, LRange, OBO::NoUnsignedWrap);
+ BinOp->getOpcode(), RRange, OBO::NoUnsignedWrap);
if (!NUWRange.isEmptySet()) {
- bool NewNUW = NUWRange.contains(LazyRRange());
- AddOp->setHasNoUnsignedWrap(NewNUW);
+ bool NewNUW = NUWRange.contains(LazyLRange());
+ BinOp->setHasNoUnsignedWrap(NewNUW);
Changed |= NewNUW;
}
}
if (!NSW) {
ConstantRange NSWRange = ConstantRange::makeGuaranteedNoWrapRegion(
- BinaryOperator::Add, LRange, OBO::NoSignedWrap);
+ BinOp->getOpcode(), RRange, OBO::NoSignedWrap);
if (!NSWRange.isEmptySet()) {
- bool NewNSW = NSWRange.contains(LazyRRange());
- AddOp->setHasNoSignedWrap(NewNSW);
+ bool NewNSW = NSWRange.contains(LazyLRange());
+ BinOp->setHasNoSignedWrap(NewNSW);
Changed |= NewNSW;
}
}
@@ -729,7 +729,8 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT,
BBChanged |= processAShr(cast<BinaryOperator>(II), LVI);
break;
case Instruction::Add:
- BBChanged |= processAdd(cast<BinaryOperator>(II), LVI);
+ case Instruction::Sub:
+ BBChanged |= processBinOp(cast<BinaryOperator>(II), LVI);
break;
}
}
OpenPOWER on IntegriCloud