@@ -169,18 +169,12 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
169
169
break ;
170
170
}
171
171
case TargetOpcode::G_SUB: {
172
- // If low bits are known to be zero in both operands, then we know they are
173
- // going to be 0 in the result. Both addition and complement operations
174
- // preserve the low zero bits.
175
- computeKnownBitsImpl (MI.getOperand (1 ).getReg (), Known2, DemandedElts,
172
+ computeKnownBitsImpl (MI.getOperand (1 ).getReg (), Known, DemandedElts,
176
173
Depth + 1 );
177
- unsigned KnownZeroLow = Known2.countMinTrailingZeros ();
178
- if (KnownZeroLow == 0 )
179
- break ;
180
174
computeKnownBitsImpl (MI.getOperand (2 ).getReg (), Known2, DemandedElts,
181
175
Depth + 1 );
182
- KnownZeroLow = std::min (KnownZeroLow, Known2. countMinTrailingZeros ());
183
- Known. Zero . setLowBits (KnownZeroLow );
176
+ Known = KnownBits::computeForAddSub ( /* Add */ false , /* NSW */ false , Known,
177
+ Known2 );
184
178
break ;
185
179
}
186
180
case TargetOpcode::G_XOR: {
@@ -204,24 +198,12 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
204
198
LLVM_FALLTHROUGH;
205
199
}
206
200
case TargetOpcode::G_ADD: {
207
- // Output known-0 bits are known if clear or set in both the low clear bits
208
- // common to both LHS & RHS. For example, 8+(X<<3) is known to have the
209
- // low 3 bits clear.
210
- // Output known-0 bits are also known if the top bits of each input are
211
- // known to be clear. For example, if one input has the top 10 bits clear
212
- // and the other has the top 8 bits clear, we know the top 7 bits of the
213
- // output must be clear.
214
- computeKnownBitsImpl (MI.getOperand (1 ).getReg (), Known2, DemandedElts,
201
+ computeKnownBitsImpl (MI.getOperand (1 ).getReg (), Known, DemandedElts,
215
202
Depth + 1 );
216
- unsigned KnownZeroHigh = Known2.countMinLeadingZeros ();
217
- unsigned KnownZeroLow = Known2.countMinTrailingZeros ();
218
203
computeKnownBitsImpl (MI.getOperand (2 ).getReg (), Known2, DemandedElts,
219
204
Depth + 1 );
220
- KnownZeroHigh = std::min (KnownZeroHigh, Known2.countMinLeadingZeros ());
221
- KnownZeroLow = std::min (KnownZeroLow, Known2.countMinTrailingZeros ());
222
- Known.Zero .setLowBits (KnownZeroLow);
223
- if (KnownZeroHigh > 1 )
224
- Known.Zero .setHighBits (KnownZeroHigh - 1 );
205
+ Known =
206
+ KnownBits::computeForAddSub (/* Add*/ true , /* NSW*/ false , Known, Known2);
225
207
break ;
226
208
}
227
209
case TargetOpcode::G_AND: {
0 commit comments