@@ -50,6 +50,14 @@ struct VecUtilsTest : public testing::Test {
50
50
}
51
51
};
52
52
53
+ sandboxir::BasicBlock &getBasicBlockByName (sandboxir::Function &F,
54
+ StringRef Name) {
55
+ for (sandboxir::BasicBlock &BB : F)
56
+ if (BB.getName () == Name)
57
+ return BB;
58
+ llvm_unreachable (" Expected to find basic block!" );
59
+ }
60
+
53
61
TEST_F (VecUtilsTest, GetNumElements) {
54
62
sandboxir::Context Ctx (C);
55
63
auto *ElemTy = sandboxir::Type::getInt32Ty (Ctx);
@@ -415,21 +423,33 @@ TEST_F(VecUtilsTest, GetLowest) {
415
423
parseIR (R"IR(
416
424
define void @foo(i8 %v) {
417
425
bb0:
418
- %A = add i8 %v, %v
419
- %B = add i8 %v, %v
420
- %C = add i8 %v, %v
426
+ br label %bb1
427
+ bb1:
428
+ %A = add i8 %v, 1
429
+ %B = add i8 %v, 2
430
+ %C = add i8 %v, 3
421
431
ret void
422
432
}
423
433
)IR" );
424
434
Function &LLVMF = *M->getFunction (" foo" );
425
435
426
436
sandboxir::Context Ctx (C);
427
437
auto &F = *Ctx.createFunction (&LLVMF);
428
- auto &BB = *F.begin ();
429
- auto It = BB.begin ();
430
- auto *IA = &*It++;
431
- auto *IB = &*It++;
432
- auto *IC = &*It++;
438
+ auto &BB0 = getBasicBlockByName (F, " bb0" );
439
+ auto It = BB0.begin ();
440
+ auto *BB0I = cast<sandboxir::BranchInst>(&*It++);
441
+
442
+ auto &BB = getBasicBlockByName (F, " bb1" );
443
+ It = BB.begin ();
444
+ auto *IA = cast<sandboxir::Instruction>(&*It++);
445
+ auto *C1 = cast<sandboxir::Constant>(IA->getOperand (1 ));
446
+ auto *IB = cast<sandboxir::Instruction>(&*It++);
447
+ auto *C2 = cast<sandboxir::Constant>(IB->getOperand (1 ));
448
+ auto *IC = cast<sandboxir::Instruction>(&*It++);
449
+ auto *C3 = cast<sandboxir::Constant>(IC->getOperand (1 ));
450
+ // Check getLowest(ArrayRef<Instruction *>)
451
+ SmallVector<sandboxir::Instruction *> A ({IA});
452
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (A), IA);
433
453
SmallVector<sandboxir::Instruction *> ABC ({IA, IB, IC});
434
454
EXPECT_EQ (sandboxir::VecUtils::getLowest (ABC), IC);
435
455
SmallVector<sandboxir::Instruction *> ACB ({IA, IC, IB});
@@ -438,6 +458,27 @@ define void @foo(i8 %v) {
438
458
EXPECT_EQ (sandboxir::VecUtils::getLowest (CAB), IC);
439
459
SmallVector<sandboxir::Instruction *> CBA ({IC, IB, IA});
440
460
EXPECT_EQ (sandboxir::VecUtils::getLowest (CBA), IC);
461
+
462
+ // Check getLowest(ArrayRef<Value *>)
463
+ SmallVector<sandboxir::Value *> C1Only ({C1});
464
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (C1Only), nullptr );
465
+ SmallVector<sandboxir::Value *> AOnly ({IA});
466
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (AOnly), IA);
467
+ SmallVector<sandboxir::Value *> AC1 ({IA, C1});
468
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (AC1), IA);
469
+ SmallVector<sandboxir::Value *> C1A ({C1, IA});
470
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (C1A), IA);
471
+ SmallVector<sandboxir::Value *> AC1B ({IA, C1, IB});
472
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (AC1B), IB);
473
+ SmallVector<sandboxir::Value *> ABC1 ({IA, IB, C1});
474
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (ABC1), IB);
475
+ SmallVector<sandboxir::Value *> AC1C2 ({IA, C1, C2});
476
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (AC1C2), IA);
477
+ SmallVector<sandboxir::Value *> C1C2C3 ({C1, C2, C3});
478
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (C1C2C3), nullptr );
479
+
480
+ SmallVector<sandboxir::Value *> DiffBBs ({BB0I, IA});
481
+ EXPECT_EQ (sandboxir::VecUtils::getLowest (DiffBBs), nullptr );
441
482
}
442
483
443
484
TEST_F (VecUtilsTest, GetCommonScalarType) {
0 commit comments