2017-08-08 08:47:13 +08:00
|
|
|
//===- SILoadStoreOptimizer.cpp -------------------------------------------===//
|
2014-10-11 06:01:59 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-10-11 06:01:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass tries to fuse DS instructions with close by immediate offsets.
|
|
|
|
// This will fuse operations such as
|
|
|
|
// ds_read_b32 v0, v2 offset:16
|
|
|
|
// ds_read_b32 v1, v2 offset:32
|
|
|
|
// ==>
|
|
|
|
// ds_read2_b32 v[0:1], v2, offset0:4 offset1:8
|
|
|
|
//
|
2017-11-28 16:42:46 +08:00
|
|
|
// The same is done for certain SMEM and VMEM opcodes, e.g.:
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
// s_buffer_load_dword s4, s[0:3], 4
|
|
|
|
// s_buffer_load_dword s5, s[0:3], 8
|
|
|
|
// ==>
|
|
|
|
// s_buffer_load_dwordx2 s[4:5], s[0:3], 4
|
|
|
|
//
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
// This pass also tries to promote constant offset to the immediate by
|
|
|
|
// adjusting the base. It tries to use a base from the nearby instructions that
|
|
|
|
// allows it to have a 13bit constant offset and then promotes the 13bit offset
|
|
|
|
// to the immediate.
|
|
|
|
// E.g.
|
|
|
|
// s_movk_i32 s0, 0x1800
|
|
|
|
// v_add_co_u32_e32 v0, vcc, s0, v2
|
|
|
|
// v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
|
|
|
|
//
|
|
|
|
// s_movk_i32 s0, 0x1000
|
|
|
|
// v_add_co_u32_e32 v5, vcc, s0, v2
|
|
|
|
// v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
|
|
|
|
// global_load_dwordx2 v[5:6], v[5:6], off
|
|
|
|
// global_load_dwordx2 v[0:1], v[0:1], off
|
|
|
|
// =>
|
|
|
|
// s_movk_i32 s0, 0x1000
|
|
|
|
// v_add_co_u32_e32 v5, vcc, s0, v2
|
|
|
|
// v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
|
|
|
|
// global_load_dwordx2 v[5:6], v[5:6], off
|
|
|
|
// global_load_dwordx2 v[0:1], v[5:6], off offset:2048
|
2014-10-11 06:01:59 +08:00
|
|
|
//
|
|
|
|
// Future improvements:
|
|
|
|
//
|
|
|
|
// - This currently relies on the scheduler to place loads and stores next to
|
|
|
|
// each other, and then only merges adjacent pairs of instructions. It would
|
|
|
|
// be good to be more flexible with interleaved instructions, and possibly run
|
|
|
|
// before scheduling. It currently missing stores of constants because loading
|
|
|
|
// the constant into the data register is placed between the stores, although
|
|
|
|
// this is arguably a scheduling problem.
|
|
|
|
//
|
|
|
|
// - Live interval recomputing seems inefficient. This currently only matches
|
|
|
|
// one pair, and recomputes live intervals and moves on to the next pair. It
|
2016-03-29 23:15:44 +08:00
|
|
|
// would be better to compute a list of all merges that need to occur.
|
2014-10-11 06:01:59 +08:00
|
|
|
//
|
|
|
|
// - With a list of instructions to process, we can also merge more. If a
|
|
|
|
// cluster of loads have offsets that are too large to fit in the 8-bit
|
|
|
|
// offsets, but are close enough to fit in the 8 bits, we can add to the base
|
|
|
|
// pointer and use the new reduced offsets.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
2016-06-24 14:30:11 +08:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2018-12-13 00:15:21 +08:00
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
2014-10-11 06:01:59 +08:00
|
|
|
#include "SIInstrInfo.h"
|
|
|
|
#include "SIRegisterInfo.h"
|
2017-01-21 08:53:49 +08:00
|
|
|
#include "Utils/AMDGPUBaseInfo.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2014-10-11 06:01:59 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2017-01-21 08:53:49 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2014-10-11 06:01:59 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2017-01-21 08:53:49 +08:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2014-10-11 06:01:59 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-01-21 08:53:49 +08:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
|
|
|
#include "llvm/Pass.h"
|
2014-10-11 06:01:59 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2017-01-21 08:53:49 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2015-03-24 03:32:43 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-08-08 08:47:13 +08:00
|
|
|
#include <algorithm>
|
2017-01-21 08:53:49 +08:00
|
|
|
#include <cassert>
|
2017-08-08 08:47:13 +08:00
|
|
|
#include <cstdlib>
|
2017-01-21 08:53:49 +08:00
|
|
|
#include <iterator>
|
|
|
|
#include <utility>
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "si-load-store-opt"
|
|
|
|
|
|
|
|
namespace {
|
2018-12-13 00:15:21 +08:00
|
|
|
enum InstClassEnum {
|
|
|
|
UNKNOWN,
|
|
|
|
DS_READ,
|
|
|
|
DS_WRITE,
|
|
|
|
S_BUFFER_LOAD_IMM,
|
|
|
|
BUFFER_LOAD_OFFEN = AMDGPU::BUFFER_LOAD_DWORD_OFFEN,
|
|
|
|
BUFFER_LOAD_OFFSET = AMDGPU::BUFFER_LOAD_DWORD_OFFSET,
|
|
|
|
BUFFER_STORE_OFFEN = AMDGPU::BUFFER_STORE_DWORD_OFFEN,
|
|
|
|
BUFFER_STORE_OFFSET = AMDGPU::BUFFER_STORE_DWORD_OFFSET,
|
|
|
|
BUFFER_LOAD_OFFEN_exact = AMDGPU::BUFFER_LOAD_DWORD_OFFEN_exact,
|
|
|
|
BUFFER_LOAD_OFFSET_exact = AMDGPU::BUFFER_LOAD_DWORD_OFFSET_exact,
|
|
|
|
BUFFER_STORE_OFFEN_exact = AMDGPU::BUFFER_STORE_DWORD_OFFEN_exact,
|
|
|
|
BUFFER_STORE_OFFSET_exact = AMDGPU::BUFFER_STORE_DWORD_OFFSET_exact,
|
|
|
|
};
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
enum RegisterEnum {
|
|
|
|
SBASE = 0x1,
|
|
|
|
SRSRC = 0x2,
|
|
|
|
SOFFSET = 0x4,
|
|
|
|
VADDR = 0x8,
|
|
|
|
ADDR = 0x10,
|
|
|
|
};
|
2017-11-09 09:52:30 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
class SILoadStoreOptimizer : public MachineFunctionPass {
|
2017-10-10 16:30:53 +08:00
|
|
|
struct CombineInfo {
|
2017-04-14 01:53:07 +08:00
|
|
|
MachineBasicBlock::iterator I;
|
|
|
|
MachineBasicBlock::iterator Paired;
|
|
|
|
unsigned EltSize;
|
|
|
|
unsigned Offset0;
|
|
|
|
unsigned Offset1;
|
2018-12-13 00:15:21 +08:00
|
|
|
unsigned Width0;
|
|
|
|
unsigned Width1;
|
2017-04-14 01:53:07 +08:00
|
|
|
unsigned BaseOff;
|
2017-11-09 09:52:30 +08:00
|
|
|
InstClassEnum InstClass;
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
bool GLC0;
|
|
|
|
bool GLC1;
|
2017-11-09 09:52:30 +08:00
|
|
|
bool SLC0;
|
|
|
|
bool SLC1;
|
2019-05-01 06:08:23 +08:00
|
|
|
bool DLC0;
|
|
|
|
bool DLC1;
|
2017-04-14 01:53:07 +08:00
|
|
|
bool UseST64;
|
2018-12-13 00:15:21 +08:00
|
|
|
SmallVector<MachineInstr *, 8> InstsToMove;
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
int AddrIdx[5];
|
|
|
|
const MachineOperand *AddrReg[5];
|
|
|
|
unsigned NumAddresses;
|
|
|
|
|
|
|
|
bool hasSameBaseAddress(const MachineInstr &MI) {
|
|
|
|
for (unsigned i = 0; i < NumAddresses; i++) {
|
|
|
|
const MachineOperand &AddrRegNext = MI.getOperand(AddrIdx[i]);
|
|
|
|
|
|
|
|
if (AddrReg[i]->isImm() || AddrRegNext.isImm()) {
|
|
|
|
if (AddrReg[i]->isImm() != AddrRegNext.isImm() ||
|
|
|
|
AddrReg[i]->getImm() != AddrRegNext.getImm()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check same base pointer. Be careful of subregisters, which can occur
|
|
|
|
// with vectors of pointers.
|
|
|
|
if (AddrReg[i]->getReg() != AddrRegNext.getReg() ||
|
|
|
|
AddrReg[i]->getSubReg() != AddrRegNext.getSubReg()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
bool hasMergeableAddress(const MachineRegisterInfo &MRI) {
|
|
|
|
for (unsigned i = 0; i < NumAddresses; ++i) {
|
|
|
|
const MachineOperand *AddrOp = AddrReg[i];
|
|
|
|
// Immediates are always OK.
|
|
|
|
if (AddrOp->isImm())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Don't try to merge addresses that aren't either immediates or registers.
|
|
|
|
// TODO: Should be possible to merge FrameIndexes and maybe some other
|
|
|
|
// non-register
|
|
|
|
if (!AddrOp->isReg())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// TODO: We should be able to merge physical reg addreses.
|
|
|
|
if (Register::isPhysicalRegister(AddrOp->getReg()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If an address has only one use then there will be on other
|
|
|
|
// instructions with the same address, so we can't merge this one.
|
|
|
|
if (MRI.hasOneNonDBGUse(AddrOp->getReg()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
void setMI(MachineBasicBlock::iterator MI, const SIInstrInfo &TII,
|
|
|
|
const GCNSubtarget &STM);
|
|
|
|
void setPaired(MachineBasicBlock::iterator MI, const SIInstrInfo &TII);
|
2018-12-13 00:15:21 +08:00
|
|
|
};
|
2017-04-14 01:53:07 +08:00
|
|
|
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
struct BaseRegisters {
|
|
|
|
unsigned LoReg = 0;
|
|
|
|
unsigned HiReg = 0;
|
|
|
|
|
|
|
|
unsigned LoSubReg = 0;
|
|
|
|
unsigned HiSubReg = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MemAddress {
|
|
|
|
BaseRegisters Base;
|
|
|
|
int64_t Offset = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
using MemInfoMap = DenseMap<MachineInstr *, MemAddress>;
|
|
|
|
|
2014-10-11 06:01:59 +08:00
|
|
|
private:
|
2018-07-12 04:59:01 +08:00
|
|
|
const GCNSubtarget *STM = nullptr;
|
2017-01-21 08:53:49 +08:00
|
|
|
const SIInstrInfo *TII = nullptr;
|
|
|
|
const SIRegisterInfo *TRI = nullptr;
|
|
|
|
MachineRegisterInfo *MRI = nullptr;
|
|
|
|
AliasAnalysis *AA = nullptr;
|
2018-12-13 00:15:21 +08:00
|
|
|
bool OptimizeAgain;
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
static bool offsetsCanBeCombined(CombineInfo &CI);
|
2019-01-11 00:21:08 +08:00
|
|
|
static bool widthsFit(const GCNSubtarget &STM, const CombineInfo &CI);
|
2018-12-13 00:15:21 +08:00
|
|
|
static unsigned getNewOpcode(const CombineInfo &CI);
|
|
|
|
static std::pair<unsigned, unsigned> getSubRegIdxs(const CombineInfo &CI);
|
|
|
|
const TargetRegisterClass *getTargetRegisterClass(const CombineInfo &CI);
|
2014-10-11 06:01:59 +08:00
|
|
|
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
bool findMatchingInst(CombineInfo &CI);
|
2017-11-29 08:55:57 +08:00
|
|
|
|
|
|
|
unsigned read2Opcode(unsigned EltSize) const;
|
|
|
|
unsigned read2ST64Opcode(unsigned EltSize) const;
|
2017-04-14 01:53:07 +08:00
|
|
|
MachineBasicBlock::iterator mergeRead2Pair(CombineInfo &CI);
|
2017-11-29 08:55:57 +08:00
|
|
|
|
|
|
|
unsigned write2Opcode(unsigned EltSize) const;
|
|
|
|
unsigned write2ST64Opcode(unsigned EltSize) const;
|
2017-04-14 01:53:07 +08:00
|
|
|
MachineBasicBlock::iterator mergeWrite2Pair(CombineInfo &CI);
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
MachineBasicBlock::iterator mergeSBufferLoadImmPair(CombineInfo &CI);
|
2017-11-09 09:52:36 +08:00
|
|
|
MachineBasicBlock::iterator mergeBufferLoadPair(CombineInfo &CI);
|
2017-11-09 09:52:55 +08:00
|
|
|
MachineBasicBlock::iterator mergeBufferStorePair(CombineInfo &CI);
|
2014-10-11 06:01:59 +08:00
|
|
|
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
void updateBaseAndOffset(MachineInstr &I, unsigned NewBase,
|
AMDGPU/SILoadStoreOptimizer: Add const to more functions
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65901
llvm-svn: 372298
2019-09-19 12:39:45 +08:00
|
|
|
int32_t NewOffset) const;
|
|
|
|
unsigned computeBase(MachineInstr &MI, const MemAddress &Addr) const;
|
|
|
|
MachineOperand createRegOrImm(int32_t Val, MachineInstr &MI) const;
|
|
|
|
Optional<int32_t> extractConstOffset(const MachineOperand &Op) const;
|
|
|
|
void processBaseWithConstOffset(const MachineOperand &Base, MemAddress &Addr) const;
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
/// Promotes constant offset to the immediate by adjusting the base. It
|
|
|
|
/// tries to use a base from the nearby instructions that allows it to have
|
|
|
|
/// a 13bit constant offset which gets promoted to the immediate.
|
|
|
|
bool promoteConstantOffsetToImm(MachineInstr &CI,
|
|
|
|
MemInfoMap &Visited,
|
AMDGPU/SILoadStoreOptimizer: Add const to more functions
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65901
llvm-svn: 372298
2019-09-19 12:39:45 +08:00
|
|
|
SmallPtrSet<MachineInstr *, 4> &Promoted) const;
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
void addInstToMergeableList(const CombineInfo &CI,
|
|
|
|
std::list<std::list<CombineInfo> > &MergeableInsts) const;
|
|
|
|
bool collectMergeableInsts(MachineBasicBlock &MBB,
|
|
|
|
std::list<std::list<CombineInfo> > &MergeableInsts) const;
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
|
2014-10-11 06:01:59 +08:00
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
2017-05-19 01:21:13 +08:00
|
|
|
SILoadStoreOptimizer() : MachineFunctionPass(ID) {
|
2014-10-11 06:01:59 +08:00
|
|
|
initializeSILoadStoreOptimizerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
void removeCombinedInst(std::list<CombineInfo> &MergeList,
|
|
|
|
const MachineInstr &MI);
|
|
|
|
bool optimizeInstsWithSameBaseAddr(std::list<CombineInfo> &MergeList,
|
|
|
|
bool &OptimizeListAgain);
|
|
|
|
bool optimizeBlock(std::list<std::list<CombineInfo> > &MergeableInsts);
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
|
2018-01-23 05:46:43 +08:00
|
|
|
StringRef getPassName() const override { return "SI Load Store Optimizer"; }
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesCFG();
|
2016-08-30 03:15:22 +08:00
|
|
|
AU.addRequired<AAResultsWrapperPass>();
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
static unsigned getOpcodeWidth(const MachineInstr &MI, const SIInstrInfo &TII) {
|
|
|
|
const unsigned Opc = MI.getOpcode();
|
|
|
|
|
|
|
|
if (TII.isMUBUF(Opc)) {
|
|
|
|
// FIXME: Handle d16 correctly
|
|
|
|
return AMDGPU::getMUBUFElements(Opc);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Opc) {
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORD_IMM:
|
|
|
|
return 1;
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORDX2_IMM:
|
|
|
|
return 2;
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORDX4_IMM:
|
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static InstClassEnum getInstClass(unsigned Opc, const SIInstrInfo &TII) {
|
|
|
|
if (TII.isMUBUF(Opc)) {
|
|
|
|
const int baseOpcode = AMDGPU::getMUBUFBaseOpcode(Opc);
|
|
|
|
|
|
|
|
// If we couldn't identify the opcode, bail out.
|
|
|
|
if (baseOpcode == -1) {
|
|
|
|
return UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (baseOpcode) {
|
|
|
|
case AMDGPU::BUFFER_LOAD_DWORD_OFFEN:
|
|
|
|
return BUFFER_LOAD_OFFEN;
|
|
|
|
case AMDGPU::BUFFER_LOAD_DWORD_OFFSET:
|
|
|
|
return BUFFER_LOAD_OFFSET;
|
|
|
|
case AMDGPU::BUFFER_STORE_DWORD_OFFEN:
|
|
|
|
return BUFFER_STORE_OFFEN;
|
|
|
|
case AMDGPU::BUFFER_STORE_DWORD_OFFSET:
|
|
|
|
return BUFFER_STORE_OFFSET;
|
|
|
|
case AMDGPU::BUFFER_LOAD_DWORD_OFFEN_exact:
|
|
|
|
return BUFFER_LOAD_OFFEN_exact;
|
|
|
|
case AMDGPU::BUFFER_LOAD_DWORD_OFFSET_exact:
|
|
|
|
return BUFFER_LOAD_OFFSET_exact;
|
|
|
|
case AMDGPU::BUFFER_STORE_DWORD_OFFEN_exact:
|
|
|
|
return BUFFER_STORE_OFFEN_exact;
|
|
|
|
case AMDGPU::BUFFER_STORE_DWORD_OFFSET_exact:
|
|
|
|
return BUFFER_STORE_OFFSET_exact;
|
|
|
|
default:
|
|
|
|
return UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Opc) {
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORD_IMM:
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORDX2_IMM:
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORDX4_IMM:
|
|
|
|
return S_BUFFER_LOAD_IMM;
|
|
|
|
case AMDGPU::DS_READ_B32:
|
|
|
|
case AMDGPU::DS_READ_B64:
|
|
|
|
case AMDGPU::DS_READ_B32_gfx9:
|
|
|
|
case AMDGPU::DS_READ_B64_gfx9:
|
|
|
|
return DS_READ;
|
|
|
|
case AMDGPU::DS_WRITE_B32:
|
|
|
|
case AMDGPU::DS_WRITE_B64:
|
|
|
|
case AMDGPU::DS_WRITE_B32_gfx9:
|
|
|
|
case AMDGPU::DS_WRITE_B64_gfx9:
|
|
|
|
return DS_WRITE;
|
|
|
|
default:
|
|
|
|
return UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getRegs(unsigned Opc, const SIInstrInfo &TII) {
|
|
|
|
if (TII.isMUBUF(Opc)) {
|
|
|
|
unsigned result = 0;
|
|
|
|
|
|
|
|
if (AMDGPU::getMUBUFHasVAddr(Opc)) {
|
|
|
|
result |= VADDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AMDGPU::getMUBUFHasSrsrc(Opc)) {
|
|
|
|
result |= SRSRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AMDGPU::getMUBUFHasSoffset(Opc)) {
|
|
|
|
result |= SOFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORD_IMM:
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORDX2_IMM:
|
|
|
|
case AMDGPU::S_BUFFER_LOAD_DWORDX4_IMM:
|
|
|
|
return SBASE;
|
|
|
|
case AMDGPU::DS_READ_B32:
|
|
|
|
case AMDGPU::DS_READ_B64:
|
|
|
|
case AMDGPU::DS_READ_B32_gfx9:
|
|
|
|
case AMDGPU::DS_READ_B64_gfx9:
|
|
|
|
case AMDGPU::DS_WRITE_B32:
|
|
|
|
case AMDGPU::DS_WRITE_B64:
|
|
|
|
case AMDGPU::DS_WRITE_B32_gfx9:
|
|
|
|
case AMDGPU::DS_WRITE_B64_gfx9:
|
|
|
|
return ADDR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SILoadStoreOptimizer::CombineInfo::setMI(MachineBasicBlock::iterator MI,
|
|
|
|
const SIInstrInfo &TII,
|
|
|
|
const GCNSubtarget &STM) {
|
|
|
|
I = MI;
|
|
|
|
unsigned Opc = MI->getOpcode();
|
|
|
|
InstClass = getInstClass(Opc, TII);
|
|
|
|
|
|
|
|
if (InstClass == UNKNOWN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (InstClass) {
|
|
|
|
case DS_READ:
|
|
|
|
EltSize =
|
|
|
|
(Opc == AMDGPU::DS_READ_B64 || Opc == AMDGPU::DS_READ_B64_gfx9) ? 8
|
|
|
|
: 4;
|
|
|
|
break;
|
|
|
|
case DS_WRITE:
|
|
|
|
EltSize =
|
|
|
|
(Opc == AMDGPU::DS_WRITE_B64 || Opc == AMDGPU::DS_WRITE_B64_gfx9) ? 8
|
|
|
|
: 4;
|
|
|
|
break;
|
|
|
|
case S_BUFFER_LOAD_IMM:
|
|
|
|
EltSize = AMDGPU::getSMRDEncodedOffset(STM, 4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
EltSize = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OffsetIdx =
|
|
|
|
AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::offset);
|
|
|
|
Offset0 = I->getOperand(OffsetIdx).getImm();
|
|
|
|
Width0 = getOpcodeWidth(*I, TII);
|
|
|
|
|
|
|
|
if ((InstClass == DS_READ) || (InstClass == DS_WRITE)) {
|
|
|
|
Offset0 &= 0xffff;
|
|
|
|
} else {
|
|
|
|
GLC0 = TII.getNamedOperand(*I, AMDGPU::OpName::glc)->getImm();
|
|
|
|
if (InstClass != S_BUFFER_LOAD_IMM) {
|
|
|
|
SLC0 = TII.getNamedOperand(*I, AMDGPU::OpName::slc)->getImm();
|
|
|
|
}
|
|
|
|
DLC0 = TII.getNamedOperand(*I, AMDGPU::OpName::dlc)->getImm();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned AddrOpName[5] = {0};
|
|
|
|
NumAddresses = 0;
|
|
|
|
const unsigned Regs = getRegs(I->getOpcode(), TII);
|
|
|
|
|
|
|
|
if (Regs & ADDR) {
|
|
|
|
AddrOpName[NumAddresses++] = AMDGPU::OpName::addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Regs & SBASE) {
|
|
|
|
AddrOpName[NumAddresses++] = AMDGPU::OpName::sbase;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Regs & SRSRC) {
|
|
|
|
AddrOpName[NumAddresses++] = AMDGPU::OpName::srsrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Regs & SOFFSET) {
|
|
|
|
AddrOpName[NumAddresses++] = AMDGPU::OpName::soffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Regs & VADDR) {
|
|
|
|
AddrOpName[NumAddresses++] = AMDGPU::OpName::vaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < NumAddresses; i++) {
|
|
|
|
AddrIdx[i] = AMDGPU::getNamedOperandIdx(I->getOpcode(), AddrOpName[i]);
|
|
|
|
AddrReg[i] = &I->getOperand(AddrIdx[i]);
|
|
|
|
}
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
|
|
|
|
InstsToMove.clear();
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SILoadStoreOptimizer::CombineInfo::setPaired(MachineBasicBlock::iterator MI,
|
|
|
|
const SIInstrInfo &TII) {
|
|
|
|
Paired = MI;
|
|
|
|
assert(InstClass == getInstClass(Paired->getOpcode(), TII));
|
|
|
|
int OffsetIdx =
|
|
|
|
AMDGPU::getNamedOperandIdx(I->getOpcode(), AMDGPU::OpName::offset);
|
|
|
|
Offset1 = Paired->getOperand(OffsetIdx).getImm();
|
|
|
|
Width1 = getOpcodeWidth(*Paired, TII);
|
|
|
|
if ((InstClass == DS_READ) || (InstClass == DS_WRITE)) {
|
|
|
|
Offset1 &= 0xffff;
|
|
|
|
} else {
|
|
|
|
GLC1 = TII.getNamedOperand(*Paired, AMDGPU::OpName::glc)->getImm();
|
|
|
|
if (InstClass != S_BUFFER_LOAD_IMM) {
|
|
|
|
SLC1 = TII.getNamedOperand(*Paired, AMDGPU::OpName::slc)->getImm();
|
|
|
|
}
|
|
|
|
DLC1 = TII.getNamedOperand(*Paired, AMDGPU::OpName::dlc)->getImm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-21 08:53:49 +08:00
|
|
|
} // end anonymous namespace.
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(SILoadStoreOptimizer, DEBUG_TYPE,
|
2018-01-23 05:46:43 +08:00
|
|
|
"SI Load Store Optimizer", false, false)
|
2016-08-30 03:15:22 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
2018-12-13 00:15:21 +08:00
|
|
|
INITIALIZE_PASS_END(SILoadStoreOptimizer, DEBUG_TYPE, "SI Load Store Optimizer",
|
|
|
|
false, false)
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
char SILoadStoreOptimizer::ID = 0;
|
|
|
|
|
|
|
|
char &llvm::SILoadStoreOptimizerID = SILoadStoreOptimizer::ID;
|
|
|
|
|
2017-05-19 01:21:13 +08:00
|
|
|
FunctionPass *llvm::createSILoadStoreOptimizerPass() {
|
|
|
|
return new SILoadStoreOptimizer();
|
2014-10-11 06:01:59 +08:00
|
|
|
}
|
|
|
|
|
2016-08-30 03:15:22 +08:00
|
|
|
static void moveInstsAfter(MachineBasicBlock::iterator I,
|
2018-12-13 00:15:21 +08:00
|
|
|
ArrayRef<MachineInstr *> InstsToMove) {
|
2016-08-30 03:15:22 +08:00
|
|
|
MachineBasicBlock *MBB = I->getParent();
|
|
|
|
++I;
|
|
|
|
for (MachineInstr *MI : InstsToMove) {
|
|
|
|
MI->removeFromParent();
|
|
|
|
MBB->insert(I, MI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 18:45:56 +08:00
|
|
|
static void addDefsUsesToList(const MachineInstr &MI,
|
|
|
|
DenseSet<unsigned> &RegDefs,
|
|
|
|
DenseSet<unsigned> &PhysRegUses) {
|
|
|
|
for (const MachineOperand &Op : MI.operands()) {
|
|
|
|
if (Op.isReg()) {
|
|
|
|
if (Op.isDef())
|
|
|
|
RegDefs.insert(Op.getReg());
|
2019-08-02 07:27:28 +08:00
|
|
|
else if (Op.readsReg() && Register::isPhysicalRegister(Op.getReg()))
|
2018-02-23 18:45:56 +08:00
|
|
|
PhysRegUses.insert(Op.getReg());
|
|
|
|
}
|
2018-02-08 09:56:14 +08:00
|
|
|
}
|
2016-08-30 03:15:22 +08:00
|
|
|
}
|
|
|
|
|
2017-01-21 08:53:49 +08:00
|
|
|
static bool memAccessesCanBeReordered(MachineBasicBlock::iterator A,
|
|
|
|
MachineBasicBlock::iterator B,
|
2018-12-13 00:15:21 +08:00
|
|
|
AliasAnalysis *AA) {
|
2017-08-31 09:53:09 +08:00
|
|
|
// RAW or WAR - cannot reorder
|
|
|
|
// WAW - cannot reorder
|
|
|
|
// RAR - safe to reorder
|
2019-02-19 07:00:26 +08:00
|
|
|
return !(A->mayStore() || B->mayStore()) || !A->mayAlias(AA, *B, true);
|
2016-11-03 22:37:13 +08:00
|
|
|
}
|
|
|
|
|
2016-10-27 16:15:07 +08:00
|
|
|
// Add MI and its defs to the lists if MI reads one of the defs that are
|
|
|
|
// already in the list. Returns true in that case.
|
2018-12-13 00:15:21 +08:00
|
|
|
static bool addToListsIfDependent(MachineInstr &MI, DenseSet<unsigned> &RegDefs,
|
|
|
|
DenseSet<unsigned> &PhysRegUses,
|
|
|
|
SmallVectorImpl<MachineInstr *> &Insts) {
|
2017-08-31 09:53:09 +08:00
|
|
|
for (MachineOperand &Use : MI.operands()) {
|
|
|
|
// If one of the defs is read, then there is a use of Def between I and the
|
|
|
|
// instruction that I will potentially be merged with. We will need to move
|
|
|
|
// this instruction after the merged instructions.
|
2018-02-23 18:45:56 +08:00
|
|
|
//
|
|
|
|
// Similarly, if there is a def which is read by an instruction that is to
|
|
|
|
// be moved for merging, then we need to move the def-instruction as well.
|
|
|
|
// This can only happen for physical registers such as M0; virtual
|
|
|
|
// registers are in SSA form.
|
|
|
|
if (Use.isReg() &&
|
|
|
|
((Use.readsReg() && RegDefs.count(Use.getReg())) ||
|
[AMDGPU] detect WaW hazards when moving/merging load/store instructions
Summary:
In order to combine memory operations efficiently, the load/store
optimizer might move some instructions around. It's usually safe
to move instructions down past the merged instruction because the
pass checks if memory operations can be re-ordered.
Though, the current logic doesn't handle Write-after-Write hazards.
This fixes a reflection issue with Monster Hunter World and DXVK.
v2: - rebased on top of master
- clean up the test case
- handle WaW hazards correctly
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=40130
Original patch by Samuel Pitoiset.
Reviewers: tpr, arsenm, nhaehnle
Reviewed By: nhaehnle
Subscribers: ronlieb, arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye
Differential Revision: https://reviews.llvm.org/D61313
llvm-svn: 361008
2019-05-17 17:32:23 +08:00
|
|
|
(Use.isDef() && RegDefs.count(Use.getReg())) ||
|
2019-08-02 07:27:28 +08:00
|
|
|
(Use.isDef() && Register::isPhysicalRegister(Use.getReg()) &&
|
2018-02-23 18:45:56 +08:00
|
|
|
PhysRegUses.count(Use.getReg())))) {
|
2016-10-27 16:15:07 +08:00
|
|
|
Insts.push_back(&MI);
|
2018-02-23 18:45:56 +08:00
|
|
|
addDefsUsesToList(MI, RegDefs, PhysRegUses);
|
2016-10-27 16:15:07 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
static bool canMoveInstsAcrossMemOp(MachineInstr &MemOp,
|
|
|
|
ArrayRef<MachineInstr *> InstsToMove,
|
2019-02-19 07:00:26 +08:00
|
|
|
AliasAnalysis *AA) {
|
2016-08-30 03:15:22 +08:00
|
|
|
assert(MemOp.mayLoadOrStore());
|
|
|
|
|
|
|
|
for (MachineInstr *InstToMove : InstsToMove) {
|
|
|
|
if (!InstToMove->mayLoadOrStore())
|
|
|
|
continue;
|
2019-02-19 07:00:26 +08:00
|
|
|
if (!memAccessesCanBeReordered(MemOp, *InstToMove, AA))
|
2018-12-13 00:15:21 +08:00
|
|
|
return false;
|
2016-08-30 03:15:22 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
AMDGPU/LoadStoreOptimizer: combine MMOs when merging instructions
Summary:
The LoadStoreOptimizer was creating instructions with 2
MachineMemOperands, which meant they were assumed to alias with all other instructions,
because MachineInstr:mayAlias() returns true when an instruction has multiple
MachineMemOperands.
This was preventing these instructions from being merged again, and was
giving the scheduler less freedom to reorder them.
Reviewers: arsenm, nhaehnle
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65036
llvm-svn: 367237
2019-07-30 00:40:58 +08:00
|
|
|
// This function assumes that \p A and \p B have are identical except for
|
|
|
|
// size and offset, and they referecne adjacent memory.
|
|
|
|
static MachineMemOperand *combineKnownAdjacentMMOs(MachineFunction &MF,
|
|
|
|
const MachineMemOperand *A,
|
|
|
|
const MachineMemOperand *B) {
|
|
|
|
unsigned MinOffset = std::min(A->getOffset(), B->getOffset());
|
|
|
|
unsigned Size = A->getSize() + B->getSize();
|
2019-08-06 00:08:44 +08:00
|
|
|
// This function adds the offset parameter to the existing offset for A,
|
|
|
|
// so we pass 0 here as the offset and then manually set it to the correct
|
|
|
|
// value after the call.
|
|
|
|
MachineMemOperand *MMO = MF.getMachineMemOperand(A, 0, Size);
|
|
|
|
MMO->setOffset(MinOffset);
|
|
|
|
return MMO;
|
AMDGPU/LoadStoreOptimizer: combine MMOs when merging instructions
Summary:
The LoadStoreOptimizer was creating instructions with 2
MachineMemOperands, which meant they were assumed to alias with all other instructions,
because MachineInstr:mayAlias() returns true when an instruction has multiple
MachineMemOperands.
This was preventing these instructions from being merged again, and was
giving the scheduler less freedom to reorder them.
Reviewers: arsenm, nhaehnle
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65036
llvm-svn: 367237
2019-07-30 00:40:58 +08:00
|
|
|
}
|
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
bool SILoadStoreOptimizer::offsetsCanBeCombined(CombineInfo &CI) {
|
2014-10-11 06:01:59 +08:00
|
|
|
// XXX - Would the same offset be OK? Is there any reason this would happen or
|
|
|
|
// be useful?
|
2017-04-14 01:53:07 +08:00
|
|
|
if (CI.Offset0 == CI.Offset1)
|
2014-10-11 06:12:32 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// This won't be valid if the offset isn't aligned.
|
2017-04-14 01:53:07 +08:00
|
|
|
if ((CI.Offset0 % CI.EltSize != 0) || (CI.Offset1 % CI.EltSize != 0))
|
2014-10-11 06:12:32 +08:00
|
|
|
return false;
|
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
unsigned EltOffset0 = CI.Offset0 / CI.EltSize;
|
|
|
|
unsigned EltOffset1 = CI.Offset1 / CI.EltSize;
|
|
|
|
CI.UseST64 = false;
|
|
|
|
CI.BaseOff = 0;
|
|
|
|
|
2017-11-09 09:52:55 +08:00
|
|
|
// Handle SMEM and VMEM instructions.
|
2018-12-13 00:15:21 +08:00
|
|
|
if ((CI.InstClass != DS_READ) && (CI.InstClass != DS_WRITE)) {
|
|
|
|
return (EltOffset0 + CI.Width0 == EltOffset1 ||
|
|
|
|
EltOffset1 + CI.Width1 == EltOffset0) &&
|
2019-05-01 06:08:23 +08:00
|
|
|
CI.GLC0 == CI.GLC1 && CI.DLC0 == CI.DLC1 &&
|
2017-11-09 09:52:30 +08:00
|
|
|
(CI.InstClass == S_BUFFER_LOAD_IMM || CI.SLC0 == CI.SLC1);
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
}
|
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
// If the offset in elements doesn't fit in 8-bits, we might be able to use
|
|
|
|
// the stride 64 versions.
|
|
|
|
if ((EltOffset0 % 64 == 0) && (EltOffset1 % 64) == 0 &&
|
|
|
|
isUInt<8>(EltOffset0 / 64) && isUInt<8>(EltOffset1 / 64)) {
|
|
|
|
CI.Offset0 = EltOffset0 / 64;
|
|
|
|
CI.Offset1 = EltOffset1 / 64;
|
|
|
|
CI.UseST64 = true;
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-11 06:12:32 +08:00
|
|
|
|
|
|
|
// Check if the new offsets fit in the reduced 8-bit range.
|
2017-04-14 01:53:07 +08:00
|
|
|
if (isUInt<8>(EltOffset0) && isUInt<8>(EltOffset1)) {
|
|
|
|
CI.Offset0 = EltOffset0;
|
|
|
|
CI.Offset1 = EltOffset1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to shift base address to decrease offsets.
|
|
|
|
unsigned OffsetDiff = std::abs((int)EltOffset1 - (int)EltOffset0);
|
|
|
|
CI.BaseOff = std::min(CI.Offset0, CI.Offset1);
|
|
|
|
|
|
|
|
if ((OffsetDiff % 64 == 0) && isUInt<8>(OffsetDiff / 64)) {
|
|
|
|
CI.Offset0 = (EltOffset0 - CI.BaseOff / CI.EltSize) / 64;
|
|
|
|
CI.Offset1 = (EltOffset1 - CI.BaseOff / CI.EltSize) / 64;
|
|
|
|
CI.UseST64 = true;
|
2014-10-11 06:12:32 +08:00
|
|
|
return true;
|
2017-04-14 01:53:07 +08:00
|
|
|
}
|
2014-10-11 06:12:32 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
if (isUInt<8>(OffsetDiff)) {
|
|
|
|
CI.Offset0 = EltOffset0 - CI.BaseOff / CI.EltSize;
|
|
|
|
CI.Offset1 = EltOffset1 - CI.BaseOff / CI.EltSize;
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-11 06:12:32 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
return false;
|
2014-10-11 06:01:59 +08:00
|
|
|
}
|
|
|
|
|
2019-01-11 00:21:08 +08:00
|
|
|
bool SILoadStoreOptimizer::widthsFit(const GCNSubtarget &STM,
|
|
|
|
const CombineInfo &CI) {
|
2018-12-13 00:15:21 +08:00
|
|
|
const unsigned Width = (CI.Width0 + CI.Width1);
|
|
|
|
switch (CI.InstClass) {
|
|
|
|
default:
|
2019-01-11 00:21:08 +08:00
|
|
|
return (Width <= 4) && (STM.hasDwordx3LoadStores() || (Width != 3));
|
2018-12-13 00:15:21 +08:00
|
|
|
case S_BUFFER_LOAD_IMM:
|
|
|
|
switch (Width) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
bool SILoadStoreOptimizer::findMatchingInst(CombineInfo &CI) {
|
2017-08-31 09:53:09 +08:00
|
|
|
MachineBasicBlock *MBB = CI.I->getParent();
|
|
|
|
MachineBasicBlock::iterator E = MBB->end();
|
2017-04-14 01:53:07 +08:00
|
|
|
MachineBasicBlock::iterator MBBI = CI.I;
|
2017-08-30 11:26:18 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
const unsigned Opc = CI.I->getOpcode();
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
const InstClassEnum InstClass = getInstClass(Opc, *TII);
|
2018-12-13 00:15:21 +08:00
|
|
|
|
|
|
|
if (InstClass == UNKNOWN) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
[AMDGPU] Extend buffer intrinsics with swizzling
Summary:
Extend cachepolicy operand in the new VMEM buffer intrinsics
to supply information whether the buffer data is swizzled.
Also, propagate this information to MIR.
Intrinsics updated:
int_amdgcn_raw_buffer_load
int_amdgcn_raw_buffer_load_format
int_amdgcn_raw_buffer_store
int_amdgcn_raw_buffer_store_format
int_amdgcn_raw_tbuffer_load
int_amdgcn_raw_tbuffer_store
int_amdgcn_struct_buffer_load
int_amdgcn_struct_buffer_load_format
int_amdgcn_struct_buffer_store
int_amdgcn_struct_buffer_store_format
int_amdgcn_struct_tbuffer_load
int_amdgcn_struct_tbuffer_store
Furthermore, disable merging of VMEM buffer instructions
in SI Load/Store optimizer, if the "swizzled" bit on the instruction
is on.
The default value of the bit is 0, meaning that data in buffer
is linear and buffer instructions can be merged.
There is no difference in the generated code with this commit.
However, in the future it will be expected that front-ends
use buffer intrinsics with correct "swizzled" bit set.
Reviewers: arsenm, nhaehnle, tpr
Reviewed By: nhaehnle
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, arphaman, jfb, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68200
llvm-svn: 373491
2019-10-03 01:22:36 +08:00
|
|
|
// Do not merge VMEM buffer instructions with "swizzled" bit set.
|
|
|
|
int Swizzled =
|
|
|
|
AMDGPU::getNamedOperandIdx(CI.I->getOpcode(), AMDGPU::OpName::swz);
|
|
|
|
if (Swizzled != -1 && CI.I->getOperand(Swizzled).getImm())
|
|
|
|
return false;
|
|
|
|
|
2014-10-11 06:01:59 +08:00
|
|
|
++MBBI;
|
|
|
|
|
2018-02-23 18:45:56 +08:00
|
|
|
DenseSet<unsigned> RegDefsToMove;
|
|
|
|
DenseSet<unsigned> PhysRegUsesToMove;
|
|
|
|
addDefsUsesToList(*CI.I, RegDefsToMove, PhysRegUsesToMove);
|
2016-08-30 03:15:22 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
for (; MBBI != E; ++MBBI) {
|
|
|
|
const bool IsDS = (InstClass == DS_READ) || (InstClass == DS_WRITE);
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
if ((getInstClass(MBBI->getOpcode(), *TII) != InstClass) ||
|
2018-12-13 00:15:21 +08:00
|
|
|
(IsDS && (MBBI->getOpcode() != Opc))) {
|
2016-08-30 03:15:22 +08:00
|
|
|
// This is not a matching DS instruction, but we can keep looking as
|
|
|
|
// long as one of these conditions are met:
|
|
|
|
// 1. It is safe to move I down past MBBI.
|
|
|
|
// 2. It is safe to move MBBI down past the instruction that I will
|
|
|
|
// be merged into.
|
|
|
|
|
2017-08-30 05:25:51 +08:00
|
|
|
if (MBBI->hasUnmodeledSideEffects()) {
|
2016-08-30 03:15:22 +08:00
|
|
|
// We can't re-order this instruction with respect to other memory
|
2017-08-30 05:25:51 +08:00
|
|
|
// operations, so we fail both conditions mentioned above.
|
2017-04-14 01:53:07 +08:00
|
|
|
return false;
|
2017-08-30 05:25:51 +08:00
|
|
|
}
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2016-08-30 03:15:22 +08:00
|
|
|
if (MBBI->mayLoadOrStore() &&
|
2019-02-19 07:00:26 +08:00
|
|
|
(!memAccessesCanBeReordered(*CI.I, *MBBI, AA) ||
|
|
|
|
!canMoveInstsAcrossMemOp(*MBBI, CI.InstsToMove, AA))) {
|
2016-08-30 03:15:22 +08:00
|
|
|
// We fail condition #1, but we may still be able to satisfy condition
|
|
|
|
// #2. Add this instruction to the move list and then we will check
|
|
|
|
// if condition #2 holds once we have selected the matching instruction.
|
2017-04-14 01:53:07 +08:00
|
|
|
CI.InstsToMove.push_back(&*MBBI);
|
2018-02-23 18:45:56 +08:00
|
|
|
addDefsUsesToList(*MBBI, RegDefsToMove, PhysRegUsesToMove);
|
2016-08-30 03:15:22 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When we match I with another DS instruction we will be moving I down
|
|
|
|
// to the location of the matched instruction any uses of I will need to
|
|
|
|
// be moved down as well.
|
2018-02-23 18:45:56 +08:00
|
|
|
addToListsIfDependent(*MBBI, RegDefsToMove, PhysRegUsesToMove,
|
|
|
|
CI.InstsToMove);
|
2016-08-30 03:15:22 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't merge volatiles.
|
|
|
|
if (MBBI->hasOrderedMemoryRef())
|
2017-04-14 01:53:07 +08:00
|
|
|
return false;
|
2016-08-30 03:15:22 +08:00
|
|
|
|
2016-10-27 16:15:07 +08:00
|
|
|
// Handle a case like
|
|
|
|
// DS_WRITE_B32 addr, v, idx0
|
|
|
|
// w = DS_READ_B32 addr, idx0
|
|
|
|
// DS_WRITE_B32 addr, f(w), idx1
|
|
|
|
// where the DS_READ_B32 ends up in InstsToMove and therefore prevents
|
|
|
|
// merging of the two writes.
|
2018-02-23 18:45:56 +08:00
|
|
|
if (addToListsIfDependent(*MBBI, RegDefsToMove, PhysRegUsesToMove,
|
|
|
|
CI.InstsToMove))
|
2016-10-27 16:15:07 +08:00
|
|
|
continue;
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
bool Match = CI.hasSameBaseAddress(*MBBI);
|
2016-08-30 03:15:22 +08:00
|
|
|
|
2017-11-09 09:52:30 +08:00
|
|
|
if (Match) {
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
CI.setPaired(MBBI, *TII);
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
|
2016-08-30 03:15:22 +08:00
|
|
|
// Check both offsets fit in the reduced range.
|
|
|
|
// We also need to go through the list of instructions that we plan to
|
|
|
|
// move and make sure they are all safe to move down past the merged
|
|
|
|
// instruction.
|
2019-01-11 00:21:08 +08:00
|
|
|
if (widthsFit(*STM, CI) && offsetsCanBeCombined(CI))
|
2019-02-19 07:00:26 +08:00
|
|
|
if (canMoveInstsAcrossMemOp(*MBBI, CI.InstsToMove, AA))
|
2017-04-14 01:53:07 +08:00
|
|
|
return true;
|
2016-08-30 03:15:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We've found a load/store that we couldn't merge for some reason.
|
|
|
|
// We could potentially keep looking, but we'd need to make sure that
|
|
|
|
// it was safe to move I and also all the instruction in InstsToMove
|
|
|
|
// down past this instruction.
|
2017-04-14 01:53:07 +08:00
|
|
|
// check if we can move I across MBBI and if we can move all I's users
|
2019-02-19 07:00:26 +08:00
|
|
|
if (!memAccessesCanBeReordered(*CI.I, *MBBI, AA) ||
|
|
|
|
!canMoveInstsAcrossMemOp(*MBBI, CI.InstsToMove, AA))
|
2016-11-03 22:37:13 +08:00
|
|
|
break;
|
2016-08-30 03:15:22 +08:00
|
|
|
}
|
2017-04-14 01:53:07 +08:00
|
|
|
return false;
|
2014-10-11 06:01:59 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 08:55:57 +08:00
|
|
|
unsigned SILoadStoreOptimizer::read2Opcode(unsigned EltSize) const {
|
|
|
|
if (STM->ldsRequiresM0Init())
|
|
|
|
return (EltSize == 4) ? AMDGPU::DS_READ2_B32 : AMDGPU::DS_READ2_B64;
|
|
|
|
return (EltSize == 4) ? AMDGPU::DS_READ2_B32_gfx9 : AMDGPU::DS_READ2_B64_gfx9;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned SILoadStoreOptimizer::read2ST64Opcode(unsigned EltSize) const {
|
|
|
|
if (STM->ldsRequiresM0Init())
|
|
|
|
return (EltSize == 4) ? AMDGPU::DS_READ2ST64_B32 : AMDGPU::DS_READ2ST64_B64;
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
return (EltSize == 4) ? AMDGPU::DS_READ2ST64_B32_gfx9
|
|
|
|
: AMDGPU::DS_READ2ST64_B64_gfx9;
|
2017-11-29 08:55:57 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
SILoadStoreOptimizer::mergeRead2Pair(CombineInfo &CI) {
|
2017-04-14 01:53:07 +08:00
|
|
|
MachineBasicBlock *MBB = CI.I->getParent();
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
// Be careful, since the addresses could be subregisters themselves in weird
|
|
|
|
// cases, like vectors of pointers.
|
2017-04-14 01:53:07 +08:00
|
|
|
const auto *AddrReg = TII->getNamedOperand(*CI.I, AMDGPU::OpName::addr);
|
2014-10-11 06:12:32 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
const auto *Dest0 = TII->getNamedOperand(*CI.I, AMDGPU::OpName::vdst);
|
|
|
|
const auto *Dest1 = TII->getNamedOperand(*CI.Paired, AMDGPU::OpName::vdst);
|
|
|
|
|
|
|
|
unsigned NewOffset0 = CI.Offset0;
|
|
|
|
unsigned NewOffset1 = CI.Offset1;
|
2018-12-13 00:15:21 +08:00
|
|
|
unsigned Opc =
|
|
|
|
CI.UseST64 ? read2ST64Opcode(CI.EltSize) : read2Opcode(CI.EltSize);
|
2017-04-14 01:53:07 +08:00
|
|
|
|
|
|
|
unsigned SubRegIdx0 = (CI.EltSize == 4) ? AMDGPU::sub0 : AMDGPU::sub0_sub1;
|
|
|
|
unsigned SubRegIdx1 = (CI.EltSize == 4) ? AMDGPU::sub1 : AMDGPU::sub2_sub3;
|
2016-08-27 05:36:47 +08:00
|
|
|
|
|
|
|
if (NewOffset0 > NewOffset1) {
|
|
|
|
// Canonicalize the merged instruction so the smaller offset comes first.
|
|
|
|
std::swap(NewOffset0, NewOffset1);
|
|
|
|
std::swap(SubRegIdx0, SubRegIdx1);
|
|
|
|
}
|
|
|
|
|
2014-10-11 06:12:32 +08:00
|
|
|
assert((isUInt<8>(NewOffset0) && isUInt<8>(NewOffset1)) &&
|
2018-12-13 00:15:21 +08:00
|
|
|
(NewOffset0 != NewOffset1) && "Computed offset doesn't fit");
|
2014-10-11 06:12:32 +08:00
|
|
|
|
|
|
|
const MCInstrDesc &Read2Desc = TII->get(Opc);
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
const TargetRegisterClass *SuperRC =
|
|
|
|
(CI.EltSize == 4) ? &AMDGPU::VReg_64RegClass : &AMDGPU::VReg_128RegClass;
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register DestReg = MRI->createVirtualRegister(SuperRC);
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
DebugLoc DL = CI.I->getDebugLoc();
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register BaseReg = AddrReg->getReg();
|
2018-09-26 07:33:18 +08:00
|
|
|
unsigned BaseSubReg = AddrReg->getSubReg();
|
2017-04-14 01:53:07 +08:00
|
|
|
unsigned BaseRegFlags = 0;
|
|
|
|
if (CI.BaseOff) {
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register ImmReg = MRI->createVirtualRegister(&AMDGPU::SGPR_32RegClass);
|
2018-01-23 05:46:43 +08:00
|
|
|
BuildMI(*MBB, CI.Paired, DL, TII->get(AMDGPU::S_MOV_B32), ImmReg)
|
2018-12-13 00:15:21 +08:00
|
|
|
.addImm(CI.BaseOff);
|
2018-01-23 05:46:43 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
BaseReg = MRI->createVirtualRegister(&AMDGPU::VGPR_32RegClass);
|
|
|
|
BaseRegFlags = RegState::Kill;
|
2017-12-01 06:51:26 +08:00
|
|
|
|
2018-01-23 05:46:43 +08:00
|
|
|
TII->getAddNoCarry(*MBB, CI.Paired, DL, BaseReg)
|
2018-12-13 00:15:21 +08:00
|
|
|
.addReg(ImmReg)
|
2019-03-19 03:35:44 +08:00
|
|
|
.addReg(AddrReg->getReg(), 0, BaseSubReg)
|
|
|
|
.addImm(0); // clamp bit
|
2018-09-26 07:33:18 +08:00
|
|
|
BaseSubReg = 0;
|
2017-04-14 01:53:07 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
MachineInstrBuilder Read2 =
|
|
|
|
BuildMI(*MBB, CI.Paired, DL, Read2Desc, DestReg)
|
|
|
|
.addReg(BaseReg, BaseRegFlags, BaseSubReg) // addr
|
|
|
|
.addImm(NewOffset0) // offset0
|
|
|
|
.addImm(NewOffset1) // offset1
|
|
|
|
.addImm(0) // gds
|
|
|
|
.cloneMergedMemRefs({&*CI.I, &*CI.Paired});
|
2017-04-14 08:33:44 +08:00
|
|
|
|
2016-08-30 19:50:21 +08:00
|
|
|
(void)Read2;
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2015-07-15 01:57:36 +08:00
|
|
|
const MCInstrDesc &CopyDesc = TII->get(TargetOpcode::COPY);
|
|
|
|
|
|
|
|
// Copy to the old destination registers.
|
2017-04-14 01:53:07 +08:00
|
|
|
BuildMI(*MBB, CI.Paired, DL, CopyDesc)
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(*Dest0) // Copy to same destination including flags and sub reg.
|
|
|
|
.addReg(DestReg, 0, SubRegIdx0);
|
2017-04-14 01:53:07 +08:00
|
|
|
MachineInstr *Copy1 = BuildMI(*MBB, CI.Paired, DL, CopyDesc)
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(*Dest1)
|
|
|
|
.addReg(DestReg, RegState::Kill, SubRegIdx1);
|
2015-07-15 01:57:36 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
moveInstsAfter(Copy1, CI.InstsToMove);
|
2015-07-15 01:57:36 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
CI.I->eraseFromParent();
|
|
|
|
CI.Paired->eraseFromParent();
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Inserted read2: " << *Read2 << '\n');
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
return Read2;
|
2014-10-11 06:01:59 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 08:55:57 +08:00
|
|
|
unsigned SILoadStoreOptimizer::write2Opcode(unsigned EltSize) const {
|
|
|
|
if (STM->ldsRequiresM0Init())
|
|
|
|
return (EltSize == 4) ? AMDGPU::DS_WRITE2_B32 : AMDGPU::DS_WRITE2_B64;
|
2018-12-13 00:15:21 +08:00
|
|
|
return (EltSize == 4) ? AMDGPU::DS_WRITE2_B32_gfx9
|
|
|
|
: AMDGPU::DS_WRITE2_B64_gfx9;
|
2017-11-29 08:55:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned SILoadStoreOptimizer::write2ST64Opcode(unsigned EltSize) const {
|
|
|
|
if (STM->ldsRequiresM0Init())
|
2018-12-13 00:15:21 +08:00
|
|
|
return (EltSize == 4) ? AMDGPU::DS_WRITE2ST64_B32
|
|
|
|
: AMDGPU::DS_WRITE2ST64_B64;
|
2017-11-29 08:55:57 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
return (EltSize == 4) ? AMDGPU::DS_WRITE2ST64_B32_gfx9
|
|
|
|
: AMDGPU::DS_WRITE2ST64_B64_gfx9;
|
2017-11-29 08:55:57 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
SILoadStoreOptimizer::mergeWrite2Pair(CombineInfo &CI) {
|
2017-04-14 01:53:07 +08:00
|
|
|
MachineBasicBlock *MBB = CI.I->getParent();
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
// Be sure to use .addOperand(), and not .addReg() with these. We want to be
|
|
|
|
// sure we preserve the subregister index and any register flags set on them.
|
2018-12-13 00:15:21 +08:00
|
|
|
const MachineOperand *AddrReg =
|
|
|
|
TII->getNamedOperand(*CI.I, AMDGPU::OpName::addr);
|
|
|
|
const MachineOperand *Data0 =
|
|
|
|
TII->getNamedOperand(*CI.I, AMDGPU::OpName::data0);
|
|
|
|
const MachineOperand *Data1 =
|
|
|
|
TII->getNamedOperand(*CI.Paired, AMDGPU::OpName::data0);
|
2014-10-11 06:12:32 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
unsigned NewOffset0 = CI.Offset0;
|
|
|
|
unsigned NewOffset1 = CI.Offset1;
|
2018-12-13 00:15:21 +08:00
|
|
|
unsigned Opc =
|
|
|
|
CI.UseST64 ? write2ST64Opcode(CI.EltSize) : write2Opcode(CI.EltSize);
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2016-08-27 05:36:47 +08:00
|
|
|
if (NewOffset0 > NewOffset1) {
|
|
|
|
// Canonicalize the merged instruction so the smaller offset comes first.
|
|
|
|
std::swap(NewOffset0, NewOffset1);
|
|
|
|
std::swap(Data0, Data1);
|
|
|
|
}
|
|
|
|
|
2014-10-11 06:12:32 +08:00
|
|
|
assert((isUInt<8>(NewOffset0) && isUInt<8>(NewOffset1)) &&
|
2018-12-13 00:15:21 +08:00
|
|
|
(NewOffset0 != NewOffset1) && "Computed offset doesn't fit");
|
2014-10-11 06:12:32 +08:00
|
|
|
|
|
|
|
const MCInstrDesc &Write2Desc = TII->get(Opc);
|
2017-04-14 01:53:07 +08:00
|
|
|
DebugLoc DL = CI.I->getDebugLoc();
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register BaseReg = AddrReg->getReg();
|
2018-09-26 07:33:18 +08:00
|
|
|
unsigned BaseSubReg = AddrReg->getSubReg();
|
2017-04-14 01:53:07 +08:00
|
|
|
unsigned BaseRegFlags = 0;
|
|
|
|
if (CI.BaseOff) {
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register ImmReg = MRI->createVirtualRegister(&AMDGPU::SGPR_32RegClass);
|
2018-01-23 05:46:43 +08:00
|
|
|
BuildMI(*MBB, CI.Paired, DL, TII->get(AMDGPU::S_MOV_B32), ImmReg)
|
2018-12-13 00:15:21 +08:00
|
|
|
.addImm(CI.BaseOff);
|
2018-01-23 05:46:43 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
BaseReg = MRI->createVirtualRegister(&AMDGPU::VGPR_32RegClass);
|
|
|
|
BaseRegFlags = RegState::Kill;
|
2017-12-01 06:51:26 +08:00
|
|
|
|
2018-01-23 05:46:43 +08:00
|
|
|
TII->getAddNoCarry(*MBB, CI.Paired, DL, BaseReg)
|
2018-12-13 00:15:21 +08:00
|
|
|
.addReg(ImmReg)
|
2019-03-19 03:35:44 +08:00
|
|
|
.addReg(AddrReg->getReg(), 0, BaseSubReg)
|
|
|
|
.addImm(0); // clamp bit
|
2018-09-26 07:33:18 +08:00
|
|
|
BaseSubReg = 0;
|
2017-04-14 01:53:07 +08:00
|
|
|
}
|
2014-10-11 06:12:32 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
MachineInstrBuilder Write2 =
|
|
|
|
BuildMI(*MBB, CI.Paired, DL, Write2Desc)
|
|
|
|
.addReg(BaseReg, BaseRegFlags, BaseSubReg) // addr
|
|
|
|
.add(*Data0) // data0
|
|
|
|
.add(*Data1) // data1
|
|
|
|
.addImm(NewOffset0) // offset0
|
|
|
|
.addImm(NewOffset1) // offset1
|
|
|
|
.addImm(0) // gds
|
|
|
|
.cloneMergedMemRefs({&*CI.I, &*CI.Paired});
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
moveInstsAfter(Write2, CI.InstsToMove);
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
CI.I->eraseFromParent();
|
|
|
|
CI.Paired->eraseFromParent();
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Inserted write2 inst: " << *Write2 << '\n');
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
return Write2;
|
2014-10-11 06:01:59 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
SILoadStoreOptimizer::mergeSBufferLoadImmPair(CombineInfo &CI) {
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
MachineBasicBlock *MBB = CI.I->getParent();
|
|
|
|
DebugLoc DL = CI.I->getDebugLoc();
|
2018-12-13 00:15:21 +08:00
|
|
|
const unsigned Opcode = getNewOpcode(CI);
|
|
|
|
|
|
|
|
const TargetRegisterClass *SuperRC = getTargetRegisterClass(CI);
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register DestReg = MRI->createVirtualRegister(SuperRC);
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
unsigned MergedOffset = std::min(CI.Offset0, CI.Offset1);
|
|
|
|
|
AMDGPU/LoadStoreOptimizer: combine MMOs when merging instructions
Summary:
The LoadStoreOptimizer was creating instructions with 2
MachineMemOperands, which meant they were assumed to alias with all other instructions,
because MachineInstr:mayAlias() returns true when an instruction has multiple
MachineMemOperands.
This was preventing these instructions from being merged again, and was
giving the scheduler less freedom to reorder them.
Reviewers: arsenm, nhaehnle
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65036
llvm-svn: 367237
2019-07-30 00:40:58 +08:00
|
|
|
// It shouldn't be possible to get this far if the two instructions
|
|
|
|
// don't have a single memoperand, because MachineInstr::mayAlias()
|
|
|
|
// will return true if this is the case.
|
|
|
|
assert(CI.I->hasOneMemOperand() && CI.Paired->hasOneMemOperand());
|
|
|
|
|
|
|
|
const MachineMemOperand *MMOa = *CI.I->memoperands_begin();
|
|
|
|
const MachineMemOperand *MMOb = *CI.Paired->memoperands_begin();
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
MachineInstr *New =
|
|
|
|
BuildMI(*MBB, CI.Paired, DL, TII->get(Opcode), DestReg)
|
|
|
|
.add(*TII->getNamedOperand(*CI.I, AMDGPU::OpName::sbase))
|
|
|
|
.addImm(MergedOffset) // offset
|
|
|
|
.addImm(CI.GLC0) // glc
|
|
|
|
.addImm(CI.DLC0) // dlc
|
|
|
|
.addMemOperand(combineKnownAdjacentMMOs(*MBB->getParent(), MMOa, MMOb));
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
std::pair<unsigned, unsigned> SubRegIdx = getSubRegIdxs(CI);
|
|
|
|
const unsigned SubRegIdx0 = std::get<0>(SubRegIdx);
|
|
|
|
const unsigned SubRegIdx1 = std::get<1>(SubRegIdx);
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
|
|
|
|
// Copy to the old destination registers.
|
|
|
|
const MCInstrDesc &CopyDesc = TII->get(TargetOpcode::COPY);
|
|
|
|
const auto *Dest0 = TII->getNamedOperand(*CI.I, AMDGPU::OpName::sdst);
|
|
|
|
const auto *Dest1 = TII->getNamedOperand(*CI.Paired, AMDGPU::OpName::sdst);
|
|
|
|
|
|
|
|
BuildMI(*MBB, CI.Paired, DL, CopyDesc)
|
|
|
|
.add(*Dest0) // Copy to same destination including flags and sub reg.
|
|
|
|
.addReg(DestReg, 0, SubRegIdx0);
|
|
|
|
MachineInstr *Copy1 = BuildMI(*MBB, CI.Paired, DL, CopyDesc)
|
|
|
|
.add(*Dest1)
|
|
|
|
.addReg(DestReg, RegState::Kill, SubRegIdx1);
|
|
|
|
|
|
|
|
moveInstsAfter(Copy1, CI.InstsToMove);
|
|
|
|
|
|
|
|
CI.I->eraseFromParent();
|
|
|
|
CI.Paired->eraseFromParent();
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
return New;
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
SILoadStoreOptimizer::mergeBufferLoadPair(CombineInfo &CI) {
|
2017-11-09 09:52:30 +08:00
|
|
|
MachineBasicBlock *MBB = CI.I->getParent();
|
|
|
|
DebugLoc DL = CI.I->getDebugLoc();
|
2017-11-09 09:52:36 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
const unsigned Opcode = getNewOpcode(CI);
|
2017-11-09 09:52:30 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
const TargetRegisterClass *SuperRC = getTargetRegisterClass(CI);
|
|
|
|
|
|
|
|
// Copy to the new source register.
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register DestReg = MRI->createVirtualRegister(SuperRC);
|
2017-11-09 09:52:30 +08:00
|
|
|
unsigned MergedOffset = std::min(CI.Offset0, CI.Offset1);
|
|
|
|
|
2017-11-09 09:52:36 +08:00
|
|
|
auto MIB = BuildMI(*MBB, CI.Paired, DL, TII->get(Opcode), DestReg);
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
const unsigned Regs = getRegs(Opcode, *TII);
|
2018-12-13 00:15:21 +08:00
|
|
|
|
|
|
|
if (Regs & VADDR)
|
|
|
|
MIB.add(*TII->getNamedOperand(*CI.I, AMDGPU::OpName::vaddr));
|
2017-11-09 09:52:36 +08:00
|
|
|
|
AMDGPU/LoadStoreOptimizer: combine MMOs when merging instructions
Summary:
The LoadStoreOptimizer was creating instructions with 2
MachineMemOperands, which meant they were assumed to alias with all other instructions,
because MachineInstr:mayAlias() returns true when an instruction has multiple
MachineMemOperands.
This was preventing these instructions from being merged again, and was
giving the scheduler less freedom to reorder them.
Reviewers: arsenm, nhaehnle
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65036
llvm-svn: 367237
2019-07-30 00:40:58 +08:00
|
|
|
// It shouldn't be possible to get this far if the two instructions
|
|
|
|
// don't have a single memoperand, because MachineInstr::mayAlias()
|
|
|
|
// will return true if this is the case.
|
|
|
|
assert(CI.I->hasOneMemOperand() && CI.Paired->hasOneMemOperand());
|
|
|
|
|
|
|
|
const MachineMemOperand *MMOa = *CI.I->memoperands_begin();
|
|
|
|
const MachineMemOperand *MMOb = *CI.Paired->memoperands_begin();
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
MachineInstr *New =
|
|
|
|
MIB.add(*TII->getNamedOperand(*CI.I, AMDGPU::OpName::srsrc))
|
|
|
|
.add(*TII->getNamedOperand(*CI.I, AMDGPU::OpName::soffset))
|
|
|
|
.addImm(MergedOffset) // offset
|
|
|
|
.addImm(CI.GLC0) // glc
|
|
|
|
.addImm(CI.SLC0) // slc
|
|
|
|
.addImm(0) // tfe
|
|
|
|
.addImm(CI.DLC0) // dlc
|
|
|
|
.addImm(0) // swz
|
|
|
|
.addMemOperand(combineKnownAdjacentMMOs(*MBB->getParent(), MMOa, MMOb));
|
2017-11-09 09:52:30 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
std::pair<unsigned, unsigned> SubRegIdx = getSubRegIdxs(CI);
|
|
|
|
const unsigned SubRegIdx0 = std::get<0>(SubRegIdx);
|
|
|
|
const unsigned SubRegIdx1 = std::get<1>(SubRegIdx);
|
2017-11-09 09:52:30 +08:00
|
|
|
|
|
|
|
// Copy to the old destination registers.
|
|
|
|
const MCInstrDesc &CopyDesc = TII->get(TargetOpcode::COPY);
|
|
|
|
const auto *Dest0 = TII->getNamedOperand(*CI.I, AMDGPU::OpName::vdata);
|
|
|
|
const auto *Dest1 = TII->getNamedOperand(*CI.Paired, AMDGPU::OpName::vdata);
|
|
|
|
|
|
|
|
BuildMI(*MBB, CI.Paired, DL, CopyDesc)
|
|
|
|
.add(*Dest0) // Copy to same destination including flags and sub reg.
|
|
|
|
.addReg(DestReg, 0, SubRegIdx0);
|
|
|
|
MachineInstr *Copy1 = BuildMI(*MBB, CI.Paired, DL, CopyDesc)
|
|
|
|
.add(*Dest1)
|
|
|
|
.addReg(DestReg, RegState::Kill, SubRegIdx1);
|
|
|
|
|
|
|
|
moveInstsAfter(Copy1, CI.InstsToMove);
|
|
|
|
|
|
|
|
CI.I->eraseFromParent();
|
|
|
|
CI.Paired->eraseFromParent();
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
return New;
|
2017-11-09 09:52:30 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
unsigned SILoadStoreOptimizer::getNewOpcode(const CombineInfo &CI) {
|
|
|
|
const unsigned Width = CI.Width0 + CI.Width1;
|
|
|
|
|
|
|
|
switch (CI.InstClass) {
|
|
|
|
default:
|
2019-08-18 08:20:43 +08:00
|
|
|
// FIXME: Handle d16 correctly
|
2018-12-13 00:15:21 +08:00
|
|
|
return AMDGPU::getMUBUFOpcode(CI.InstClass, Width);
|
|
|
|
case UNKNOWN:
|
|
|
|
llvm_unreachable("Unknown instruction class");
|
|
|
|
case S_BUFFER_LOAD_IMM:
|
|
|
|
switch (Width) {
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case 2:
|
|
|
|
return AMDGPU::S_BUFFER_LOAD_DWORDX2_IMM;
|
|
|
|
case 4:
|
|
|
|
return AMDGPU::S_BUFFER_LOAD_DWORDX4_IMM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<unsigned, unsigned>
|
|
|
|
SILoadStoreOptimizer::getSubRegIdxs(const CombineInfo &CI) {
|
|
|
|
if (CI.Offset0 > CI.Offset1) {
|
|
|
|
switch (CI.Width0) {
|
|
|
|
default:
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
case 1:
|
|
|
|
switch (CI.Width1) {
|
|
|
|
default:
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
case 1:
|
|
|
|
return std::make_pair(AMDGPU::sub1, AMDGPU::sub0);
|
|
|
|
case 2:
|
|
|
|
return std::make_pair(AMDGPU::sub2, AMDGPU::sub0_sub1);
|
|
|
|
case 3:
|
|
|
|
return std::make_pair(AMDGPU::sub3, AMDGPU::sub0_sub1_sub2);
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
switch (CI.Width1) {
|
|
|
|
default:
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
case 1:
|
|
|
|
return std::make_pair(AMDGPU::sub1_sub2, AMDGPU::sub0);
|
|
|
|
case 2:
|
|
|
|
return std::make_pair(AMDGPU::sub2_sub3, AMDGPU::sub0_sub1);
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
switch (CI.Width1) {
|
|
|
|
default:
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
case 1:
|
|
|
|
return std::make_pair(AMDGPU::sub1_sub2_sub3, AMDGPU::sub0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (CI.Width0) {
|
|
|
|
default:
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
case 1:
|
|
|
|
switch (CI.Width1) {
|
|
|
|
default:
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
case 1:
|
|
|
|
return std::make_pair(AMDGPU::sub0, AMDGPU::sub1);
|
|
|
|
case 2:
|
|
|
|
return std::make_pair(AMDGPU::sub0, AMDGPU::sub1_sub2);
|
|
|
|
case 3:
|
|
|
|
return std::make_pair(AMDGPU::sub0, AMDGPU::sub1_sub2_sub3);
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
switch (CI.Width1) {
|
|
|
|
default:
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
case 1:
|
|
|
|
return std::make_pair(AMDGPU::sub0_sub1, AMDGPU::sub2);
|
|
|
|
case 2:
|
|
|
|
return std::make_pair(AMDGPU::sub0_sub1, AMDGPU::sub2_sub3);
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
switch (CI.Width1) {
|
|
|
|
default:
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
case 1:
|
|
|
|
return std::make_pair(AMDGPU::sub0_sub1_sub2, AMDGPU::sub3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const TargetRegisterClass *
|
|
|
|
SILoadStoreOptimizer::getTargetRegisterClass(const CombineInfo &CI) {
|
|
|
|
if (CI.InstClass == S_BUFFER_LOAD_IMM) {
|
|
|
|
switch (CI.Width0 + CI.Width1) {
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
case 2:
|
|
|
|
return &AMDGPU::SReg_64_XEXECRegClass;
|
|
|
|
case 4:
|
|
|
|
return &AMDGPU::SReg_128RegClass;
|
|
|
|
case 8:
|
|
|
|
return &AMDGPU::SReg_256RegClass;
|
|
|
|
case 16:
|
|
|
|
return &AMDGPU::SReg_512RegClass;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (CI.Width0 + CI.Width1) {
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
case 2:
|
|
|
|
return &AMDGPU::VReg_64RegClass;
|
|
|
|
case 3:
|
|
|
|
return &AMDGPU::VReg_96RegClass;
|
|
|
|
case 4:
|
|
|
|
return &AMDGPU::VReg_128RegClass;
|
|
|
|
}
|
|
|
|
}
|
2017-11-09 09:52:55 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
SILoadStoreOptimizer::mergeBufferStorePair(CombineInfo &CI) {
|
2017-11-09 09:52:55 +08:00
|
|
|
MachineBasicBlock *MBB = CI.I->getParent();
|
|
|
|
DebugLoc DL = CI.I->getDebugLoc();
|
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
const unsigned Opcode = getNewOpcode(CI);
|
2017-11-09 09:52:55 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
std::pair<unsigned, unsigned> SubRegIdx = getSubRegIdxs(CI);
|
|
|
|
const unsigned SubRegIdx0 = std::get<0>(SubRegIdx);
|
|
|
|
const unsigned SubRegIdx1 = std::get<1>(SubRegIdx);
|
2017-11-09 09:52:55 +08:00
|
|
|
|
|
|
|
// Copy to the new source register.
|
2018-12-13 00:15:21 +08:00
|
|
|
const TargetRegisterClass *SuperRC = getTargetRegisterClass(CI);
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register SrcReg = MRI->createVirtualRegister(SuperRC);
|
2017-11-09 09:52:55 +08:00
|
|
|
|
|
|
|
const auto *Src0 = TII->getNamedOperand(*CI.I, AMDGPU::OpName::vdata);
|
|
|
|
const auto *Src1 = TII->getNamedOperand(*CI.Paired, AMDGPU::OpName::vdata);
|
|
|
|
|
|
|
|
BuildMI(*MBB, CI.Paired, DL, TII->get(AMDGPU::REG_SEQUENCE), SrcReg)
|
|
|
|
.add(*Src0)
|
|
|
|
.addImm(SubRegIdx0)
|
|
|
|
.add(*Src1)
|
|
|
|
.addImm(SubRegIdx1);
|
|
|
|
|
|
|
|
auto MIB = BuildMI(*MBB, CI.Paired, DL, TII->get(Opcode))
|
2018-12-13 00:15:21 +08:00
|
|
|
.addReg(SrcReg, RegState::Kill);
|
2017-11-09 09:52:55 +08:00
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Add helper functions for working with CombineInfo
Summary:
This is a refactoring that will make future improvements to this pass easier.
This change should not change the behavior of the pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Reviewed By: nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65496
llvm-svn: 373366
2019-10-02 01:56:59 +08:00
|
|
|
const unsigned Regs = getRegs(Opcode, *TII);
|
2018-12-13 00:15:21 +08:00
|
|
|
|
|
|
|
if (Regs & VADDR)
|
|
|
|
MIB.add(*TII->getNamedOperand(*CI.I, AMDGPU::OpName::vaddr));
|
2017-11-09 09:52:55 +08:00
|
|
|
|
AMDGPU/LoadStoreOptimizer: combine MMOs when merging instructions
Summary:
The LoadStoreOptimizer was creating instructions with 2
MachineMemOperands, which meant they were assumed to alias with all other instructions,
because MachineInstr:mayAlias() returns true when an instruction has multiple
MachineMemOperands.
This was preventing these instructions from being merged again, and was
giving the scheduler less freedom to reorder them.
Reviewers: arsenm, nhaehnle
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65036
llvm-svn: 367237
2019-07-30 00:40:58 +08:00
|
|
|
|
|
|
|
// It shouldn't be possible to get this far if the two instructions
|
|
|
|
// don't have a single memoperand, because MachineInstr::mayAlias()
|
|
|
|
// will return true if this is the case.
|
|
|
|
assert(CI.I->hasOneMemOperand() && CI.Paired->hasOneMemOperand());
|
|
|
|
|
|
|
|
const MachineMemOperand *MMOa = *CI.I->memoperands_begin();
|
|
|
|
const MachineMemOperand *MMOb = *CI.Paired->memoperands_begin();
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
MachineInstr *New =
|
|
|
|
MIB.add(*TII->getNamedOperand(*CI.I, AMDGPU::OpName::srsrc))
|
|
|
|
.add(*TII->getNamedOperand(*CI.I, AMDGPU::OpName::soffset))
|
|
|
|
.addImm(std::min(CI.Offset0, CI.Offset1)) // offset
|
|
|
|
.addImm(CI.GLC0) // glc
|
|
|
|
.addImm(CI.SLC0) // slc
|
|
|
|
.addImm(0) // tfe
|
|
|
|
.addImm(CI.DLC0) // dlc
|
|
|
|
.addImm(0) // swz
|
|
|
|
.addMemOperand(combineKnownAdjacentMMOs(*MBB->getParent(), MMOa, MMOb));
|
2017-11-09 09:52:55 +08:00
|
|
|
|
|
|
|
moveInstsAfter(MIB, CI.InstsToMove);
|
|
|
|
|
|
|
|
CI.I->eraseFromParent();
|
|
|
|
CI.Paired->eraseFromParent();
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
return New;
|
2017-11-09 09:52:55 +08:00
|
|
|
}
|
|
|
|
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
MachineOperand
|
AMDGPU/SILoadStoreOptimizer: Add const to more functions
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65901
llvm-svn: 372298
2019-09-19 12:39:45 +08:00
|
|
|
SILoadStoreOptimizer::createRegOrImm(int32_t Val, MachineInstr &MI) const {
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
APInt V(32, Val, true);
|
|
|
|
if (TII->isInlineConstant(V))
|
|
|
|
return MachineOperand::CreateImm(Val);
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = MRI->createVirtualRegister(&AMDGPU::SReg_32RegClass);
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
MachineInstr *Mov =
|
|
|
|
BuildMI(*MI.getParent(), MI.getIterator(), MI.getDebugLoc(),
|
|
|
|
TII->get(AMDGPU::S_MOV_B32), Reg)
|
|
|
|
.addImm(Val);
|
2018-12-15 20:25:22 +08:00
|
|
|
(void)Mov;
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
LLVM_DEBUG(dbgs() << " "; Mov->dump());
|
|
|
|
return MachineOperand::CreateReg(Reg, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute base address using Addr and return the final register.
|
|
|
|
unsigned SILoadStoreOptimizer::computeBase(MachineInstr &MI,
|
AMDGPU/SILoadStoreOptimizer: Add const to more functions
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65901
llvm-svn: 372298
2019-09-19 12:39:45 +08:00
|
|
|
const MemAddress &Addr) const {
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
MachineBasicBlock *MBB = MI.getParent();
|
|
|
|
MachineBasicBlock::iterator MBBI = MI.getIterator();
|
|
|
|
DebugLoc DL = MI.getDebugLoc();
|
|
|
|
|
|
|
|
assert((TRI->getRegSizeInBits(Addr.Base.LoReg, *MRI) == 32 ||
|
|
|
|
Addr.Base.LoSubReg) &&
|
|
|
|
"Expected 32-bit Base-Register-Low!!");
|
|
|
|
|
|
|
|
assert((TRI->getRegSizeInBits(Addr.Base.HiReg, *MRI) == 32 ||
|
|
|
|
Addr.Base.HiSubReg) &&
|
|
|
|
"Expected 32-bit Base-Register-Hi!!");
|
|
|
|
|
|
|
|
LLVM_DEBUG(dbgs() << " Re-Computed Anchor-Base:\n");
|
|
|
|
MachineOperand OffsetLo = createRegOrImm(static_cast<int32_t>(Addr.Offset), MI);
|
|
|
|
MachineOperand OffsetHi =
|
|
|
|
createRegOrImm(static_cast<int32_t>(Addr.Offset >> 32), MI);
|
2019-06-17 01:13:09 +08:00
|
|
|
|
|
|
|
const auto *CarryRC = TRI->getRegClass(AMDGPU::SReg_1_XEXECRegClassID);
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register CarryReg = MRI->createVirtualRegister(CarryRC);
|
|
|
|
Register DeadCarryReg = MRI->createVirtualRegister(CarryRC);
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register DestSub0 = MRI->createVirtualRegister(&AMDGPU::VGPR_32RegClass);
|
|
|
|
Register DestSub1 = MRI->createVirtualRegister(&AMDGPU::VGPR_32RegClass);
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
MachineInstr *LoHalf =
|
|
|
|
BuildMI(*MBB, MBBI, DL, TII->get(AMDGPU::V_ADD_I32_e64), DestSub0)
|
|
|
|
.addReg(CarryReg, RegState::Define)
|
|
|
|
.addReg(Addr.Base.LoReg, 0, Addr.Base.LoSubReg)
|
2019-03-19 03:35:44 +08:00
|
|
|
.add(OffsetLo)
|
|
|
|
.addImm(0); // clamp bit
|
2018-12-15 20:25:22 +08:00
|
|
|
(void)LoHalf;
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
LLVM_DEBUG(dbgs() << " "; LoHalf->dump(););
|
|
|
|
|
|
|
|
MachineInstr *HiHalf =
|
|
|
|
BuildMI(*MBB, MBBI, DL, TII->get(AMDGPU::V_ADDC_U32_e64), DestSub1)
|
|
|
|
.addReg(DeadCarryReg, RegState::Define | RegState::Dead)
|
|
|
|
.addReg(Addr.Base.HiReg, 0, Addr.Base.HiSubReg)
|
|
|
|
.add(OffsetHi)
|
2019-03-19 03:35:44 +08:00
|
|
|
.addReg(CarryReg, RegState::Kill)
|
|
|
|
.addImm(0); // clamp bit
|
2018-12-15 20:25:22 +08:00
|
|
|
(void)HiHalf;
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
LLVM_DEBUG(dbgs() << " "; HiHalf->dump(););
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register FullDestReg = MRI->createVirtualRegister(&AMDGPU::VReg_64RegClass);
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
MachineInstr *FullBase =
|
|
|
|
BuildMI(*MBB, MBBI, DL, TII->get(TargetOpcode::REG_SEQUENCE), FullDestReg)
|
|
|
|
.addReg(DestSub0)
|
|
|
|
.addImm(AMDGPU::sub0)
|
|
|
|
.addReg(DestSub1)
|
|
|
|
.addImm(AMDGPU::sub1);
|
2018-12-15 20:25:22 +08:00
|
|
|
(void)FullBase;
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
LLVM_DEBUG(dbgs() << " "; FullBase->dump(); dbgs() << "\n";);
|
|
|
|
|
|
|
|
return FullDestReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update base and offset with the NewBase and NewOffset in MI.
|
|
|
|
void SILoadStoreOptimizer::updateBaseAndOffset(MachineInstr &MI,
|
|
|
|
unsigned NewBase,
|
AMDGPU/SILoadStoreOptimizer: Add const to more functions
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65901
llvm-svn: 372298
2019-09-19 12:39:45 +08:00
|
|
|
int32_t NewOffset) const {
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
TII->getNamedOperand(MI, AMDGPU::OpName::vaddr)->setReg(NewBase);
|
|
|
|
TII->getNamedOperand(MI, AMDGPU::OpName::offset)->setImm(NewOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<int32_t>
|
AMDGPU/SILoadStoreOptimizer: Add const to more functions
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65901
llvm-svn: 372298
2019-09-19 12:39:45 +08:00
|
|
|
SILoadStoreOptimizer::extractConstOffset(const MachineOperand &Op) const {
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
if (Op.isImm())
|
|
|
|
return Op.getImm();
|
|
|
|
|
|
|
|
if (!Op.isReg())
|
|
|
|
return None;
|
|
|
|
|
|
|
|
MachineInstr *Def = MRI->getUniqueVRegDef(Op.getReg());
|
|
|
|
if (!Def || Def->getOpcode() != AMDGPU::S_MOV_B32 ||
|
|
|
|
!Def->getOperand(1).isImm())
|
|
|
|
return None;
|
|
|
|
|
|
|
|
return Def->getOperand(1).getImm();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Analyze Base and extracts:
|
|
|
|
// - 32bit base registers, subregisters
|
|
|
|
// - 64bit constant offset
|
|
|
|
// Expecting base computation as:
|
|
|
|
// %OFFSET0:sgpr_32 = S_MOV_B32 8000
|
|
|
|
// %LO:vgpr_32, %c:sreg_64_xexec =
|
|
|
|
// V_ADD_I32_e64 %BASE_LO:vgpr_32, %103:sgpr_32,
|
|
|
|
// %HI:vgpr_32, = V_ADDC_U32_e64 %BASE_HI:vgpr_32, 0, killed %c:sreg_64_xexec
|
|
|
|
// %Base:vreg_64 =
|
|
|
|
// REG_SEQUENCE %LO:vgpr_32, %subreg.sub0, %HI:vgpr_32, %subreg.sub1
|
|
|
|
void SILoadStoreOptimizer::processBaseWithConstOffset(const MachineOperand &Base,
|
AMDGPU/SILoadStoreOptimizer: Add const to more functions
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65901
llvm-svn: 372298
2019-09-19 12:39:45 +08:00
|
|
|
MemAddress &Addr) const {
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
if (!Base.isReg())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MachineInstr *Def = MRI->getUniqueVRegDef(Base.getReg());
|
|
|
|
if (!Def || Def->getOpcode() != AMDGPU::REG_SEQUENCE
|
|
|
|
|| Def->getNumOperands() != 5)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MachineOperand BaseLo = Def->getOperand(1);
|
|
|
|
MachineOperand BaseHi = Def->getOperand(3);
|
|
|
|
if (!BaseLo.isReg() || !BaseHi.isReg())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MachineInstr *BaseLoDef = MRI->getUniqueVRegDef(BaseLo.getReg());
|
|
|
|
MachineInstr *BaseHiDef = MRI->getUniqueVRegDef(BaseHi.getReg());
|
|
|
|
|
|
|
|
if (!BaseLoDef || BaseLoDef->getOpcode() != AMDGPU::V_ADD_I32_e64 ||
|
|
|
|
!BaseHiDef || BaseHiDef->getOpcode() != AMDGPU::V_ADDC_U32_e64)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto *Src0 = TII->getNamedOperand(*BaseLoDef, AMDGPU::OpName::src0);
|
|
|
|
const auto *Src1 = TII->getNamedOperand(*BaseLoDef, AMDGPU::OpName::src1);
|
|
|
|
|
|
|
|
auto Offset0P = extractConstOffset(*Src0);
|
|
|
|
if (Offset0P)
|
|
|
|
BaseLo = *Src1;
|
|
|
|
else {
|
|
|
|
if (!(Offset0P = extractConstOffset(*Src1)))
|
|
|
|
return;
|
|
|
|
BaseLo = *Src0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Src0 = TII->getNamedOperand(*BaseHiDef, AMDGPU::OpName::src0);
|
|
|
|
Src1 = TII->getNamedOperand(*BaseHiDef, AMDGPU::OpName::src1);
|
|
|
|
|
|
|
|
if (Src0->isImm())
|
|
|
|
std::swap(Src0, Src1);
|
|
|
|
|
|
|
|
if (!Src1->isImm())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint64_t Offset1 = Src1->getImm();
|
|
|
|
BaseHi = *Src0;
|
|
|
|
|
|
|
|
Addr.Base.LoReg = BaseLo.getReg();
|
|
|
|
Addr.Base.HiReg = BaseHi.getReg();
|
|
|
|
Addr.Base.LoSubReg = BaseLo.getSubReg();
|
|
|
|
Addr.Base.HiSubReg = BaseHi.getSubReg();
|
|
|
|
Addr.Offset = (*Offset0P & 0x00000000ffffffff) | (Offset1 << 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SILoadStoreOptimizer::promoteConstantOffsetToImm(
|
|
|
|
MachineInstr &MI,
|
|
|
|
MemInfoMap &Visited,
|
AMDGPU/SILoadStoreOptimizer: Add const to more functions
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65901
llvm-svn: 372298
2019-09-19 12:39:45 +08:00
|
|
|
SmallPtrSet<MachineInstr *, 4> &AnchorList) const {
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
|
2019-09-06 23:33:53 +08:00
|
|
|
if (!(MI.mayLoad() ^ MI.mayStore()))
|
|
|
|
return false;
|
|
|
|
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
// TODO: Support flat and scratch.
|
2019-09-06 23:33:53 +08:00
|
|
|
if (AMDGPU::getGlobalSaddrOp(MI.getOpcode()) < 0)
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
return false;
|
|
|
|
|
2019-09-06 23:33:53 +08:00
|
|
|
if (MI.mayLoad() && TII->getNamedOperand(MI, AMDGPU::OpName::vdata) != NULL)
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (AnchorList.count(&MI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LLVM_DEBUG(dbgs() << "\nTryToPromoteConstantOffsetToImmFor "; MI.dump());
|
|
|
|
|
|
|
|
if (TII->getNamedOperand(MI, AMDGPU::OpName::offset)->getImm()) {
|
|
|
|
LLVM_DEBUG(dbgs() << " Const-offset is already promoted.\n";);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step1: Find the base-registers and a 64bit constant offset.
|
|
|
|
MachineOperand &Base = *TII->getNamedOperand(MI, AMDGPU::OpName::vaddr);
|
|
|
|
MemAddress MAddr;
|
|
|
|
if (Visited.find(&MI) == Visited.end()) {
|
|
|
|
processBaseWithConstOffset(Base, MAddr);
|
|
|
|
Visited[&MI] = MAddr;
|
|
|
|
} else
|
|
|
|
MAddr = Visited[&MI];
|
|
|
|
|
|
|
|
if (MAddr.Offset == 0) {
|
|
|
|
LLVM_DEBUG(dbgs() << " Failed to extract constant-offset or there are no"
|
|
|
|
" constant offsets that can be promoted.\n";);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVM_DEBUG(dbgs() << " BASE: {" << MAddr.Base.HiReg << ", "
|
|
|
|
<< MAddr.Base.LoReg << "} Offset: " << MAddr.Offset << "\n\n";);
|
|
|
|
|
|
|
|
// Step2: Traverse through MI's basic block and find an anchor(that has the
|
|
|
|
// same base-registers) with the highest 13bit distance from MI's offset.
|
|
|
|
// E.g. (64bit loads)
|
|
|
|
// bb:
|
|
|
|
// addr1 = &a + 4096; load1 = load(addr1, 0)
|
|
|
|
// addr2 = &a + 6144; load2 = load(addr2, 0)
|
|
|
|
// addr3 = &a + 8192; load3 = load(addr3, 0)
|
|
|
|
// addr4 = &a + 10240; load4 = load(addr4, 0)
|
|
|
|
// addr5 = &a + 12288; load5 = load(addr5, 0)
|
|
|
|
//
|
|
|
|
// Starting from the first load, the optimization will try to find a new base
|
|
|
|
// from which (&a + 4096) has 13 bit distance. Both &a + 6144 and &a + 8192
|
|
|
|
// has 13bit distance from &a + 4096. The heuristic considers &a + 8192
|
|
|
|
// as the new-base(anchor) because of the maximum distance which can
|
|
|
|
// accomodate more intermediate bases presumeably.
|
|
|
|
//
|
|
|
|
// Step3: move (&a + 8192) above load1. Compute and promote offsets from
|
|
|
|
// (&a + 8192) for load1, load2, load4.
|
|
|
|
// addr = &a + 8192
|
|
|
|
// load1 = load(addr, -4096)
|
|
|
|
// load2 = load(addr, -2048)
|
|
|
|
// load3 = load(addr, 0)
|
|
|
|
// load4 = load(addr, 2048)
|
|
|
|
// addr5 = &a + 12288; load5 = load(addr5, 0)
|
|
|
|
//
|
|
|
|
MachineInstr *AnchorInst = nullptr;
|
|
|
|
MemAddress AnchorAddr;
|
|
|
|
uint32_t MaxDist = std::numeric_limits<uint32_t>::min();
|
|
|
|
SmallVector<std::pair<MachineInstr *, int64_t>, 4> InstsWCommonBase;
|
|
|
|
|
|
|
|
MachineBasicBlock *MBB = MI.getParent();
|
|
|
|
MachineBasicBlock::iterator E = MBB->end();
|
|
|
|
MachineBasicBlock::iterator MBBI = MI.getIterator();
|
|
|
|
++MBBI;
|
|
|
|
const SITargetLowering *TLI =
|
|
|
|
static_cast<const SITargetLowering *>(STM->getTargetLowering());
|
|
|
|
|
|
|
|
for ( ; MBBI != E; ++MBBI) {
|
|
|
|
MachineInstr &MINext = *MBBI;
|
|
|
|
// TODO: Support finding an anchor(with same base) from store addresses or
|
|
|
|
// any other load addresses where the opcodes are different.
|
|
|
|
if (MINext.getOpcode() != MI.getOpcode() ||
|
|
|
|
TII->getNamedOperand(MINext, AMDGPU::OpName::offset)->getImm())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const MachineOperand &BaseNext =
|
|
|
|
*TII->getNamedOperand(MINext, AMDGPU::OpName::vaddr);
|
|
|
|
MemAddress MAddrNext;
|
|
|
|
if (Visited.find(&MINext) == Visited.end()) {
|
|
|
|
processBaseWithConstOffset(BaseNext, MAddrNext);
|
|
|
|
Visited[&MINext] = MAddrNext;
|
|
|
|
} else
|
|
|
|
MAddrNext = Visited[&MINext];
|
|
|
|
|
|
|
|
if (MAddrNext.Base.LoReg != MAddr.Base.LoReg ||
|
|
|
|
MAddrNext.Base.HiReg != MAddr.Base.HiReg ||
|
|
|
|
MAddrNext.Base.LoSubReg != MAddr.Base.LoSubReg ||
|
|
|
|
MAddrNext.Base.HiSubReg != MAddr.Base.HiSubReg)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
InstsWCommonBase.push_back(std::make_pair(&MINext, MAddrNext.Offset));
|
|
|
|
|
|
|
|
int64_t Dist = MAddr.Offset - MAddrNext.Offset;
|
|
|
|
TargetLoweringBase::AddrMode AM;
|
|
|
|
AM.HasBaseReg = true;
|
|
|
|
AM.BaseOffs = Dist;
|
|
|
|
if (TLI->isLegalGlobalAddressingMode(AM) &&
|
2018-12-15 09:32:58 +08:00
|
|
|
(uint32_t)std::abs(Dist) > MaxDist) {
|
|
|
|
MaxDist = std::abs(Dist);
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
|
|
|
|
AnchorAddr = MAddrNext;
|
|
|
|
AnchorInst = &MINext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AnchorInst) {
|
|
|
|
LLVM_DEBUG(dbgs() << " Anchor-Inst(with max-distance from Offset): ";
|
|
|
|
AnchorInst->dump());
|
|
|
|
LLVM_DEBUG(dbgs() << " Anchor-Offset from BASE: "
|
|
|
|
<< AnchorAddr.Offset << "\n\n");
|
|
|
|
|
|
|
|
// Instead of moving up, just re-compute anchor-instruction's base address.
|
|
|
|
unsigned Base = computeBase(MI, AnchorAddr);
|
|
|
|
|
|
|
|
updateBaseAndOffset(MI, Base, MAddr.Offset - AnchorAddr.Offset);
|
|
|
|
LLVM_DEBUG(dbgs() << " After promotion: "; MI.dump(););
|
|
|
|
|
|
|
|
for (auto P : InstsWCommonBase) {
|
|
|
|
TargetLoweringBase::AddrMode AM;
|
|
|
|
AM.HasBaseReg = true;
|
|
|
|
AM.BaseOffs = P.second - AnchorAddr.Offset;
|
|
|
|
|
|
|
|
if (TLI->isLegalGlobalAddressingMode(AM)) {
|
|
|
|
LLVM_DEBUG(dbgs() << " Promote Offset(" << P.second;
|
|
|
|
dbgs() << ")"; P.first->dump());
|
|
|
|
updateBaseAndOffset(*P.first, Base, P.second - AnchorAddr.Offset);
|
|
|
|
LLVM_DEBUG(dbgs() << " After promotion: "; P.first->dump());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AnchorList.insert(AnchorInst);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
void SILoadStoreOptimizer::addInstToMergeableList(const CombineInfo &CI,
|
|
|
|
std::list<std::list<CombineInfo> > &MergeableInsts) const {
|
|
|
|
for (std::list<CombineInfo> &AddrList : MergeableInsts) {
|
|
|
|
if (AddrList.front().hasSameBaseAddress(*CI.I) &&
|
|
|
|
AddrList.front().InstClass == CI.InstClass) {
|
|
|
|
AddrList.emplace_back(CI);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-10-11 06:01:59 +08:00
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
// Base address not found, so add a new list.
|
|
|
|
MergeableInsts.emplace_back(1, CI);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SILoadStoreOptimizer::collectMergeableInsts(MachineBasicBlock &MBB,
|
|
|
|
std::list<std::list<CombineInfo> > &MergeableInsts) const {
|
|
|
|
bool Modified = false;
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
// Contain the list
|
|
|
|
MemInfoMap Visited;
|
|
|
|
// Contains the list of instructions for which constant offsets are being
|
|
|
|
// promoted to the IMM.
|
|
|
|
SmallPtrSet<MachineInstr *, 4> AnchorList;
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
// Sort potential mergeable instructions into lists. One list per base address.
|
|
|
|
for (MachineInstr &MI : MBB.instrs()) {
|
|
|
|
// We run this before checking if an address is mergeable, because it can produce
|
|
|
|
// better code even if the instructions aren't mergeable.
|
[AMDGPU] Promote constant offset to the immediate by finding a new base with 13bit constant offset from the nearby instructions.
Summary: Promote constant offset to immediate by recomputing the relative 13bit offset from nearby instructions.
E.g.
s_movk_i32 s0, 0x1800
v_add_co_u32_e32 v0, vcc, s0, v2
v_addc_co_u32_e32 v1, vcc, 0, v6, vcc
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[0:1], off
=>
s_movk_i32 s0, 0x1000
v_add_co_u32_e32 v5, vcc, s0, v2
v_addc_co_u32_e32 v6, vcc, 0, v6, vcc
global_load_dwordx2 v[5:6], v[5:6], off
global_load_dwordx2 v[0:1], v[5:6], off offset:2048
Author: FarhanaAleen
Reviewed By: arsenm, rampitec
Subscribers: llvm-commits, AMDGPU
Differential Revision: https://reviews.llvm.org/D55539
llvm-svn: 349196
2018-12-15 05:13:14 +08:00
|
|
|
if (promoteConstantOffsetToImm(MI, Visited, AnchorList))
|
|
|
|
Modified = true;
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
const InstClassEnum InstClass = getInstClass(MI.getOpcode(), *TII);
|
|
|
|
if (InstClass == UNKNOWN)
|
|
|
|
continue;
|
|
|
|
|
2014-10-11 06:01:59 +08:00
|
|
|
// Don't combine if volatile.
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
if (MI.hasOrderedMemoryRef())
|
2014-10-11 06:01:59 +08:00
|
|
|
continue;
|
|
|
|
|
2017-04-14 01:53:07 +08:00
|
|
|
CombineInfo CI;
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
CI.setMI(MI, *TII, *STM);
|
|
|
|
|
|
|
|
if (!CI.hasMergeableAddress(*MRI))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
addInstToMergeableList(CI, MergeableInsts);
|
|
|
|
}
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan through looking for adjacent LDS operations with constant offsets from
|
|
|
|
// the same base register. We rely on the scheduler to do the hard work of
|
|
|
|
// clustering nearby loads, and assume these are all adjacent.
|
|
|
|
bool SILoadStoreOptimizer::optimizeBlock(
|
|
|
|
std::list<std::list<CombineInfo> > &MergeableInsts) {
|
|
|
|
bool Modified = false;
|
|
|
|
|
|
|
|
for (std::list<CombineInfo> &MergeList : MergeableInsts) {
|
|
|
|
if (MergeList.size() < 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool OptimizeListAgain = false;
|
|
|
|
if (!optimizeInstsWithSameBaseAddr(MergeList, OptimizeListAgain)) {
|
|
|
|
// We weren't able to make any changes, so clear the list so we don't
|
|
|
|
// process the same instructions the next time we try to optimize this
|
|
|
|
// block.
|
|
|
|
MergeList.clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We made changes, but also determined that there were no more optimization
|
|
|
|
// opportunities, so we don't need to reprocess the list
|
|
|
|
if (!OptimizeListAgain)
|
|
|
|
MergeList.clear();
|
|
|
|
|
|
|
|
OptimizeAgain |= OptimizeListAgain;
|
|
|
|
Modified = true;
|
|
|
|
}
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SILoadStoreOptimizer::removeCombinedInst(std::list<CombineInfo> &MergeList,
|
|
|
|
const MachineInstr &MI) {
|
|
|
|
|
|
|
|
for (auto CI = MergeList.begin(), E = MergeList.end(); CI != E; ++CI) {
|
|
|
|
if (&*CI->I == &MI) {
|
|
|
|
MergeList.erase(CI);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SILoadStoreOptimizer::optimizeInstsWithSameBaseAddr(
|
|
|
|
std::list<CombineInfo> &MergeList,
|
|
|
|
bool &OptimizeListAgain) {
|
|
|
|
bool Modified = false;
|
|
|
|
for (auto I = MergeList.begin(); I != MergeList.end(); ++I) {
|
|
|
|
CombineInfo &CI = *I;
|
2017-11-29 08:55:57 +08:00
|
|
|
|
2018-12-13 00:15:21 +08:00
|
|
|
switch (CI.InstClass) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case DS_READ:
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
if (findMatchingInst(CI)) {
|
2014-10-11 06:01:59 +08:00
|
|
|
Modified = true;
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
removeCombinedInst(MergeList, *CI.Paired);
|
|
|
|
MachineBasicBlock::iterator NewMI = mergeRead2Pair(CI);
|
|
|
|
CI.setMI(NewMI, *TII, *STM);
|
2014-10-11 06:01:59 +08:00
|
|
|
}
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
break;
|
2018-12-13 00:15:21 +08:00
|
|
|
case DS_WRITE:
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
if (findMatchingInst(CI)) {
|
2014-10-11 06:01:59 +08:00
|
|
|
Modified = true;
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
removeCombinedInst(MergeList, *CI.Paired);
|
|
|
|
MachineBasicBlock::iterator NewMI = mergeWrite2Pair(CI);
|
|
|
|
CI.setMI(NewMI, *TII, *STM);
|
2014-10-11 06:01:59 +08:00
|
|
|
}
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
break;
|
2018-12-13 00:15:21 +08:00
|
|
|
case S_BUFFER_LOAD_IMM:
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
if (findMatchingInst(CI)) {
|
|
|
|
Modified = true;
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
removeCombinedInst(MergeList, *CI.Paired);
|
|
|
|
MachineBasicBlock::iterator NewMI = mergeSBufferLoadImmPair(CI);
|
|
|
|
CI.setMI(NewMI, *TII, *STM);
|
|
|
|
OptimizeListAgain |= (CI.Width0 + CI.Width1) < 16;
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
}
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
break;
|
2018-12-13 00:15:21 +08:00
|
|
|
case BUFFER_LOAD_OFFEN:
|
|
|
|
case BUFFER_LOAD_OFFSET:
|
|
|
|
case BUFFER_LOAD_OFFEN_exact:
|
|
|
|
case BUFFER_LOAD_OFFSET_exact:
|
2017-11-09 09:52:30 +08:00
|
|
|
if (findMatchingInst(CI)) {
|
|
|
|
Modified = true;
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
removeCombinedInst(MergeList, *CI.Paired);
|
|
|
|
MachineBasicBlock::iterator NewMI = mergeBufferLoadPair(CI);
|
|
|
|
CI.setMI(NewMI, *TII, *STM);
|
|
|
|
OptimizeListAgain |= (CI.Width0 + CI.Width1) < 4;
|
2017-11-09 09:52:30 +08:00
|
|
|
}
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
break;
|
2018-12-13 00:15:21 +08:00
|
|
|
case BUFFER_STORE_OFFEN:
|
|
|
|
case BUFFER_STORE_OFFSET:
|
|
|
|
case BUFFER_STORE_OFFEN_exact:
|
|
|
|
case BUFFER_STORE_OFFSET_exact:
|
2017-11-09 09:52:55 +08:00
|
|
|
if (findMatchingInst(CI)) {
|
|
|
|
Modified = true;
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
removeCombinedInst(MergeList, *CI.Paired);
|
|
|
|
MachineBasicBlock::iterator NewMI = mergeBufferStorePair(CI);
|
|
|
|
CI.setMI(NewMI, *TII, *STM);
|
|
|
|
OptimizeListAgain |= (CI.Width0 + CI.Width1) < 4;
|
2017-11-09 09:52:55 +08:00
|
|
|
}
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
break;
|
2017-11-09 09:52:55 +08:00
|
|
|
}
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
// Clear the InstsToMove after we have finished searching so we don't have
|
|
|
|
// stale values left over if we search for this CI again in another pass
|
|
|
|
// over the block.
|
|
|
|
CI.InstsToMove.clear();
|
2014-10-11 06:01:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SILoadStoreOptimizer::runOnMachineFunction(MachineFunction &MF) {
|
2017-12-16 06:22:58 +08:00
|
|
|
if (skipFunction(MF.getFunction()))
|
2016-04-26 06:23:44 +08:00
|
|
|
return false;
|
|
|
|
|
2018-07-12 04:59:01 +08:00
|
|
|
STM = &MF.getSubtarget<GCNSubtarget>();
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
if (!STM->loadStoreOptEnabled())
|
2016-06-28 04:32:13 +08:00
|
|
|
return false;
|
|
|
|
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
TII = STM->getInstrInfo();
|
2016-06-24 14:30:11 +08:00
|
|
|
TRI = &TII->getRegisterInfo();
|
|
|
|
|
2014-10-11 06:01:59 +08:00
|
|
|
MRI = &MF.getRegInfo();
|
2016-08-30 03:15:22 +08:00
|
|
|
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
2014-10-11 06:01:59 +08:00
|
|
|
|
2017-08-31 09:53:09 +08:00
|
|
|
assert(MRI->isSSA() && "Must be run on SSA");
|
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Running SILoadStoreOptimizer\n");
|
2014-10-11 06:01:59 +08:00
|
|
|
|
|
|
|
bool Modified = false;
|
|
|
|
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
|
2017-11-28 16:42:46 +08:00
|
|
|
for (MachineBasicBlock &MBB : MF) {
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
std::list<std::list<CombineInfo> > MergeableInsts;
|
|
|
|
// First pass: Collect list of all instructions we know how to merge.
|
|
|
|
Modified |= collectMergeableInsts(MBB, MergeableInsts);
|
2018-12-13 00:15:21 +08:00
|
|
|
do {
|
|
|
|
OptimizeAgain = false;
|
AMDGPU/SILoadStoreOptimizer: Optimize scanning for mergeable instructions
Summary:
This adds a pre-pass to this optimization that scans through the basic
block and generates lists of mergeable instructions with one list per unique
address.
In the optimization phase instead of scanning through the basic block for mergeable
instructions, we now iterate over the lists generated by the pre-pass.
The decision to re-optimize a block is now made per list, so if we fail to merge any
instructions with the same address, then we do not attempt to optimize them in
future passes over the block. This will help to reduce the time this pass
spends re-optimizing instructions.
In one pathological test case, this change reduces the time spent in the
SILoadStoreOptimizer from 0.2s to 0.03s.
This restructuring will also make it possible to implement further solutions in
this pass, because we can now add less expensive checks to the pre-pass and
filter instructions out early which will avoid the need to do the expensive
scanning during the optimization pass. For example, checking for adjacent
offsets is an inexpensive test we can move to the pre-pass.
Reviewers: arsenm, pendingchaos, rampitec, nhaehnle, vpykhtin
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65961
llvm-svn: 373630
2019-10-04 01:11:47 +08:00
|
|
|
Modified |= optimizeBlock(MergeableInsts);
|
2018-12-13 00:15:21 +08:00
|
|
|
} while (OptimizeAgain);
|
AMDGPU: Merge S_BUFFER_LOAD_DWORD_IMM into x2, x4
Summary:
Only constant offsets (*_IMM opcodes) are merged.
It reuses code for LDS load/store merging.
It relies on the scheduler to group loads.
The results are mixed, I think they are mostly positive. Most shaders are
affected, so here are total stats only:
SGPRS: 2072198 -> 2151462 (3.83 %)
VGPRS: 1628024 -> 1634612 (0.40 %)
Spilled SGPRs: 7883 -> 8942 (13.43 %)
Spilled VGPRs: 97 -> 101 (4.12 %)
Scratch size: 1488 -> 1492 (0.27 %) dwords per thread
Code Size: 60222620 -> 52940672 (-12.09 %) bytes
Max Waves: 374337 -> 373066 (-0.34 %)
There is 13.4% increase in SGPR spilling, DiRT Showdown spills a few more
VGPRs (now 37), but 12% decrease in code size.
These are the new stats for SGPR spilling. We already spill a lot SGPRs,
so it's uncertain whether more spilling will make any difference since
SGPRs are always spilled to VGPRs:
SGPR SPILLING APPS Shaders SpillSGPR AvgPerSh
alien_isolation 2938 100 0.0
batman_arkham_origins 589 6 0.0
bioshock-infinite 1769 4 0.0
borderlands2 3968 22 0.0
counter_strike_glob.. 1142 60 0.1
deus_ex_mankind_div.. 1410 79 0.1
dirt-showdown 533 4 0.0
dirt_rally 364 1163 3.2
divinity 1052 2 0.0
dota2 1747 7 0.0
f1-2015 776 1515 2.0
grid_autosport 1767 1505 0.9
hitman 1413 273 0.2
left_4_dead_2 1762 4 0.0
life_is_strange 1296 26 0.0
mad_max 358 96 0.3
metro_2033_redux 2670 60 0.0
payday2 1362 22 0.0
portal 474 3 0.0
saints_row_iv 1704 8 0.0
serious_sam_3_bfe 392 1348 3.4
shadow_of_mordor 1418 12 0.0
shadow_warrior 3956 239 0.1
talos_principle 324 1735 5.4
thea 172 17 0.1
tomb_raider 1449 215 0.1
total_war_warhammer 242 56 0.2
ue4_effects_cave 295 55 0.2
ue4_elemental 572 12 0.0
unigine_tropics 210 56 0.3
unigine_valley 278 152 0.5
victor_vran 1262 84 0.1
yofrankie 82 2 0.0
Reviewers: arsenm, nhaehnle
Subscribers: kzhuravl, wdng, yaxunl, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D38949
llvm-svn: 317751
2017-11-09 09:52:23 +08:00
|
|
|
}
|
|
|
|
|
2014-10-11 06:01:59 +08:00
|
|
|
return Modified;
|
|
|
|
}
|