Skip to content

Commit 9d96d01

Browse files
committed
[IR] Add offset stripping test with mixed const/variable offsets (NFC)
Regression test for: a7edc95#commitcomment-163691175
1 parent 9115bef commit 9d96d01

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

llvm/unittests/IR/InstructionsTest.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,5 +1935,22 @@ TEST(InstructionsTest, CmpPredicate) {
19351935
EXPECT_EQ(P2, R2);
19361936
}
19371937

1938+
TEST(InstructionsTest, StripAndAccumulateConstantOffset) {
1939+
LLVMContext C;
1940+
DataLayout DL;
1941+
std::unique_ptr<Module> M = parseIR(C, R"(
1942+
define void @foo(ptr %ptr, i64 %offset) {
1943+
%gep = getelementptr inbounds [1 x i8], ptr %ptr, i64 4, i64 %offset
1944+
ret void
1945+
})");
1946+
ASSERT_TRUE(M);
1947+
Value *GEP = &M->getFunction("foo")->getEntryBlock().front();
1948+
APInt Offset(DL.getIndexTypeSizeInBits(GEP->getType()), 0);
1949+
Value *Stripped = GEP->stripAndAccumulateConstantOffsets(
1950+
DL, Offset, /*AllowNonInBounds=*/true);
1951+
EXPECT_EQ(Stripped, GEP);
1952+
EXPECT_TRUE(Offset.isZero());
1953+
}
1954+
19381955
} // end anonymous namespace
19391956
} // end namespace llvm

0 commit comments

Comments
 (0)