[llvm] 710c2f0 - [SandboxIR][Tracker] Test UncondBrInst CondBrInst setters (#187549)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 24 15:49:17 PDT 2026
Author: vporpo
Date: 2026-03-24T15:49:12-07:00
New Revision: 710c2f0ca5a4e0b93eda0e014af24ed09946f5c5
URL: https://github.com/llvm/llvm-project/commit/710c2f0ca5a4e0b93eda0e014af24ed09946f5c5
DIFF: https://github.com/llvm/llvm-project/commit/710c2f0ca5a4e0b93eda0e014af24ed09946f5c5.diff
LOG: [SandboxIR][Tracker] Test UncondBrInst CondBrInst setters (#187549)
This checks the `setCondition()` and `setSuccessor()` setters introduced
in #187196.
Added:
Modified:
llvm/unittests/SandboxIR/TrackerTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/SandboxIR/TrackerTest.cpp b/llvm/unittests/SandboxIR/TrackerTest.cpp
index 78919335a6a85..10abd07a19302 100644
--- a/llvm/unittests/SandboxIR/TrackerTest.cpp
+++ b/llvm/unittests/SandboxIR/TrackerTest.cpp
@@ -630,6 +630,84 @@ define void @foo(i8 %arg0, i8 %arg1) {
EXPECT_EQ(Call->getCalledFunction(), Bar1F);
}
+TEST_F(TrackerTest, UncondBrSetters) {
+ parseIR(C, R"IR(
+define void @foo() {
+ bb0:
+ br label %bb1
+ bb1:
+ ret void
+ bb2:
+ ret void
+}
+)IR");
+ Function &LLVMF = *M->getFunction("foo");
+ sandboxir::Context Ctx(C);
+ [[maybe_unused]] auto &F = *Ctx.createFunction(&LLVMF);
+ auto *BB0 = cast<sandboxir::BasicBlock>(
+ Ctx.getValue(getBasicBlockByName(LLVMF, "bb0")));
+ auto *BB1 = cast<sandboxir::BasicBlock>(
+ Ctx.getValue(getBasicBlockByName(LLVMF, "bb1")));
+ auto *BB2 = cast<sandboxir::BasicBlock>(
+ Ctx.getValue(getBasicBlockByName(LLVMF, "bb2")));
+ auto It = BB0->begin();
+ auto *Br = cast<sandboxir::UncondBrInst>(&*It++);
+
+ // Check setSuccessor().
+ Ctx.save();
+ EXPECT_EQ(Br->getSuccessor(), BB1);
+ Br->setSuccessor(BB2);
+ EXPECT_EQ(Br->getSuccessor(), BB2);
+ Ctx.revert();
+ EXPECT_EQ(Br->getSuccessor(), BB1);
+}
+
+TEST_F(TrackerTest, CondBrSetters) {
+ parseIR(C, R"IR(
+define void @foo(i1 %cond0, i1 %cond2) {
+ bb0:
+ br i1 %cond0, label %bb1, label %bb2
+ bb1:
+ ret void
+ bb2:
+ ret void
+}
+)IR");
+ Function &LLVMF = *M->getFunction("foo");
+ sandboxir::Context Ctx(C);
+ [[maybe_unused]] auto &F = *Ctx.createFunction(&LLVMF);
+ auto *Cond0 = F.getArg(0);
+ auto *Cond1 = F.getArg(1);
+ auto *BB0 = cast<sandboxir::BasicBlock>(
+ Ctx.getValue(getBasicBlockByName(LLVMF, "bb0")));
+ auto *BB1 = cast<sandboxir::BasicBlock>(
+ Ctx.getValue(getBasicBlockByName(LLVMF, "bb1")));
+ auto *BB2 = cast<sandboxir::BasicBlock>(
+ Ctx.getValue(getBasicBlockByName(LLVMF, "bb2")));
+ auto It = BB0->begin();
+ auto *Br = cast<sandboxir::CondBrInst>(&*It++);
+
+ // Check setSuccessor().
+ Ctx.save();
+ EXPECT_EQ(Br->getSuccessor(0), BB1);
+ EXPECT_EQ(Br->getSuccessor(1), BB2);
+ Br->setSuccessor(0, BB2);
+ Br->setSuccessor(1, BB1);
+ EXPECT_EQ(Br->getSuccessor(0), BB2);
+ EXPECT_EQ(Br->getSuccessor(1), BB1);
+ Ctx.revert();
+ EXPECT_EQ(Br->getSuccessor(0), BB1);
+ EXPECT_EQ(Br->getSuccessor(1), BB2);
+
+ // Check setCondition().
+ Ctx.save();
+ EXPECT_EQ(Br->getCondition(), Cond0);
+ Br->setCondition(Cond1);
+ EXPECT_EQ(Br->getCondition(), Cond1);
+ Ctx.revert();
+ EXPECT_EQ(Br->getCondition(), Cond0);
+}
+
TEST_F(TrackerTest, InvokeSetters) {
parseIR(C, R"IR(
define void @foo(i8 %arg) {
More information about the llvm-commits
mailing list