Skip to content

Commit 8b1fa07

Browse files
committed
[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
1 parent 2149811 commit 8b1fa07

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

llvm/lib/IR/ConstantRange.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
238238

239239
switch (BinOp) {
240240
default:
241-
// Conservative answer: empty set
242-
return getEmpty(BitWidth);
241+
llvm_unreachable("Unsupported binary op");
243242

244243
case Instruction::Add: {
245244
if (Unsigned)

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,12 @@ static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI,
400400

401401
// See if we can prove that the given overflow intrinsic will not overflow.
402402
static bool willNotOverflow(WithOverflowInst *WO, LazyValueInfo *LVI) {
403-
Value *RHS = WO->getRHS();
404-
ConstantRange RRange = LVI->getConstantRange(RHS, WO->getParent(), WO);
403+
ConstantRange LRange = LVI->getConstantRange(
404+
WO->getLHS(), WO->getParent(), WO);
405+
ConstantRange RRange = LVI->getConstantRange(
406+
WO->getRHS(), WO->getParent(), WO);
405407
ConstantRange NWRegion = ConstantRange::makeGuaranteedNoWrapRegion(
406408
WO->getBinaryOp(), RRange, WO->getNoWrapKind());
407-
// As an optimization, do not compute LRange if we do not need it.
408-
if (NWRegion.isEmptySet())
409-
return false;
410-
Value *LHS = WO->getLHS();
411-
ConstantRange LRange = LVI->getConstantRange(LHS, WO->getParent(), WO);
412409
return NWRegion.contains(LRange);
413410
}
414411

@@ -626,36 +623,23 @@ static bool processBinOp(BinaryOperator *BinOp, LazyValueInfo *LVI) {
626623
Value *LHS = BinOp->getOperand(0);
627624
Value *RHS = BinOp->getOperand(1);
628625

626+
ConstantRange LRange = LVI->getConstantRange(LHS, BB, BinOp);
629627
ConstantRange RRange = LVI->getConstantRange(RHS, BB, BinOp);
630628

631-
// Initialize LRange only if we need it. If we know that guaranteed no wrap
632-
// range for the given RHS range is empty don't spend time calculating the
633-
// range for the LHS.
634-
Optional<ConstantRange> LRange;
635-
auto LazyLRange = [&] () {
636-
if (!LRange)
637-
LRange = LVI->getConstantRange(LHS, BB, BinOp);
638-
return LRange.getValue();
639-
};
640-
641629
bool Changed = false;
642630
if (!NUW) {
643631
ConstantRange NUWRange = ConstantRange::makeGuaranteedNoWrapRegion(
644632
BinOp->getOpcode(), RRange, OBO::NoUnsignedWrap);
645-
if (!NUWRange.isEmptySet()) {
646-
bool NewNUW = NUWRange.contains(LazyLRange());
647-
BinOp->setHasNoUnsignedWrap(NewNUW);
648-
Changed |= NewNUW;
649-
}
633+
bool NewNUW = NUWRange.contains(LRange);
634+
BinOp->setHasNoUnsignedWrap(NewNUW);
635+
Changed |= NewNUW;
650636
}
651637
if (!NSW) {
652638
ConstantRange NSWRange = ConstantRange::makeGuaranteedNoWrapRegion(
653639
BinOp->getOpcode(), RRange, OBO::NoSignedWrap);
654-
if (!NSWRange.isEmptySet()) {
655-
bool NewNSW = NSWRange.contains(LazyLRange());
656-
BinOp->setHasNoSignedWrap(NewNSW);
657-
Changed |= NewNSW;
658-
}
640+
bool NewNSW = NSWRange.contains(LRange);
641+
BinOp->setHasNoSignedWrap(NewNSW);
642+
Changed |= NewNSW;
659643
}
660644

661645
return Changed;

0 commit comments

Comments
 (0)