@@ -107,9 +107,7 @@ bool SCCPSolver::tryToReplaceWithConstant(Value *V) {
107107static bool refineInstruction (SCCPSolver &Solver,
108108 const SmallPtrSetImpl<Value *> &InsertedValues,
109109 Instruction &Inst) {
110- if (!isa<OverflowingBinaryOperator>(Inst))
111- return false ;
112-
110+ bool Changed = false ;
113111 auto GetRange = [&Solver, &InsertedValues](Value *Op) {
114112 if (auto *Const = dyn_cast<ConstantInt>(Op))
115113 return ConstantRange (Const->getValue ());
@@ -120,23 +118,32 @@ static bool refineInstruction(SCCPSolver &Solver,
120118 return getConstantRange (Solver.getLatticeValueFor (Op), Op->getType (),
121119 /* UndefAllowed=*/ false );
122120 };
123- auto RangeA = GetRange (Inst.getOperand (0 ));
124- auto RangeB = GetRange (Inst.getOperand (1 ));
125- bool Changed = false ;
126- if (!Inst.hasNoUnsignedWrap ()) {
127- auto NUWRange = ConstantRange::makeGuaranteedNoWrapRegion (
128- Instruction::BinaryOps (Inst.getOpcode ()), RangeB,
129- OverflowingBinaryOperator::NoUnsignedWrap);
130- if (NUWRange.contains (RangeA)) {
131- Inst.setHasNoUnsignedWrap ();
132- Changed = true ;
121+
122+ if (isa<OverflowingBinaryOperator>(Inst)) {
123+ auto RangeA = GetRange (Inst.getOperand (0 ));
124+ auto RangeB = GetRange (Inst.getOperand (1 ));
125+ if (!Inst.hasNoUnsignedWrap ()) {
126+ auto NUWRange = ConstantRange::makeGuaranteedNoWrapRegion (
127+ Instruction::BinaryOps (Inst.getOpcode ()), RangeB,
128+ OverflowingBinaryOperator::NoUnsignedWrap);
129+ if (NUWRange.contains (RangeA)) {
130+ Inst.setHasNoUnsignedWrap ();
131+ Changed = true ;
132+ }
133133 }
134- }
135- if (!Inst.hasNoSignedWrap ()) {
136- auto NSWRange = ConstantRange::makeGuaranteedNoWrapRegion (
137- Instruction::BinaryOps (Inst.getOpcode ()), RangeB, OverflowingBinaryOperator::NoSignedWrap);
138- if (NSWRange.contains (RangeA)) {
139- Inst.setHasNoSignedWrap ();
134+ if (!Inst.hasNoSignedWrap ()) {
135+ auto NSWRange = ConstantRange::makeGuaranteedNoWrapRegion (
136+ Instruction::BinaryOps (Inst.getOpcode ()), RangeB,
137+ OverflowingBinaryOperator::NoSignedWrap);
138+ if (NSWRange.contains (RangeA)) {
139+ Inst.setHasNoSignedWrap ();
140+ Changed = true ;
141+ }
142+ }
143+ } else if (isa<ZExtInst>(Inst) && !Inst.hasNonNeg ()) {
144+ auto Range = GetRange (Inst.getOperand (0 ));
145+ if (Range.isAllNonNegative ()) {
146+ Inst.setNonNeg ();
140147 Changed = true ;
141148 }
142149 }
0 commit comments