Skip to content

Conversation

@Enna1
Copy link
Contributor

@Enna1 Enna1 commented Dec 16, 2025

No description provided.

… delegate the removal directly to the underlying `llvm::PHINode::removeIncomingValueIf`.
@Enna1 Enna1 changed the title [SandboxIR] Refactor SandboxIR::PHINode::removeIncomingValueIf() to delegate the removal directly to the underlying llvm::PHINode::removeIncomingValueIf [SandboxIR] Refactor sandboxir::PHINode::removeIncomingValueIf() to delegate the removal directly to the underlying llvm::PHINode::removeIncomingValueIf Dec 16, 2025
@Enna1 Enna1 requested a review from nikic December 16, 2025 09:03
@Enna1 Enna1 marked this pull request as ready for review December 16, 2025 09:03
@nikic nikic requested a review from vporpo December 16, 2025 09:19
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would actually interfere with #171963, because it uses a removeIncomingValueIf() and removeIncomingValue() use different removal strategies, so I think having a single PHIRemoveIncoming wouldn't be able to cover both?

@Enna1
Copy link
Contributor Author

Enna1 commented Dec 16, 2025

I think this would actually interfere with #171963, because it uses a removeIncomingValueIf() and removeIncomingValue() use different removal strategies, so I think having a single PHIRemoveIncoming wouldn't be able to cover both?

The intention behind this patch was that we don't need having KeepIncomingOrder flag for removeIncomingValue() in #171963 with this patch.

But think about this a bit, this is not enough. as you pointed out, with #171963, removeIncomingValueIf() and removeIncomingValue() will use different removal strategies, so we cannot cover them with a single PHIRemoveIncoming.

If we don't want the KeepIncomingOrder flag for PHINode::removeIncomingValue(), two version PHIRemoveIncoming are needed, we can move the KeepIncomingOrder flag into PHIRemoveIncoming...

What do you think?

@nikic
Copy link
Contributor

nikic commented Dec 16, 2025

If you keep the current removeIncomingValueIf() implementation, wouldn't you only need one implementation because it uses removeIncomingValue() internally? As it already does the walk backwards, it should be compatible with the swapping approach, right?

@Enna1
Copy link
Contributor Author

Enna1 commented Dec 16, 2025

If you keep the current removeIncomingValueIf() implementation, wouldn't you only need one implementation because it uses removeIncomingValue() internally? As it already does the walk backwards, it should be compatible with the swapping approach, right?

// Check replaceIncomingValueIf
EXPECT_EQ(PHI->getNumIncomingValues(), 5u);
auto *RemainBB0 = PHI->getIncomingBlock(0);
auto *RemoveBB0 = PHI->getIncomingBlock(1);
auto *RemainBB1 = PHI->getIncomingBlock(2);
auto *RemoveBB1 = PHI->getIncomingBlock(3);
auto *RemainBB2 = PHI->getIncomingBlock(4);
PHI->removeIncomingValueIf([&](unsigned Idx) {
return PHI->getIncomingBlock(Idx) == RemoveBB0 ||
PHI->getIncomingBlock(Idx) == RemoveBB1;
});
EXPECT_EQ(PHI->getNumIncomingValues(), 3u);
EXPECT_EQ(PHI->getIncomingBlock(0), RemainBB0);
EXPECT_EQ(PHI->getIncomingBlock(1), RemainBB1);
EXPECT_EQ(PHI->getIncomingBlock(2), RemainBB2);

This test expects after removal the order of incoming values remained is preserved.

Current removeIncomingValueIf() implementation call removeIncomingValue() , assertion will fail if removeIncomingValue() switch to the swapping approach.

@nikic
Copy link
Contributor

nikic commented Dec 16, 2025

Wouldn't it be fine to change the test expectation? For SandboxIR, the main thing we care about is that the change can be reliably undone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants