@@ -1510,20 +1510,15 @@ ConstantRange ConstantRange::smul_sat(const ConstantRange &Other) const {
1510
1510
// [-1,4) * [-2,3) = min(-1*-2, -1*2, 3*-2, 3*2) = -6.
1511
1511
// Similarly for the upper bound, swapping min for max.
1512
1512
1513
- APInt this_min = getSignedMin (). sext ( getBitWidth () * 2 );
1514
- APInt this_max = getSignedMax (). sext ( getBitWidth () * 2 );
1515
- APInt Other_min = Other.getSignedMin (). sext ( getBitWidth () * 2 );
1516
- APInt Other_max = Other.getSignedMax (). sext ( getBitWidth () * 2 );
1513
+ APInt Min = getSignedMin ();
1514
+ APInt Max = getSignedMax ();
1515
+ APInt OtherMin = Other.getSignedMin ();
1516
+ APInt OtherMax = Other.getSignedMax ();
1517
1517
1518
- auto L = {this_min * Other_min, this_min * Other_max, this_max * Other_min ,
1519
- this_max * Other_max };
1518
+ auto L = {Min. smul_sat (OtherMin), Min. smul_sat (OtherMax) ,
1519
+ Max. smul_sat (OtherMin), Max. smul_sat (OtherMax) };
1520
1520
auto Compare = [](const APInt &A, const APInt &B) { return A.slt (B); };
1521
-
1522
- // Note that we wanted to perform signed saturating multiplication,
1523
- // so since we performed plain multiplication in twice the bitwidth,
1524
- // we need to perform signed saturating truncation.
1525
- return getNonEmpty (std::min (L, Compare).truncSSat (getBitWidth ()),
1526
- std::max (L, Compare).truncSSat (getBitWidth ()) + 1 );
1521
+ return getNonEmpty (std::min (L, Compare), std::max (L, Compare) + 1 );
1527
1522
}
1528
1523
1529
1524
ConstantRange ConstantRange::ushl_sat (const ConstantRange &Other) const {
0 commit comments