Skip to content

Commit 4ee240b

Browse files
committed
[NFC] [ValueTracking] Add unittest for haveNoCommonBitsSet
1 parent 3e19ba3 commit 4ee240b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

llvm/unittests/Analysis/ValueTrackingTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,28 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsCrash) {
17251725
A, M->getDataLayout(), /* Depth */ 0, &AC, F->front().getTerminator());
17261726
}
17271727

1728+
TEST_F(ValueTrackingTest, HaveNoCommonBitsSet) {
1729+
{
1730+
// Check for an inverted mask: (X & ~M) op (Y & M).
1731+
auto M = parseModule(R"(
1732+
define i32 @test(i32 %X, i32 %Y, i32 %M) {
1733+
%1 = xor i32 %M, -1
1734+
%LHS = and i32 %1, %X
1735+
%RHS = and i32 %Y, %M
1736+
%Ret = add i32 %LHS, %RHS
1737+
ret i32 %Ret
1738+
})");
1739+
1740+
F = M->getFunction("test");
1741+
auto *LHS = findInstructionByNameOrNull(F, "LHS");
1742+
auto *RHS = findInstructionByNameOrNull(F, "RHS");
1743+
1744+
const DataLayout &DL = M->getDataLayout();
1745+
EXPECT_TRUE(haveNoCommonBitsSet(LHS, RHS, DL));
1746+
EXPECT_TRUE(haveNoCommonBitsSet(RHS, LHS, DL));
1747+
}
1748+
}
1749+
17281750
class IsBytewiseValueTest : public ValueTrackingTest,
17291751
public ::testing::WithParamInterface<
17301752
std::pair<const char *, const char *>> {

0 commit comments

Comments
 (0)