Skip to content

Commit 2aa1dbf

Browse files
authored
[SandboxIR] Add a test for creating non-contiguous Regions. (#112027)
It checks that a Region can have non-contiguous instructions, and that when iterating through it you don't get the instructions in-between that aren't part of the Region.
1 parent 7f1b465 commit 2aa1dbf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

llvm/unittests/SandboxIR/RegionTest.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,31 @@ define i8 @foo(i8 %v0, i8 %v1) {
108108
EXPECT_THAT(Regions[1]->insts(), testing::UnorderedElementsAre(T1, T2));
109109
}
110110

111+
TEST_F(RegionTest, NonContiguousRegion) {
112+
parseIR(C, R"IR(
113+
define i8 @foo(i8 %v0, i8 %v1) {
114+
%t0 = add i8 %v0, 1, !sandboxvec !0
115+
%t1 = add i8 %t0, %v1
116+
%t2 = add i8 %t1, %v1, !sandboxvec !0
117+
ret i8 %t2
118+
}
119+
120+
!0 = distinct !{!"sandboxregion"}
121+
)IR");
122+
llvm::Function *LLVMF = &*M->getFunction("foo");
123+
sandboxir::Context Ctx(C);
124+
auto *F = Ctx.createFunction(LLVMF);
125+
auto *BB = &*F->begin();
126+
auto It = BB->begin();
127+
auto *T0 = cast<sandboxir::Instruction>(&*It++);
128+
[[maybe_unused]] auto *T1 = cast<sandboxir::Instruction>(&*It++);
129+
auto *T2 = cast<sandboxir::Instruction>(&*It++);
130+
131+
SmallVector<std::unique_ptr<sandboxir::Region>> Regions =
132+
sandboxir::Region::createRegionsFromMD(*F);
133+
EXPECT_THAT(Regions[0]->insts(), testing::UnorderedElementsAre(T0, T2));
134+
}
135+
111136
TEST_F(RegionTest, DumpedMetadata) {
112137
parseIR(C, R"IR(
113138
define i8 @foo(i8 %v0, i8 %v1) {

0 commit comments

Comments
 (0)