summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-05-25 14:11:55 +0000
committerNikita Popov <nikita.ppv@gmail.com>2019-05-25 14:11:55 +0000
commit8b1fa076397555968ffa7dcda5ef91715cec5c8e (patch)
treee47a0712f9f3236a67296564789c2a5b3deda5ee /llvm/lib
parent214981185478329ee6745cbfdd35783e7320e73c (diff)
downloadbcm5719-llvm-8b1fa076397555968ffa7dcda5ef91715cec5c8e.tar.gz
bcm5719-llvm-8b1fa076397555968ffa7dcda5ef91715cec5c8e.zip
[CVP] Remove unnecessary checks for empty GNWR; NFC
The guaranteed no-wrap region is never empty, it always contains at least zero, so these optimizations don't ever apply. To make this more obviously true, replace the conversative return in makeGNWR with an assertion. llvm-svn: 361698
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp3
-rw-r--r--llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp38
2 files changed, 12 insertions, 29 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 549886271ff..0d44c3815b3 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -238,8 +238,7 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
switch (BinOp) {
default:
- // Conservative answer: empty set
- return getEmpty(BitWidth);
+ llvm_unreachable("Unsupported binary op");
case Instruction::Add: {
if (Unsigned)
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 2c31e4aa6cd..4e4715be61a 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -400,15 +400,12 @@ static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI,
// See if we can prove that the given overflow intrinsic will not overflow.
static bool willNotOverflow(WithOverflowInst *WO, LazyValueInfo *LVI) {
- Value *RHS = WO->getRHS();
- ConstantRange RRange = LVI->getConstantRange(RHS, WO->getParent(), WO);
+ ConstantRange LRange = LVI->getConstantRange(
+ WO->getLHS(), WO->getParent(), WO);
+ ConstantRange RRange = LVI->getConstantRange(
+ WO->getRHS(), WO->getParent(), WO);
ConstantRange NWRegion = ConstantRange::makeGuaranteedNoWrapRegion(
WO->getBinaryOp(), RRange, WO->getNoWrapKind());
- // As an optimization, do not compute LRange if we do not need it.
- if (NWRegion.isEmptySet())
- return false;
- Value *LHS = WO->getLHS();
- ConstantRange LRange = LVI->getConstantRange(LHS, WO->getParent(), WO);
return NWRegion.contains(LRange);
}
@@ -626,36 +623,23 @@ static bool processBinOp(BinaryOperator *BinOp, LazyValueInfo *LVI) {
Value *LHS = BinOp->getOperand(0);
Value *RHS = BinOp->getOperand(1);
+ ConstantRange LRange = LVI->getConstantRange(LHS, BB, BinOp);
ConstantRange RRange = LVI->getConstantRange(RHS, BB, BinOp);
- // 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(
BinOp->getOpcode(), RRange, OBO::NoUnsignedWrap);
- if (!NUWRange.isEmptySet()) {
- bool NewNUW = NUWRange.contains(LazyLRange());
- BinOp->setHasNoUnsignedWrap(NewNUW);
- Changed |= NewNUW;
- }
+ bool NewNUW = NUWRange.contains(LRange);
+ BinOp->setHasNoUnsignedWrap(NewNUW);
+ Changed |= NewNUW;
}
if (!NSW) {
ConstantRange NSWRange = ConstantRange::makeGuaranteedNoWrapRegion(
BinOp->getOpcode(), RRange, OBO::NoSignedWrap);
- if (!NSWRange.isEmptySet()) {
- bool NewNSW = NSWRange.contains(LazyLRange());
- BinOp->setHasNoSignedWrap(NewNSW);
- Changed |= NewNSW;
- }
+ bool NewNSW = NSWRange.contains(LRange);
+ BinOp->setHasNoSignedWrap(NewNSW);
+ Changed |= NewNSW;
}
return Changed;
OpenPOWER on IntegriCloud