// possible shifts.
APInt MaxShiftAmount = RHS.getMaxValue();
if (!LHS.isUnknown()) {
- uint64_t ShiftAmtZeroMask = (~RHS.Zero).getZExtValue();
- uint64_t ShiftAmtOneMask = RHS.One.getZExtValue();
+ uint64_t ShiftAmtZeroMask = (~RHS.Zero).zextOrTrunc(64).getZExtValue();
+ uint64_t ShiftAmtOneMask = RHS.One.zextOrTrunc(64).getZExtValue();
assert(MinShiftAmount.ult(MaxShiftAmount) && "Illegal shift range");
Known.Zero.setAllBits();
Known.One.setAllBits();
// possible shifts.
APInt MaxShiftAmount = RHS.getMaxValue();
if (!LHS.isUnknown()) {
- uint64_t ShiftAmtZeroMask = (~RHS.Zero).getZExtValue();
- uint64_t ShiftAmtOneMask = RHS.One.getZExtValue();
+ uint64_t ShiftAmtZeroMask = (~RHS.Zero).zextOrTrunc(64).getZExtValue();
+ uint64_t ShiftAmtOneMask = RHS.One.zextOrTrunc(64).getZExtValue();
assert(MinShiftAmount.ult(MaxShiftAmount) && "Illegal shift range");
Known.Zero.setAllBits();
Known.One.setAllBits();
// possible shifts.
APInt MaxShiftAmount = RHS.getMaxValue();
if (!LHS.isUnknown()) {
- uint64_t ShiftAmtZeroMask = (~RHS.Zero).getZExtValue();
- uint64_t ShiftAmtOneMask = RHS.One.getZExtValue();
+ uint64_t ShiftAmtZeroMask = (~RHS.Zero).zextOrTrunc(64).getZExtValue();
+ uint64_t ShiftAmtOneMask = RHS.One.zextOrTrunc(64).getZExtValue();
assert(MinShiftAmount.ult(MaxShiftAmount) && "Illegal shift range");
Known.Zero.setAllBits();
Known.One.setAllBits();
[](const APInt &N) { return N * N; }, checkCorrectnessOnlyUnary);
}
+TEST(KnownBitsTest, WideShifts) {
+ unsigned BitWidth = 128;
+ KnownBits Unknown(BitWidth);
+ KnownBits AllOnes = KnownBits::makeConstant(APInt::getAllOnes(BitWidth));
+
+ KnownBits ShlResult(BitWidth);
+ ShlResult.makeNegative();
+ EXPECT_EQ(KnownBits::shl(AllOnes, Unknown), ShlResult);
+ KnownBits LShrResult(BitWidth);
+ LShrResult.One.setBit(0);
+ EXPECT_EQ(KnownBits::lshr(AllOnes, Unknown), LShrResult);
+ EXPECT_EQ(KnownBits::ashr(AllOnes, Unknown), AllOnes);
+}
+
TEST(KnownBitsTest, ICmpExhaustive) {
unsigned Bits = 4;
ForeachKnownBits(Bits, [&](const KnownBits &Known1) {