diff options
author | Luqman Aden <me@luqman.ca> | 2019-04-20 13:14:18 +0000 |
---|---|---|
committer | Luqman Aden <me@luqman.ca> | 2019-04-20 13:14:18 +0000 |
commit | 2993661cc0e5d7f6d15e071bfcd047592aef6675 (patch) | |
tree | a03c0526995394a5e62b94507cfbdec5a2599069 /llvm/lib | |
parent | d3b2682351184c8a2aacb40ae0b62888ff847478 (diff) | |
download | bcm5719-llvm-2993661cc0e5d7f6d15e071bfcd047592aef6675.tar.gz bcm5719-llvm-2993661cc0e5d7f6d15e071bfcd047592aef6675.zip |
[CorrelatedValuePropagation] Mark subs that we know not to wrap with nuw/nsw.
Summary:
Teach CorrelatedValuePropagation to also handle sub instructions in addition to add. Relatively simple since makeGuaranteedNoWrapRegion already understood sub instructions. Only subtle change is which range is passed as "Other" to that function, since sub isn't commutative.
Note that CorrelatedValuePropagation::processAddSub is still hidden behind a default-off flag as IndVarSimplify hasn't yet been fixed to strip the added nsw/nuw flags and causes a miscompile. (PR31181)
Reviewers: sanjoy, apilipenko, nikic
Reviewed By: nikic
Subscribers: hiraditya, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60036
llvm-svn: 358816
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 51 |
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; } } |