Index: llvm/lib/IR/ConstantRange.cpp =================================================================== --- llvm/lib/IR/ConstantRange.cpp +++ llvm/lib/IR/ConstantRange.cpp @@ -1477,9 +1477,13 @@ } APInt OtherMax = Other.getUnsignedMax(); + // Make sure single element for negative value just for simplicity, + // otherwise we should checking both Lower and Upper for negative value. + bool Neg = getSingleElement() && isAllNegative() && + OtherMax.ule(Max.abs().countl_zero()); // There's overflow! - if (OtherMax.ugt(Max.countl_zero())) + if (OtherMax.ugt(Max.countl_zero()) && !Neg) return getFull(); // FIXME: implement the other tricky cases @@ -1487,6 +1491,10 @@ Min <<= Other.getUnsignedMin(); Max <<= OtherMax; + // For negitive value c, its shifted range is [c<