================ @@ -2720,6 +2720,22 @@ TEST_F(ConstantRangeTest, binaryAnd) { EXPECT_EQ(R16_32.binaryAnd(R0_99), R0_32); EXPECT_EQ(R0_99.binaryAnd(R16_32), R0_32); + // 'And' with leading bits are masked (with common leading bits stripped) + ConstantRange RMaskedL(APInt(8, 0b10'00101'1), APInt(8, 0b10'10000'0 + 1)); + ConstantRange RMaskedR(APInt(8, 0b10'11111'0), APInt(8, 0b10'11111'1 + 1)); + EXPECT_EQ(RMaskedL.binaryAnd(RMaskedR).getLower(), APInt(8, 0b10'00101'0)); + EXPECT_EQ(RMaskedR.binaryAnd(RMaskedL).getLower(), APInt(8, 0b10'00101'0)); + + ConstantRange RMaskedL1(APInt(8, 0b00'011'010), APInt(8, 0b00'100'100 + 1)); + ConstantRange RMaskedR1(APInt(8, 0b00'111'010), APInt(8, 0b00'111'110 + 1)); + EXPECT_EQ(RMaskedL1.binaryAnd(RMaskedR1).getLower(), APInt(8, 0b00'011'000)); + EXPECT_EQ(RMaskedR1.binaryAnd(RMaskedL1).getLower(), APInt(8, 0b00'011'000)); + + ConstantRange RMaskedL2(APInt(8, 0b0000'0111u), APInt(8, 0b0000'1101u + 1u)); + ConstantRange RMaskedR2(APInt(8, 0xff), APInt(8, 0)); + EXPECT_EQ(RMaskedL2.binaryAnd(RMaskedR2), RMaskedL2); + EXPECT_EQ(RMaskedR2.binaryAnd(RMaskedL2), RMaskedL2); ---------------- zsrkmyn wrote:
So, should I `EXPECT_GE(lower, 0)` or `EXPECT_EQ(lower, 0)`? I prefer the former, because tests won't fail if the algorithm is further optimized. https://github.com/llvm/llvm-project/pull/120352 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits