Page MenuHomePhabricator

Target hooks for custom COPY insertion.
AcceptedPublic

Authored by alex-t on Tue, Sep 3, 7:58 AM.

Details

Reviewers
rampitec
vpykhtin
Summary

PHI Elimination pass relies on TargetInstrInfo::isBlockPrologue/isTerminator target hooks to determine the COPY insertion points.
In some cases this is not sufficient. Divergent control flow requires instructions that belong to block prologue and consume registers defined by the PHI node in the same block.
2 new hooks were added to allow target to override the default COPY placement if necessary or fall through to the base class method otherwise.

Diff Detail

Event Timeline

alex-t created this revision.Tue, Sep 3, 7:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptTue, Sep 3, 7:58 AM
vpykhtin added inline comments.Tue, Sep 3, 10:19 AM
llvm/lib/CodeGen/PHIElimination.cpp
280

return inserted instruction and assign iterator to it to AfterPHIsIt

410

returned InsertPos and NewSrcInstr is the same, use only returned value, remove reference arg from the interface.

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
6398

use the same name for LastPHIIt arg as in the declaration

6400

auto

6407

search first user from the beginning of the block?

llvm/lib/Target/AMDGPU/SIInstrInfo.h
957

void -> MachineInstr*, remove reference to InsPt

963

remove reference from InsPt

Would be good to have test coverage either in the same patch or have dependent patch explicitly marked as such.

arsenm added inline comments.Tue, Sep 3, 10:41 AM
llvm/include/llvm/CodeGen/TargetInstrInfo.h
1647

Should use Register instead of unsigned

Would be good to have test coverage either in the same patch or have dependent patch explicitly marked as such.

The patch really changes AMDGPU PHI elimination and leaves other targets behavior unaffected.
So the test that I will add make sense for AMDGPU only.
Is it okay?

Would be good to have test coverage either in the same patch or have dependent patch explicitly marked as such.

The patch really changes AMDGPU PHI elimination and leaves other targets behavior unaffected.
So the test that I will add make sense for AMDGPU only.
Is it okay?

Absolutely.

alex-t updated this revision to Diff 218911.Thu, Sep 5, 6:59 AM

Changed according to the reviewers requests. Tests added.

alex-t marked 8 inline comments as done.Thu, Sep 5, 7:00 AM
vpykhtin accepted this revision.Thu, Sep 5, 7:04 AM

LGTM.

This revision is now accepted and ready to land.Thu, Sep 5, 7:04 AM
MaskRay added a subscriber: MaskRay.Thu, Sep 5, 7:22 AM
MaskRay added inline comments.
llvm/include/llvm/CodeGen/TargetInstrInfo.h
1642

Delete to

1652

Delete to

alex-t closed this revision.Tue, Sep 10, 5:05 AM
alex-t reopened this revision.Fri, Sep 13, 10:35 AM
This revision is now accepted and ready to land.Fri, Sep 13, 10:35 AM
alex-t updated this revision to Diff 220147.Fri, Sep 13, 11:29 AM

Commit was reverted due to the EXPENSIVE_CHECKS failure.
Issue fixed

rampitec added inline comments.Fri, Sep 13, 11:33 AM
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
6417

So you think it is always scalar and always 64 bit?

alex-t updated this revision to Diff 220166.Fri, Sep 13, 1:27 PM

Empty block handling added

alex-t marked an inline comment as done.Fri, Sep 13, 1:28 PM
alex-t added inline comments.
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
6417

Since only case is SI_CF yes.

alex-t marked an inline comment as done.Fri, Sep 13, 1:32 PM
alex-t added inline comments.
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
6417

Oh... yes. in WAVE32 it will be S_MOV_B32_term

alex-t updated this revision to Diff 220167.Fri, Sep 13, 1:42 PM

Wave32/Wave64 cases

rampitec added inline comments.Fri, Sep 13, 1:53 PM
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
6422

impdef is just exec, you do not need to use exec_lo.

llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp
204

S_MOV_B64?

rampitec added inline comments.Fri, Sep 13, 2:01 PM
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
6417

What ensures that is just SI_CF? Why it cannot be some another PHI?

alex-t updated this revision to Diff 220352.EditedMon, Sep 16, 9:28 AM

Changed according the reviewer's request + some refactoring done.

alex-t marked 3 inline comments as done.Mon, Sep 16, 9:29 AM