Index: llvm/include/llvm/Support/KnownBits.h =================================================================== --- llvm/include/llvm/Support/KnownBits.h +++ llvm/include/llvm/Support/KnownBits.h @@ -415,6 +415,12 @@ return KnownBits(Zero.reverseBits(), One.reverseBits()); } + bool operator==(const KnownBits &Other) const { + return Zero == Other.Zero && One == Other.One; + } + + bool operator!=(const KnownBits &Other) const { return !(*this == Other); } + void print(raw_ostream &OS) const; void dump() const; }; Index: llvm/lib/Support/KnownBits.cpp =================================================================== --- llvm/lib/Support/KnownBits.cpp +++ llvm/lib/Support/KnownBits.cpp @@ -417,9 +417,8 @@ unsigned BitWidth = LHS.getBitWidth(); assert(BitWidth == RHS.getBitWidth() && !LHS.hasConflict() && !RHS.hasConflict() && "Operand mismatch"); - assert( - (!NoUndefSelfMultiply || (LHS.One == RHS.One && LHS.Zero == RHS.Zero)) && - "Self multiplication knownbits mismatch"); + assert((!NoUndefSelfMultiply || LHS == RHS) && + "Self multiplication knownbits mismatch"); // Compute the high known-0 bits by multiplying the unsigned max of each side. // Conservatively, M active bits * N active bits results in M + N bits in the Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1077,7 +1077,7 @@ KnownBits KnownLHS = computeKnownBits(LHS, 0, &Zext); KnownBits KnownRHS = computeKnownBits(RHS, 0, &Zext); - if (KnownLHS.Zero == KnownRHS.Zero && KnownLHS.One == KnownRHS.One) { + if (KnownLHS == KnownRHS) { APInt KnownBits = KnownLHS.Zero | KnownLHS.One; APInt UnknownBit = ~KnownBits; if (UnknownBit.countPopulation() == 1) { Index: llvm/unittests/IR/ConstantRangeTest.cpp =================================================================== --- llvm/unittests/IR/ConstantRangeTest.cpp +++ llvm/unittests/IR/ConstantRangeTest.cpp @@ -2379,8 +2379,7 @@ }); // For an empty CR any result would be legal. if (!CR.isEmptySet()) { - EXPECT_EQ(ExpectedKnown.One, Known.One); - EXPECT_EQ(ExpectedKnown.Zero, Known.Zero); + EXPECT_EQ(ExpectedKnown, Known); } }); } Index: llvm/unittests/Support/KnownBitsTest.cpp =================================================================== --- llvm/unittests/Support/KnownBitsTest.cpp +++ llvm/unittests/Support/KnownBitsTest.cpp @@ -41,10 +41,9 @@ }); }); - KnownBits KnownComputed = KnownBits::computeForAddCarry( - Known1, Known2, KnownCarry); - EXPECT_EQ(Known.Zero, KnownComputed.Zero); - EXPECT_EQ(Known.One, KnownComputed.One); + KnownBits KnownComputed = + KnownBits::computeForAddCarry(Known1, Known2, KnownCarry); + EXPECT_EQ(Known, KnownComputed); }); }); }); @@ -79,10 +78,9 @@ }); }); - KnownBits KnownComputed = KnownBits::computeForAddSub( - IsAdd, /*NSW*/false, Known1, Known2); - EXPECT_EQ(Known.Zero, KnownComputed.Zero); - EXPECT_EQ(Known.One, KnownComputed.One); + KnownBits KnownComputed = + KnownBits::computeForAddSub(IsAdd, /*NSW*/ false, Known1, Known2); + EXPECT_EQ(Known, KnownComputed); // The NSW calculation is not precise, only check that it's // conservatively correct. @@ -201,32 +199,25 @@ }); KnownBits ComputedAnd = Known1 & Known2; - EXPECT_EQ(KnownAnd.Zero, ComputedAnd.Zero); - EXPECT_EQ(KnownAnd.One, ComputedAnd.One); + EXPECT_EQ(KnownAnd, ComputedAnd); KnownBits ComputedOr = Known1 | Known2; - EXPECT_EQ(KnownOr.Zero, ComputedOr.Zero); - EXPECT_EQ(KnownOr.One, ComputedOr.One); + EXPECT_EQ(KnownOr, ComputedOr); KnownBits ComputedXor = Known1 ^ Known2; - EXPECT_EQ(KnownXor.Zero, ComputedXor.Zero); - EXPECT_EQ(KnownXor.One, ComputedXor.One); + EXPECT_EQ(KnownXor, ComputedXor); KnownBits ComputedUMax = KnownBits::umax(Known1, Known2); - EXPECT_EQ(KnownUMax.Zero, ComputedUMax.Zero); - EXPECT_EQ(KnownUMax.One, ComputedUMax.One); + EXPECT_EQ(KnownUMax, ComputedUMax); KnownBits ComputedUMin = KnownBits::umin(Known1, Known2); - EXPECT_EQ(KnownUMin.Zero, ComputedUMin.Zero); - EXPECT_EQ(KnownUMin.One, ComputedUMin.One); + EXPECT_EQ(KnownUMin, ComputedUMin); KnownBits ComputedSMax = KnownBits::smax(Known1, Known2); - EXPECT_EQ(KnownSMax.Zero, ComputedSMax.Zero); - EXPECT_EQ(KnownSMax.One, ComputedSMax.One); + EXPECT_EQ(KnownSMax, ComputedSMax); KnownBits ComputedSMin = KnownBits::smin(Known1, Known2); - EXPECT_EQ(KnownSMin.Zero, ComputedSMin.Zero); - EXPECT_EQ(KnownSMin.One, ComputedSMin.One); + EXPECT_EQ(KnownSMin, ComputedSMin); // The following are conservatively correct, but not guaranteed to be // precise. @@ -476,8 +467,7 @@ KnownBits Baseline; InitKnownBits(Baseline, Input.sextOrTrunc(Size)); Test = Test.sextOrTrunc(Size); - EXPECT_EQ(Test.One, Baseline.One); - EXPECT_EQ(Test.Zero, Baseline.Zero); + EXPECT_EQ(Test, Baseline); } } }