@@ -386,6 +386,49 @@ define void @foo(i8 %v) {
386
386
" .*already.*" );
387
387
}
388
388
389
+ // Check that Aux automatically drops instructions that get deleted.
390
+ TEST_F (RegionTest, AuxDeleteInstr) {
391
+ parseIR (C, R"IR(
392
+ define void @foo(i8 %v) {
393
+ %Add0 = add i8 %v, 0, !sandboxvec !0, !sandboxaux !1
394
+ %Add1 = add i8 %v, 1, !sandboxvec !0, !sandboxaux !2
395
+ %Add2 = add i8 %v, 2, !sandboxvec !0, !sandboxaux !3
396
+ %Add3 = add i8 %v, 2, !sandboxvec !0, !sandboxaux !4
397
+ ret void
398
+ }
399
+
400
+ !0 = distinct !{!"sandboxregion"}
401
+ !1 = !{i32 0}
402
+ !2 = !{i32 1}
403
+ !3 = !{i32 2}
404
+ !4 = !{i32 3}
405
+ )IR" );
406
+ llvm::Function *LLVMF = &*M->getFunction (" foo" );
407
+ sandboxir::Context Ctx (C);
408
+ auto *F = Ctx.createFunction (LLVMF);
409
+ auto *BB = &*F->begin ();
410
+ auto It = BB->begin ();
411
+ auto *Add0 = &*It++;
412
+ auto *Add1 = &*It++;
413
+ auto *Add2 = &*It++;
414
+ auto *Add3 = &*It++;
415
+ SmallVector<std::unique_ptr<sandboxir::Region>> Regions =
416
+ sandboxir::Region::createRegionsFromMD (*F, *TTI);
417
+ auto &R = *Regions[0 ];
418
+ EXPECT_THAT (R.getAux (), testing::ElementsAre (Add0, Add1, Add2, Add3));
419
+ // Now delete Add1 and check that Aux contains nullptr instead of Add1.
420
+ Add2->eraseFromParent ();
421
+ EXPECT_THAT (R.getAux (), testing::ElementsAre (Add0, Add1, Add3));
422
+ {
423
+ // Check that metadata have also been updated.
424
+ // But first drop Add3 to create a legal Aux vector with no gaps.
425
+ Add3->eraseFromParent ();
426
+ SmallVector<std::unique_ptr<sandboxir::Region>> Regions =
427
+ sandboxir::Region::createRegionsFromMD (*F, *TTI);
428
+ EXPECT_THAT (Regions[0 ]->getAux (), testing::ElementsAre (Add0, Add1));
429
+ }
430
+ }
431
+
389
432
TEST_F (RegionTest, AuxRoundTrip) {
390
433
parseIR (C, R"IR(
391
434
define i8 @foo(i8 %v0, i8 %v1) {
0 commit comments