@@ -400,15 +400,12 @@ static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI,
400
400
401
401
// See if we can prove that the given overflow intrinsic will not overflow.
402
402
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);
405
407
ConstantRange NWRegion = ConstantRange::makeGuaranteedNoWrapRegion (
406
408
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);
412
409
return NWRegion.contains (LRange);
413
410
}
414
411
@@ -626,36 +623,23 @@ static bool processBinOp(BinaryOperator *BinOp, LazyValueInfo *LVI) {
626
623
Value *LHS = BinOp->getOperand (0 );
627
624
Value *RHS = BinOp->getOperand (1 );
628
625
626
+ ConstantRange LRange = LVI->getConstantRange (LHS, BB, BinOp);
629
627
ConstantRange RRange = LVI->getConstantRange (RHS, BB, BinOp);
630
628
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
-
641
629
bool Changed = false ;
642
630
if (!NUW) {
643
631
ConstantRange NUWRange = ConstantRange::makeGuaranteedNoWrapRegion (
644
632
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;
650
636
}
651
637
if (!NSW) {
652
638
ConstantRange NSWRange = ConstantRange::makeGuaranteedNoWrapRegion (
653
639
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;
659
643
}
660
644
661
645
return Changed;
0 commit comments