@@ -50,6 +50,14 @@ struct VecUtilsTest : public testing::Test {
5050 }
5151};
5252
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+
5361TEST_F (VecUtilsTest, GetNumElements) {
5462 sandboxir::Context Ctx (C);
5563 auto *ElemTy = sandboxir::Type::getInt32Ty (Ctx);
@@ -415,21 +423,33 @@ TEST_F(VecUtilsTest, GetLowest) {
415423 parseIR (R"IR(
416424define void @foo(i8 %v) {
417425bb0:
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
421431 ret void
422432}
423433)IR" );
424434 Function &LLVMF = *M->getFunction (" foo" );
425435
426436 sandboxir::Context Ctx (C);
427437 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);
433453 SmallVector<sandboxir::Instruction *> ABC ({IA, IB, IC});
434454 EXPECT_EQ (sandboxir::VecUtils::getLowest (ABC), IC);
435455 SmallVector<sandboxir::Instruction *> ACB ({IA, IC, IB});
@@ -438,6 +458,27 @@ define void @foo(i8 %v) {
438458 EXPECT_EQ (sandboxir::VecUtils::getLowest (CAB), IC);
439459 SmallVector<sandboxir::Instruction *> CBA ({IC, IB, IA});
440460 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 );
441482}
442483
443484TEST_F (VecUtilsTest, GetCommonScalarType) {
0 commit comments