This is an archive of the discontinued LLVM Phabricator instance.

[amdgpu] Remove the GlobalDCE pass prior to the internalization pass.
ClosedPublic

Authored by hliao on Jul 7 2021, 1:51 PM.

Details

Summary
  • In D98783, an extra GlobalDCE pass is inserted before the internalization pass to ensure a global variable without users could be internalized even if there are dead users. Instead of inserting a dedicated optimization pass, the dead user checking, i.e. 'use_empty()', should be preceeded with constant dead user removal to ensure an accurate result.

Diff Detail

Event Timeline

hliao created this revision.Jul 7 2021, 1:51 PM
hliao requested review of this revision.Jul 7 2021, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2021, 1:51 PM
rampitec added inline comments.Jul 7 2021, 1:57 PM
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
434

Maybe do this in the InternalizePass itself? This is a predicate function and it is not expected to change the IR.

hliao added a comment.Jul 7 2021, 1:57 PM

Instead of inserting GlobalDCE to remove all constant users, call 'removeDeadConstantUsers' directly before 'use_empty' check. That should be the standard way to check whether a global is still in use.

hliao added inline comments.Jul 7 2021, 2:01 PM
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
434

In fact, even there are dead constants removed, the IR won't be changed. IR printer won't be able to print those dead constant users from this GV.

foad accepted this revision.Jul 8 2021, 2:02 AM
foad added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
434

Agreed, I think this is the right way to do this.

This revision is now accepted and ready to land.Jul 8 2021, 2:02 AM