diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2016-03-28 16:10:13 +0000 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2016-03-28 16:10:13 +0000 |
commit | a76bcc2ea1474fe7df0c757d3a4ca0bfaeed8913 (patch) | |
tree | 286d0524226e8af2d487bdad1958e2600d55f567 /llvm/lib | |
parent | 6db1dcbf6b42d1eedc070585c65e6fe7dab25e54 (diff) | |
download | bcm5719-llvm-a76bcc2ea1474fe7df0c757d3a4ca0bfaeed8913.tar.gz bcm5719-llvm-a76bcc2ea1474fe7df0c757d3a4ca0bfaeed8913.zip |
AMDGPU/SI: Limit load clustering to 16 bytes instead of 4 instructions
Summary:
This helps prevent load clustering from drastically increasing register
pressure by trying to cluster 4 SMRDx8 loads together. The limit of 16
bytes was chosen, because it seems like that was the original intent
of setting the limit to 4 instructions, but more analysis could show
that a different limit is better.
This fixes yields small decreases in register usage with shader-db, but
also helps avoid a large increase in register usage when lane mask
tracking is enabled in the machine scheduler, because lane mask tracking
enables more opportunities for load clustering.
shader-db stats:
2379 shaders in 477 tests
Totals:
SGPRS: 49744 -> 48600 (-2.30 %)
VGPRS: 34120 -> 34076 (-0.13 %)
Code Size: 1282888 -> 1283184 (0.02 %) bytes
LDS: 28 -> 28 (0.00 %) blocks
Scratch: 495616 -> 492544 (-0.62 %) bytes per wave
Max Waves: 6843 -> 6853 (0.15 %)
Wait states: 0 -> 0 (0.00 %)
Reviewers: nhaehnle, arsenm
Subscribers: arsenm, llvm-commits
Differential Revision: http://reviews.llvm.org/D18451
llvm-svn: 264589
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp index f0b420d10a8..4b1b15f868a 100644 --- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp @@ -295,18 +295,43 @@ bool SIInstrInfo::getMemOpBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg, bool SIInstrInfo::shouldClusterLoads(MachineInstr *FirstLdSt, MachineInstr *SecondLdSt, unsigned NumLoads) const { - // TODO: This needs finer tuning - if (NumLoads > 4) + const MachineOperand *FirstDst = nullptr; + const MachineOperand *SecondDst = nullptr; + + if (isDS(*FirstLdSt) && isDS(*SecondLdSt)) { + FirstDst = getNamedOperand(*FirstLdSt, AMDGPU::OpName::vdst); + SecondDst = getNamedOperand(*SecondLdSt, AMDGPU::OpName::vdst); + } + + if (isSMRD(*FirstLdSt) && isSMRD(*FirstLdSt)) { + FirstDst = getNamedOperand(*FirstLdSt, AMDGPU::OpName::sdst); + SecondDst = getNamedOperand(*SecondLdSt, AMDGPU::OpName::sdst); + } + + if ((isMUBUF(*FirstLdSt) && isMUBUF(*SecondLdSt)) || + (isMTBUF(*FirstLdSt) && isMTBUF(*SecondLdSt))) { + FirstDst = getNamedOperand(*FirstLdSt, AMDGPU::OpName::vdata); + SecondDst = getNamedOperand(*SecondLdSt, AMDGPU::OpName::vdata); + } + + if (!FirstDst || !SecondDst) return false; - if (isDS(*FirstLdSt) && isDS(*SecondLdSt)) - return true; + // Try to limit clustering based on the total number of bytes loaded + // rather than the number of instructions. This is done to help reduce + // register pressure. The method used is somewhat inexact, though, + // because it assumes that all loads in the cluster will load the + // same number of bytes as FirstLdSt. - if (isSMRD(*FirstLdSt) && isSMRD(*SecondLdSt)) - return true; + // The unit of this value is bytes. + // FIXME: This needs finer tuning. + unsigned LoadClusterThreshold = 16; + + const MachineRegisterInfo &MRI = + FirstLdSt->getParent()->getParent()->getRegInfo(); + const TargetRegisterClass *DstRC = MRI.getRegClass(FirstDst->getReg()); - return (isMUBUF(*FirstLdSt) || isMTBUF(*FirstLdSt)) && - (isMUBUF(*SecondLdSt) || isMTBUF(*SecondLdSt)); + return (NumLoads * DstRC->getSize()) <= LoadClusterThreshold; } void |