diff options
author | Stephen Senran Zhang <zsrkmyn@gmail.com> | 2025-01-01 10:40:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-31 18:40:17 -0800 |
commit | 2feffecb8853b1cdd38a0653df63d70412e65c12 (patch) | |
tree | 9fac36059f0115ba1ce6263abcb14bf0a211941e /llvm/unittests/IR/ConstantRangeTest.cpp | |
parent | 1d0f40ba05b76ff028c69054899f88f1c7452b4b (diff) | |
download | llvm-2feffecb8853b1cdd38a0653df63d70412e65c12.zip llvm-2feffecb8853b1cdd38a0653df63d70412e65c12.tar.gz llvm-2feffecb8853b1cdd38a0653df63d70412e65c12.tar.bz2 |
[ConstantRange] Estimate tighter lower (upper) bounds for masked binary and (or) (#120352)
Fixes #118108.
Co-author: Yingwei Zheng (@dtcxzyw)
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r-- | llvm/unittests/IR/ConstantRangeTest.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index e1d9b3e..c390ffe 100644 --- a/llvm/unittests/IR/ConstantRangeTest.cpp +++ b/llvm/unittests/IR/ConstantRangeTest.cpp @@ -2720,6 +2720,37 @@ 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); + + ConstantRange RMaskedL3(APInt(4, 0b0011u), APInt(4, 0)); + ConstantRange RMaskedR3(APInt(4, 0b1011u), APInt(4, 0)); + APInt Zero_4(4, 0); + EXPECT_EQ(RMaskedL3.binaryAnd(RMaskedR3).getLower().uge(Zero_4), true); + EXPECT_EQ(RMaskedR3.binaryAnd(RMaskedL3).getLower().uge(Zero_4), true); + + // wrapped set + APInt NegSeven(4, 9); // Also -7 + ConstantRange RMaskedL4(NegSeven, APInt(4, 1)); + ConstantRange RMaskedR4(NegSeven, APInt(4, 0)); + EXPECT_EQ(RMaskedL4.binaryAnd(RMaskedR4).contains(Zero_4), true); + EXPECT_EQ(RMaskedR4.binaryAnd(RMaskedL4).contains(Zero_4), true); + EXPECT_EQ(RMaskedL4.binaryAnd(RMaskedR4).contains(NegSeven), true); + EXPECT_EQ(RMaskedR4.binaryAnd(RMaskedL4).contains(NegSeven), true); + TestBinaryOpExhaustive( [](const ConstantRange &CR1, const ConstantRange &CR2) { return CR1.binaryAnd(CR2); |