summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/GlobalISel/Localizer.cpp
diff options
context:
space:
mode:
authorAmara Emerson <aemerson@apple.com>2019-06-21 00:36:19 +0000
committerAmara Emerson <aemerson@apple.com>2019-06-21 00:36:19 +0000
commitbc0d08e0eec68c6065a5836ae7bdbd2e60495e2b (patch)
tree4806d1f84b03e2eedc882e8a75de642fed42b7ab /llvm/lib/CodeGen/GlobalISel/Localizer.cpp
parentf923d9b53f2264044bc12369beaf3102d6537bd8 (diff)
downloadbcm5719-llvm-bc0d08e0eec68c6065a5836ae7bdbd2e60495e2b.tar.gz
bcm5719-llvm-bc0d08e0eec68c6065a5836ae7bdbd2e60495e2b.zip
[GlobalISel][Localizer] Allow localization of G_INTTOPTR and chains of instructions.
G_INTTOPTR can prevent the localizer from moving G_CONSTANTs, but since it's essentially a side effect free cast instruction we can remat both instructions. This patch changes the localizer to enable localization of the chains by iterating over the entry block instructions in reverse order. That way, uses will localized first, and then the defs are free to be localized as well. This also changes the previous SmallPtrSet of localized instructions to use a SetVector instead. We're dealing with pointers and need deterministic iteration order. Overall, this change improves ARM64 -O0 CTMark code size by around 0.7% geomean. Differential Revision: https://reviews.llvm.org/D63630 llvm-svn: 364001
Diffstat (limited to 'llvm/lib/CodeGen/GlobalISel/Localizer.cpp')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/Localizer.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/Localizer.cpp b/llvm/lib/CodeGen/GlobalISel/Localizer.cpp
index 808f611159a..3592409710a 100644
--- a/llvm/lib/CodeGen/GlobalISel/Localizer.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Localizer.cpp
@@ -12,7 +12,6 @@
#include "llvm/CodeGen/GlobalISel/Localizer.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Support/Debug.h"
@@ -76,6 +75,7 @@ bool Localizer::shouldLocalize(const MachineInstr &MI) {
case TargetOpcode::G_CONSTANT:
case TargetOpcode::G_FCONSTANT:
case TargetOpcode::G_FRAME_INDEX:
+ case TargetOpcode::G_INTTOPTR:
return true;
case TargetOpcode::G_GLOBAL_VALUE: {
unsigned RematCost = TTI->getGISelRematGlobalCost();
@@ -104,8 +104,8 @@ bool Localizer::isLocalUse(MachineOperand &MOUse, const MachineInstr &Def,
return InsertMBB == Def.getParent();
}
-bool Localizer::localizeInterBlock(
- MachineFunction &MF, SmallPtrSetImpl<MachineInstr *> &LocalizedInstrs) {
+bool Localizer::localizeInterBlock(MachineFunction &MF,
+ LocalizedSetVecT &LocalizedInstrs) {
bool Changed = false;
DenseMap<std::pair<MachineBasicBlock *, unsigned>, unsigned> MBBWithLocalDef;
@@ -114,7 +114,8 @@ bool Localizer::localizeInterBlock(
// we only localize instructions in the entry block here. This might change if
// we start doing CSE across blocks.
auto &MBB = MF.front();
- for (MachineInstr &MI : MBB) {
+ for (auto RI = MBB.rbegin(), RE = MBB.rend(); RI != RE; ++RI) {
+ MachineInstr &MI = *RI;
if (!shouldLocalize(MI))
continue;
LLVM_DEBUG(dbgs() << "Should localize: " << MI);
@@ -166,8 +167,7 @@ bool Localizer::localizeInterBlock(
return Changed;
}
-bool Localizer::localizeIntraBlock(
- SmallPtrSetImpl<MachineInstr *> &LocalizedInstrs) {
+bool Localizer::localizeIntraBlock(LocalizedSetVecT &LocalizedInstrs) {
bool Changed = false;
// For each already-localized instruction which has multiple users, then we
@@ -179,15 +179,16 @@ bool Localizer::localizeIntraBlock(
for (MachineInstr *MI : LocalizedInstrs) {
unsigned Reg = MI->getOperand(0).getReg();
MachineBasicBlock &MBB = *MI->getParent();
- // If the instruction has a single use, we would have already moved it right
- // before its user in localizeInterBlock().
- if (MRI->hasOneUse(Reg))
- continue;
-
// All of the user MIs of this reg.
SmallPtrSet<MachineInstr *, 32> Users;
- for (MachineInstr &UseMI : MRI->use_nodbg_instructions(Reg))
- Users.insert(&UseMI);
+ for (MachineInstr &UseMI : MRI->use_nodbg_instructions(Reg)) {
+ if (!UseMI.isPHI())
+ Users.insert(&UseMI);
+ }
+ // If all the users were PHIs then they're not going to be in our block,
+ // don't try to move this instruction.
+ if (Users.empty())
+ continue;
MachineBasicBlock::iterator II(MI);
++II;
@@ -216,7 +217,7 @@ bool Localizer::runOnMachineFunction(MachineFunction &MF) {
// Keep track of the instructions we localized. We'll do a second pass of
// intra-block localization to further reduce live ranges.
- SmallPtrSet<MachineInstr *, 32> LocalizedInstrs;
+ LocalizedSetVecT LocalizedInstrs;
bool Changed = localizeInterBlock(MF, LocalizedInstrs);
return Changed |= localizeIntraBlock(LocalizedInstrs);
OpenPOWER on IntegriCloud