@@ -162,6 +162,9 @@ define void @foo(i8 %v0) {
162
162
EXPECT_EQ (Diffs.size (), 1u );
163
163
const sandboxir::Interval<sandboxir::Instruction> &Diff = Diffs[0 ];
164
164
EXPECT_THAT (getPtrVec (Diff), testing::ElementsAre (I0, I1, I2, Ret));
165
+
166
+ // Check getSingleDiff().
167
+ EXPECT_EQ (I0Ret.getSingleDiff (Empty), Diff);
165
168
}
166
169
{
167
170
// Check [] - [I0,Ret]
@@ -171,6 +174,9 @@ define void @foo(i8 %v0) {
171
174
EXPECT_EQ (Diffs.size (), 1u );
172
175
const sandboxir::Interval<sandboxir::Instruction> &Diff = Diffs[0 ];
173
176
EXPECT_TRUE (Diff.empty ());
177
+
178
+ // Check getSingleDiff().
179
+ EXPECT_EQ (Empty.getSingleDiff (I0Ret), Diff);
174
180
}
175
181
{
176
182
// Check [I0,Ret] - [I0].
@@ -180,6 +186,9 @@ define void @foo(i8 %v0) {
180
186
EXPECT_EQ (Diffs.size (), 1u );
181
187
const sandboxir::Interval<sandboxir::Instruction> &Diff = Diffs[0 ];
182
188
EXPECT_THAT (getPtrVec (Diff), testing::ElementsAre (I1, I2, Ret));
189
+
190
+ // Check getSingleDiff().
191
+ EXPECT_EQ (I0Ret.getSingleDiff (I0I0), Diff);
183
192
}
184
193
{
185
194
// Check [I0,Ret] - [I1].
@@ -191,6 +200,11 @@ define void @foo(i8 %v0) {
191
200
EXPECT_THAT (getPtrVec (Diff0), testing::ElementsAre (I0));
192
201
const sandboxir::Interval<sandboxir::Instruction> &Diff1 = Diffs[1 ];
193
202
EXPECT_THAT (getPtrVec (Diff1), testing::ElementsAre (I2, Ret));
203
+
204
+ #ifndef NDEBUG
205
+ // Check getSingleDiff().
206
+ EXPECT_DEATH (I0Ret.getSingleDiff (I1I1), " .*single.*" );
207
+ #endif // NDEBUG
194
208
}
195
209
}
196
210
@@ -249,3 +263,52 @@ define void @foo(i8 %v0) {
249
263
EXPECT_THAT (getPtrVec (Intersection), testing::ElementsAre (I1));
250
264
}
251
265
}
266
+
267
+ TEST_F (IntervalTest, UnionInterval) {
268
+ parseIR (C, R"IR(
269
+ define void @foo(i8 %v0) {
270
+ %I0 = add i8 %v0, %v0
271
+ %I1 = add i8 %v0, %v0
272
+ %I2 = add i8 %v0, %v0
273
+ ret void
274
+ }
275
+ )IR" );
276
+ Function &LLVMF = *M->getFunction (" foo" );
277
+ sandboxir::Context Ctx (C);
278
+ auto &F = *Ctx.createFunction (&LLVMF);
279
+ auto *BB = &*F.begin ();
280
+ auto It = BB->begin ();
281
+ auto *I0 = &*It++;
282
+ auto *I1 = &*It++;
283
+ [[maybe_unused]] auto *I2 = &*It++;
284
+ auto *Ret = &*It++;
285
+
286
+ {
287
+ // Check [I0] unionInterval [I2].
288
+ sandboxir::Interval<sandboxir::Instruction> I0I0 (I0, I0);
289
+ sandboxir::Interval<sandboxir::Instruction> I2I2 (I2, I2);
290
+ auto SingleUnion = I0I0.getUnionInterval (I2I2);
291
+ EXPECT_THAT (getPtrVec (SingleUnion), testing::ElementsAre (I0, I1, I2));
292
+ }
293
+ {
294
+ // Check [I0] unionInterval Empty.
295
+ sandboxir::Interval<sandboxir::Instruction> I0I0 (I0, I0);
296
+ sandboxir::Interval<sandboxir::Instruction> Empty;
297
+ auto SingleUnion = I0I0.getUnionInterval (Empty);
298
+ EXPECT_THAT (getPtrVec (SingleUnion), testing::ElementsAre (I0));
299
+ }
300
+ {
301
+ // Check [I0,I1] unionInterval [I1].
302
+ sandboxir::Interval<sandboxir::Instruction> I0I1 (I0, I1);
303
+ sandboxir::Interval<sandboxir::Instruction> I1I1 (I1, I1);
304
+ auto SingleUnion = I0I1.getUnionInterval (I1I1);
305
+ EXPECT_THAT (getPtrVec (SingleUnion), testing::ElementsAre (I0, I1));
306
+ }
307
+ {
308
+ // Check [I2,Ret] unionInterval [I0].
309
+ sandboxir::Interval<sandboxir::Instruction> I2Ret (I2, Ret);
310
+ sandboxir::Interval<sandboxir::Instruction> I0I0 (I0, I0);
311
+ auto SingleUnion = I2Ret.getUnionInterval (I0I0);
312
+ EXPECT_THAT (getPtrVec (SingleUnion), testing::ElementsAre (I0, I1, I2, Ret));
313
+ }
314
+ }
0 commit comments