Index: llvm/lib/IR/ConstantRange.cpp =================================================================== --- llvm/lib/IR/ConstantRange.cpp +++ llvm/lib/IR/ConstantRange.cpp @@ -1478,6 +1478,14 @@ APInt OtherMax = Other.getUnsignedMax(); + bool Neg = false; + if (getSingleElement() && isAllNegative()) { + // Negative the number to easily calculate its shifted value. + Neg = true; + Min = -Min; + Max = -Max; + } + // There's overflow! if (OtherMax.ugt(Max.countl_zero())) return getFull(); @@ -1487,6 +1495,14 @@ Min <<= Other.getUnsignedMin(); Max <<= OtherMax; + if (Neg) { + // For negitive value c, its shifted range is [-((-c) <