This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Move LowerSwitch pass to CodeGenPrepare.
ClosedPublic

Authored by cdevadas on Jul 10 2020, 12:35 PM.

Details

Summary

It is possible that LowerSwitch pass leaves certain blocks
unreachable from the entry. If not removed, these dead blocks
can cause undefined behavior in the subsequent passes.
It caused a crash in the AMDGPU backend after the instruction
selection when a PHI node has its incoming values coming from
these unreachable blocks.

In the AMDGPU pass flow, the last invocation of UnreachableBlockElim
precedes where LowerSwitch is currently placed and eventually
missed out on the opportunity to get these blocks eliminated.
This patch ensures that LowerSwitch pass get inserted earlier
to make use of the existing unreachable block elimination pass.

Diff Detail

Event Timeline

cdevadas created this revision.Jul 10 2020, 12:35 PM
arsenm added inline comments.Jul 10 2020, 3:01 PM
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
790

Can you add a comment for why this is here

llvm/test/CodeGen/AMDGPU/switch-default-block-unreachable.ll
7

typo soonafter

cdevadas updated this revision to Diff 277193.Jul 10 2020, 7:10 PM

Incorporated the suggestions.

sameerds added inline comments.Jul 10 2020, 9:41 PM
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
790

The comment shouldn't record where the pass used to be. That is all in git history. But it should explain why this point is the correct place in the flow. Consider it as hint you would want to leave a future programmer if they discovered a reason to move the pass yet again.

From the description: "This patch inserts the Lowerswitch pass in an appropriate place to ensure any dead blocks resulting from the transformation will be removed"

This change is not really about one transformation (LowerSwitch). It's about generally protecting the backend from unreachable blocks, no matter where they originate. So a better explanation of why this is the "appropriate place" will be useful.

cdevadas updated this revision to Diff 277230.Jul 11 2020, 3:25 AM
cdevadas edited the summary of this revision. (Show Details)

Expanded the comment.

sameerds accepted this revision.Jul 11 2020, 3:45 AM

LGTM!

This revision is now accepted and ready to land.Jul 11 2020, 3:45 AM
This revision was automatically updated to reflect the committed changes.