@@ -95,6 +95,17 @@ KnownBits ConstantRange::toKnownBits() const {
95
95
return Known;
96
96
}
97
97
98
+ std::pair<ConstantRange, ConstantRange> ConstantRange::splitPosNeg () const {
99
+ uint32_t BW = getBitWidth ();
100
+ APInt Zero = APInt::getZero (BW), One = APInt (BW, 1 );
101
+ APInt SignedMin = APInt::getSignedMinValue (BW);
102
+ // There are no positive 1-bit values. The 1 would get interpreted as -1.
103
+ ConstantRange PosFilter =
104
+ BW == 1 ? getEmpty () : ConstantRange (One, SignedMin);
105
+ ConstantRange NegFilter (SignedMin, Zero);
106
+ return {intersectWith (PosFilter), intersectWith (NegFilter)};
107
+ }
108
+
98
109
ConstantRange ConstantRange::makeAllowedICmpRegion (CmpInst::Predicate Pred,
99
110
const ConstantRange &CR) {
100
111
if (CR.isEmptySet ())
@@ -1356,20 +1367,14 @@ ConstantRange::udiv(const ConstantRange &RHS) const {
1356
1367
}
1357
1368
1358
1369
ConstantRange ConstantRange::sdiv (const ConstantRange &RHS) const {
1370
+ APInt Zero = APInt::getZero (getBitWidth ());
1371
+ APInt SignedMin = APInt::getSignedMinValue (getBitWidth ());
1372
+
1359
1373
// We split up the LHS and RHS into positive and negative components
1360
1374
// and then also compute the positive and negative components of the result
1361
1375
// separately by combining division results with the appropriate signs.
1362
- APInt Zero = APInt::getZero (getBitWidth ());
1363
- APInt SignedMin = APInt::getSignedMinValue (getBitWidth ());
1364
- // There are no positive 1-bit values. The 1 would get interpreted as -1.
1365
- ConstantRange PosFilter =
1366
- getBitWidth () == 1 ? getEmpty ()
1367
- : ConstantRange (APInt (getBitWidth (), 1 ), SignedMin);
1368
- ConstantRange NegFilter (SignedMin, Zero);
1369
- ConstantRange PosL = intersectWith (PosFilter);
1370
- ConstantRange NegL = intersectWith (NegFilter);
1371
- ConstantRange PosR = RHS.intersectWith (PosFilter);
1372
- ConstantRange NegR = RHS.intersectWith (NegFilter);
1376
+ auto [PosL, NegL] = splitPosNeg ();
1377
+ auto [PosR, NegR] = RHS.splitPosNeg ();
1373
1378
1374
1379
ConstantRange PosRes = getEmpty ();
1375
1380
if (!PosL.isEmptySet () && !PosR.isEmptySet ())
0 commit comments