diff --git a/llvm/unittests/Support/KnownBitsTest.h b/llvm/unittests/Support/KnownBitsTest.h index 556da2b9ecdad..974051891d48e 100644 --- a/llvm/unittests/Support/KnownBitsTest.h +++ b/llvm/unittests/Support/KnownBitsTest.h @@ -34,13 +34,13 @@ template void ForeachKnownBits(unsigned Bits, FnTy Fn) { template void ForeachNumInKnownBits(const KnownBits &Known, FnTy Fn) { unsigned Bits = Known.getBitWidth(); - unsigned Max = 1 << Bits; + assert(Bits < 32); + unsigned Max = 1u << Bits; + unsigned Zero = Known.Zero.getZExtValue(); + unsigned One = Known.One.getZExtValue(); for (unsigned N = 0; N < Max; ++N) { - APInt Num(Bits, N); - if ((Num & Known.Zero) != 0 || (~Num & Known.One) != 0) - continue; - - Fn(Num); + if ((N & Zero) == 0 && (~N & One) == 0) + Fn(APInt(Bits, N)); } }