[llvm] [SandboxIR] Implement missing PHINode functions (PR #101734)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 11:16:11 PDT 2024


================
@@ -1974,7 +1975,19 @@ define void @foo(i32 %arg) {
   EXPECT_EQ(PHI->hasConstantOrUndefValue(), LLVMPHI->hasConstantOrUndefValue());
   // Check isComplete().
   EXPECT_EQ(PHI->isComplete(), LLVMPHI->isComplete());
-
+  // Check replaceIncomingBlockWith
+  OrigBB = PHI->getIncomingBlock(0);
+  auto *NewBB = BB2;
+  EXPECT_NE(NewBB, OrigBB);
+  PHI->replaceIncomingBlockWith(OrigBB, NewBB);
+  EXPECT_EQ(PHI->getIncomingBlock(0), NewBB);
+  // Check replaceIncomingValueIf
+  EXPECT_EQ(PHI->getNumIncomingValues(), 3u);
+  PHI->removeIncomingValueIf([&](unsigned Idx) {
+    return PHI->getIncomingBlock(Idx) == NewBB;
+  });
+  EXPECT_EQ(PHI->getNumIncomingValues(), 1u);
+  EXPECT_EQ(PHI->getIncomingBlock(0), BB3);
   // Check create().
----------------
vporpo wrote:

I think we should exercise `removeIncomingValueIf()` a bit more. In the existing check we are removing the first two values if I am not mistaken: (NewBB, NewBB, BB3) -> (BB3).
Maybe we should try removing the last incoming value, resulting in an empty PHI, and perhaps a different pattern with gaps, like (A, B, C, D) -> (B, D).

https://github.com/llvm/llvm-project/pull/101734


More information about the llvm-commits mailing list