@@ -107,9 +107,7 @@ bool SCCPSolver::tryToReplaceWithConstant(Value *V) {
107
107
static bool refineInstruction (SCCPSolver &Solver,
108
108
const SmallPtrSetImpl<Value *> &InsertedValues,
109
109
Instruction &Inst) {
110
- if (!isa<OverflowingBinaryOperator>(Inst))
111
- return false ;
112
-
110
+ bool Changed = false ;
113
111
auto GetRange = [&Solver, &InsertedValues](Value *Op) {
114
112
if (auto *Const = dyn_cast<ConstantInt>(Op))
115
113
return ConstantRange (Const->getValue ());
@@ -120,23 +118,32 @@ static bool refineInstruction(SCCPSolver &Solver,
120
118
return getConstantRange (Solver.getLatticeValueFor (Op), Op->getType (),
121
119
/* UndefAllowed=*/ false );
122
120
};
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
+ }
133
133
}
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 ();
140
147
Changed = true ;
141
148
}
142
149
}
0 commit comments