This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix iterating in SIFixSGPRCopies
ClosedPublic

Authored by sebastian-ne on Nov 2 2020, 4:56 AM.

Details

Summary

The insertion of waterfall loops splits the current basic block into
three blocks. So the basic block that we iterate over must be updated.

This failed assert(!NodePtr->isKnownSentinel()) in ilist_iterator for
divergent calls in branches before.

Diff Detail

Event Timeline

sebastian-ne created this revision.Nov 2 2020, 4:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2020, 4:56 AM
sebastian-ne requested review of this revision.Nov 2 2020, 4:56 AM
arsenm added inline comments.Nov 2 2020, 9:24 AM
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
659–660

I'm not sure this is an entirely reliable way to get the parent if the instruction was erased (I guess this doesn't happen for any of the copy-like cases). Other places that change the control flow in situations like this return the new block from the modifying function and check if it matches the original

sebastian-ne added inline comments.Nov 3 2020, 5:13 AM
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
659–660

That means loadSRsrcFromVGPR, SIInstrInfo::legalizeOperands and SIInstrInfo::moveToVALU should return the newly created basic block?

arsenm added inline comments.Nov 3 2020, 6:43 AM
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
659–660

Yes

Return new basic block from SIInstrInfo functions.

arsenm added inline comments.Nov 4 2020, 9:09 AM
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
695

The NewBB &&s are redundant

sebastian-ne added inline comments.Nov 4 2020, 9:36 AM
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
695

Thank you for your reviews.

moveToVALU returns nullptr if nothing changed. Without this check, MBB would be set to nullptr.

arsenm accepted this revision.Nov 4 2020, 9:36 AM
This revision is now accepted and ready to land.Nov 4 2020, 9:36 AM
This revision was landed with ongoing or failed builds.Nov 4 2020, 9:43 AM
This revision was automatically updated to reflect the committed changes.