[Support] Ensure KnownBits::sextInReg can handle the src == dst sext-in-reg case.

This was resulting in assertions inside APInt::zext that we were extending to the same bitwidth.
This commit is contained in:
Simon Pilgrim 2021-01-14 14:50:09 +00:00
parent 332e220ef4
commit 0b46f19a9e
2 changed files with 6 additions and 2 deletions

View File

@ -85,7 +85,11 @@ KnownBits KnownBits::computeForAddSub(bool Add, bool NSW,
KnownBits KnownBits::sextInReg(unsigned SrcBitWidth) const {
unsigned BitWidth = getBitWidth();
assert(BitWidth >= SrcBitWidth && "Illegal sext-in-register");
assert(0 < SrcBitWidth && SrcBitWidth <= BitWidth &&
"Illegal sext-in-register");
if (SrcBitWidth == BitWidth)
return *this;
// Sign extension. Compute the demanded bits in the result that are not
// present in the input.

View File

@ -427,7 +427,7 @@ TEST(KnownBitsTest, SExtOrTrunc) {
TEST(KnownBitsTest, SExtInReg) {
unsigned Bits = 4;
for (unsigned FromBits = 1; FromBits != Bits; ++FromBits) {
for (unsigned FromBits = 1; FromBits <= Bits; ++FromBits) {
ForeachKnownBits(Bits, [&](const KnownBits &Known) {
APInt CommonOne = APInt::getAllOnesValue(Bits);
APInt CommonZero = APInt::getAllOnesValue(Bits);