This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fix const folding of switched with default case
ClosedPublic

Authored by danilaml on May 30 2022, 6:41 AM.

Details

Summary

In case phi was in the default block it could lead to multi-edge.
Fixes #55721.

Diff Detail

Event Timeline

danilaml created this revision.May 30 2022, 6:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 6:41 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
danilaml requested review of this revision.May 30 2022, 6:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 6:41 AM
nikic added inline comments.May 30 2022, 6:51 AM
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
1308

I don't think this is sufficient. Can you please add a test where the default doesn't directly go to the phi block, but have one dummy block in between? (That is, go to a sw.19 block from both 19 and default.)

I think the right fix would be adding a ++SuccCount[SI->getDefaultDest()].

danilaml added inline comments.May 30 2022, 7:51 AM
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
1308

I'll add this test case, but I'm pretty sure that this is covered by the dominance check

DT.dominates(BasicBlockEdge(IDom, It->second),
                          BasicBlockEdge(Pred, BB));

I think this check will only succeed when both edges are the "same".

Then again, I think your proposed fix would work as well (at the expense of slightly more work), so I can switch to it.

danilaml updated this revision to Diff 432939.May 30 2022, 8:56 AM

Addressed the comments

danilaml marked an inline comment as done.May 30 2022, 8:56 AM
nikic accepted this revision.May 30 2022, 1:27 PM

LGTM

This revision is now accepted and ready to land.May 30 2022, 1:27 PM
This revision was landed with ongoing or failed builds.May 31 2022, 5:14 AM
This revision was automatically updated to reflect the committed changes.