2017-07-26 07:51:02 +08:00
|
|
|
//===- AArch64LoadStoreOptimizer.cpp - AArch64 load/store opt. pass -------===//
|
2014-03-29 18:18:08 +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-03-29 18:18:08 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a pass that performs load / store related peephole
|
|
|
|
// optimizations. This pass should be run after register allocation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "AArch64InstrInfo.h"
|
2014-08-05 05:25:23 +08:00
|
|
|
#include "AArch64Subtarget.h"
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "MCTargetDesc/AArch64AddressingModes.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2015-05-22 05:36:46 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2014-07-25 19:42:14 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2017-01-25 08:29:26 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
2017-07-26 07:51:02 +08:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2017-01-25 08:29:26 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2017-01-25 08:29:26 +08:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2019-12-21 21:47:08 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
2017-01-25 08:29:26 +08:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
[AArch64][Fix] LdSt optimization generate premature stack-popping
Summary:
When moving add and sub to memory operand instructions,
aarch64-ldst-opt would prematurally pop the stack pointer,
before memory instructions that do access the stack using
indirect loads.
e.g.
```
int foo(int offset){
int local[4] = {0};
return local[offset];
}
```
would generate:
```
sub sp, sp, #16 ; Push the stack
mov x8, sp ; Save stack in register
stp xzr, xzr, [sp], #16 ; Zero initialize stack, and post-increment, making it invalid
------ If an exception goes here, the stack value might be corrupted
ldr w0, [x8, w0, sxtw #2] ; Access correct position, but it is not guarded by SP
```
Reviewers: fhahn, foad, thegameg, eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, kristof.beyls, hiraditya, danielkiss, llvm-commits, simon_tatham
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75755
2020-03-14 01:32:31 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2017-01-25 08:29:26 +08:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/Pass.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
#include "llvm/Support/DebugCounter.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-01-25 08:29:26 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
#include <functional>
|
2017-01-25 08:29:26 +08:00
|
|
|
#include <iterator>
|
|
|
|
#include <limits>
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
#define DEBUG_TYPE "aarch64-ldst-opt"
|
2014-04-22 10:41:26 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
STATISTIC(NumPairCreated, "Number of load/store pair instructions generated");
|
|
|
|
STATISTIC(NumPostFolded, "Number of post-index updates folded");
|
|
|
|
STATISTIC(NumPreFolded, "Number of pre-index updates folded");
|
|
|
|
STATISTIC(NumUnscaledPairCreated,
|
|
|
|
"Number of load/store from unscaled generated");
|
2015-11-21 05:14:07 +08:00
|
|
|
STATISTIC(NumZeroStoresPromoted, "Number of narrow zero stores promoted");
|
2015-12-23 00:36:16 +08:00
|
|
|
STATISTIC(NumLoadsFromStoresPromoted, "Number of loads from stores promoted");
|
2014-03-29 18:18:08 +08:00
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
DEBUG_COUNTER(RegRenamingCounter, DEBUG_TYPE "-reg-renaming",
|
|
|
|
"Controls which pairs are considered for renaming");
|
|
|
|
|
2016-02-05 05:26:02 +08:00
|
|
|
// The LdStLimit limits how far we search for load/store pairs.
|
|
|
|
static cl::opt<unsigned> LdStLimit("aarch64-load-store-scan-limit",
|
2014-06-04 20:40:35 +08:00
|
|
|
cl::init(20), cl::Hidden);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-02-05 05:26:02 +08:00
|
|
|
// The UpdateLimit limits how far we search for update instructions when we form
|
|
|
|
// pre-/post-index instructions.
|
|
|
|
static cl::opt<unsigned> UpdateLimit("aarch64-update-scan-limit", cl::init(100),
|
|
|
|
cl::Hidden);
|
|
|
|
|
2020-01-28 07:11:45 +08:00
|
|
|
// Enable register renaming to find additional store pairing opportunities.
|
|
|
|
static cl::opt<bool> EnableRenaming("aarch64-load-store-renaming",
|
2020-02-26 19:05:59 +08:00
|
|
|
cl::init(true), cl::Hidden);
|
2020-01-28 07:11:45 +08:00
|
|
|
|
2015-08-05 21:44:51 +08:00
|
|
|
#define AARCH64_LOAD_STORE_OPT_NAME "AArch64 load / store optimization pass"
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
namespace {
|
2015-07-22 01:42:04 +08:00
|
|
|
|
2017-07-26 07:51:02 +08:00
|
|
|
using LdStPairFlags = struct LdStPairFlags {
|
2015-07-22 01:42:04 +08:00
|
|
|
// If a matching instruction is found, MergeForward is set to true if the
|
|
|
|
// merge is to remove the first instruction and replace the second with
|
|
|
|
// a pair-wise insn, and false if the reverse is true.
|
2017-01-25 08:29:26 +08:00
|
|
|
bool MergeForward = false;
|
2015-07-22 01:42:04 +08:00
|
|
|
|
|
|
|
// SExtIdx gives the index of the result of the load pair that must be
|
|
|
|
// extended. The value of SExtIdx assumes that the paired load produces the
|
|
|
|
// value in this order: (I, returned iterator), i.e., -1 means no value has
|
|
|
|
// to be extended, 0 means I, and 1 means the returned iterator.
|
2017-01-25 08:29:26 +08:00
|
|
|
int SExtIdx = -1;
|
2015-07-22 01:42:04 +08:00
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
// If not none, RenameReg can be used to rename the result register of the
|
|
|
|
// first store in a pair. Currently this only works when merging stores
|
|
|
|
// forward.
|
|
|
|
Optional<MCPhysReg> RenameReg = None;
|
|
|
|
|
2017-01-25 08:29:26 +08:00
|
|
|
LdStPairFlags() = default;
|
2015-07-22 01:42:04 +08:00
|
|
|
|
|
|
|
void setMergeForward(bool V = true) { MergeForward = V; }
|
|
|
|
bool getMergeForward() const { return MergeForward; }
|
|
|
|
|
|
|
|
void setSExtIdx(int V) { SExtIdx = V; }
|
|
|
|
int getSExtIdx() const { return SExtIdx; }
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
|
|
|
|
void setRenameReg(MCPhysReg R) { RenameReg = R; }
|
|
|
|
void clearRenameReg() { RenameReg = None; }
|
|
|
|
Optional<MCPhysReg> getRenameReg() const { return RenameReg; }
|
2017-07-26 07:51:02 +08:00
|
|
|
};
|
2015-07-22 01:42:04 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
struct AArch64LoadStoreOpt : public MachineFunctionPass {
|
2014-03-29 18:18:08 +08:00
|
|
|
static char ID;
|
2017-01-25 08:29:26 +08:00
|
|
|
|
2015-11-07 00:27:47 +08:00
|
|
|
AArch64LoadStoreOpt() : MachineFunctionPass(ID) {
|
2015-08-05 21:44:51 +08:00
|
|
|
initializeAArch64LoadStoreOptPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2017-03-17 22:19:55 +08:00
|
|
|
AliasAnalysis *AA;
|
2014-05-24 20:50:23 +08:00
|
|
|
const AArch64InstrInfo *TII;
|
2014-03-29 18:18:08 +08:00
|
|
|
const TargetRegisterInfo *TRI;
|
2015-11-10 19:04:18 +08:00
|
|
|
const AArch64Subtarget *Subtarget;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
// Track which register units have been modified and used.
|
|
|
|
LiveRegUnits ModifiedRegUnits, UsedRegUnits;
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
LiveRegUnits DefinedInBB;
|
2016-02-02 23:02:30 +08:00
|
|
|
|
2017-07-26 07:51:02 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2017-03-17 22:19:55 +08:00
|
|
|
AU.addRequired<AAResultsWrapperPass>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// Scan the instructions looking for a load/store that can be combined
|
|
|
|
// with the current instruction into a load/store pair.
|
|
|
|
// Return the matching instruction if one is found, else MBB->end().
|
|
|
|
MachineBasicBlock::iterator findMatchingInsn(MachineBasicBlock::iterator I,
|
2015-07-22 01:42:04 +08:00
|
|
|
LdStPairFlags &Flags,
|
[AArch64] Handle missing store pair opportunity
Summary:
This change will handle missing store pair opportunity where the first store
instruction stores zero followed by the non-zero store. For example, this change
will convert :
str wzr, [x8]
str w1, [x8, #4]
into:
stp wzr, w1, [x8]
Reviewers: jmolloy, t.p.northover, mcrosier
Subscribers: flyingforyou, aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18570
llvm-svn: 265021
2016-03-31 22:47:24 +08:00
|
|
|
unsigned Limit,
|
|
|
|
bool FindNarrowMerge);
|
2015-12-23 00:36:16 +08:00
|
|
|
|
|
|
|
// Scan the instructions looking for a store that writes to the address from
|
|
|
|
// which the current load instruction reads. Return true if one is found.
|
|
|
|
bool findMatchingStore(MachineBasicBlock::iterator I, unsigned Limit,
|
|
|
|
MachineBasicBlock::iterator &StoreI);
|
|
|
|
|
2016-11-07 23:27:22 +08:00
|
|
|
// Merge the two instructions indicated into a wider narrow store instruction.
|
2016-02-10 03:02:12 +08:00
|
|
|
MachineBasicBlock::iterator
|
2016-11-07 23:27:22 +08:00
|
|
|
mergeNarrowZeroStores(MachineBasicBlock::iterator I,
|
|
|
|
MachineBasicBlock::iterator MergeMI,
|
|
|
|
const LdStPairFlags &Flags);
|
2016-02-10 03:02:12 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// Merge the two instructions indicated into a single pair-wise instruction.
|
|
|
|
MachineBasicBlock::iterator
|
|
|
|
mergePairedInsns(MachineBasicBlock::iterator I,
|
2015-07-22 01:42:04 +08:00
|
|
|
MachineBasicBlock::iterator Paired,
|
2015-07-22 01:47:56 +08:00
|
|
|
const LdStPairFlags &Flags);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-12-23 00:36:16 +08:00
|
|
|
// Promote the load that reads directly from the address stored to.
|
|
|
|
MachineBasicBlock::iterator
|
|
|
|
promoteLoadFromStore(MachineBasicBlock::iterator LoadI,
|
|
|
|
MachineBasicBlock::iterator StoreI);
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// Scan the instruction list to find a base register update that can
|
|
|
|
// be combined with the current instruction (a load or store) using
|
|
|
|
// pre or post indexed addressing with writeback. Scan forwards.
|
|
|
|
MachineBasicBlock::iterator
|
2016-01-19 05:56:40 +08:00
|
|
|
findMatchingUpdateInsnForward(MachineBasicBlock::iterator I,
|
2016-02-05 05:26:02 +08:00
|
|
|
int UnscaledOffset, unsigned Limit);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Scan the instruction list to find a base register update that can
|
|
|
|
// be combined with the current instruction (a load or store) using
|
|
|
|
// pre or post indexed addressing with writeback. Scan backwards.
|
|
|
|
MachineBasicBlock::iterator
|
2016-02-05 05:26:02 +08:00
|
|
|
findMatchingUpdateInsnBackward(MachineBasicBlock::iterator I, unsigned Limit);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-09-26 01:48:17 +08:00
|
|
|
// Find an instruction that updates the base register of the ld/st
|
|
|
|
// instruction.
|
2016-07-09 04:29:42 +08:00
|
|
|
bool isMatchingUpdateInsn(MachineInstr &MemMI, MachineInstr &MI,
|
2015-09-26 01:48:17 +08:00
|
|
|
unsigned BaseReg, int Offset);
|
|
|
|
|
2015-09-23 21:51:44 +08:00
|
|
|
// Merge a pre- or post-index base register update into a ld/st instruction.
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock::iterator
|
2015-09-23 21:51:44 +08:00
|
|
|
mergeUpdateInsn(MachineBasicBlock::iterator I,
|
|
|
|
MachineBasicBlock::iterator Update, bool IsPreIdx);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-11-07 23:27:22 +08:00
|
|
|
// Find and merge zero store instructions.
|
|
|
|
bool tryToMergeZeroStInst(MachineBasicBlock::iterator &MBBI);
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
|
2016-02-10 02:10:20 +08:00
|
|
|
// Find and pair ldr/str instructions.
|
|
|
|
bool tryToPairLdStInst(MachineBasicBlock::iterator &MBBI);
|
|
|
|
|
2015-12-23 00:36:16 +08:00
|
|
|
// Find and promote load instructions which read directly from store.
|
|
|
|
bool tryToPromoteLoadFromStore(MachineBasicBlock::iterator &MBBI);
|
|
|
|
|
2017-11-16 05:06:22 +08:00
|
|
|
// Find and merge a base register updates before or after a ld/st instruction.
|
|
|
|
bool tryToMergeLdStUpdate(MachineBasicBlock::iterator &MBBI);
|
|
|
|
|
2016-11-07 23:27:22 +08:00
|
|
|
bool optimizeBlock(MachineBasicBlock &MBB, bool EnableNarrowZeroStOpt);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-04-29 15:58:25 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &Fn) override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-04-05 01:09:25 +08:00
|
|
|
MachineFunctionProperties getRequiredProperties() const override {
|
|
|
|
return MachineFunctionProperties().set(
|
2016-08-25 09:27:13 +08:00
|
|
|
MachineFunctionProperties::Property::NoVRegs);
|
2016-04-05 01:09:25 +08:00
|
|
|
}
|
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override { return AARCH64_LOAD_STORE_OPT_NAME; }
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
2017-01-25 08:29:26 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
char AArch64LoadStoreOpt::ID = 0;
|
2017-01-25 08:29:26 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-08-05 21:44:51 +08:00
|
|
|
INITIALIZE_PASS(AArch64LoadStoreOpt, "aarch64-ldst-opt",
|
|
|
|
AARCH64_LOAD_STORE_OPT_NAME, false, false)
|
|
|
|
|
2015-11-21 05:14:07 +08:00
|
|
|
static bool isNarrowStore(unsigned Opc) {
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case AArch64::STRBBui:
|
|
|
|
case AArch64::STURBBi:
|
|
|
|
case AArch64::STRHHui:
|
|
|
|
case AArch64::STURHHi:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-21 01:36:27 +08:00
|
|
|
// These instruction set memory tag and either keep memory contents unchanged or
|
|
|
|
// set it to zero, ignoring the address part of the source register.
|
|
|
|
static bool isTagStore(const MachineInstr &MI) {
|
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case AArch64::STGOffset:
|
|
|
|
case AArch64::STZGOffset:
|
|
|
|
case AArch64::ST2GOffset:
|
|
|
|
case AArch64::STZ2GOffset:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-07 06:42:10 +08:00
|
|
|
static unsigned getMatchingNonSExtOpcode(unsigned Opc,
|
|
|
|
bool *IsValidLdStrOpc = nullptr) {
|
|
|
|
if (IsValidLdStrOpc)
|
|
|
|
*IsValidLdStrOpc = true;
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
if (IsValidLdStrOpc)
|
|
|
|
*IsValidLdStrOpc = false;
|
2017-01-25 08:29:26 +08:00
|
|
|
return std::numeric_limits<unsigned>::max();
|
2015-03-07 06:42:10 +08:00
|
|
|
case AArch64::STRDui:
|
|
|
|
case AArch64::STURDi:
|
|
|
|
case AArch64::STRQui:
|
|
|
|
case AArch64::STURQi:
|
2015-11-21 05:14:07 +08:00
|
|
|
case AArch64::STRBBui:
|
|
|
|
case AArch64::STURBBi:
|
|
|
|
case AArch64::STRHHui:
|
|
|
|
case AArch64::STURHHi:
|
2015-03-07 06:42:10 +08:00
|
|
|
case AArch64::STRWui:
|
|
|
|
case AArch64::STURWi:
|
|
|
|
case AArch64::STRXui:
|
|
|
|
case AArch64::STURXi:
|
|
|
|
case AArch64::LDRDui:
|
|
|
|
case AArch64::LDURDi:
|
|
|
|
case AArch64::LDRQui:
|
|
|
|
case AArch64::LDURQi:
|
|
|
|
case AArch64::LDRWui:
|
|
|
|
case AArch64::LDURWi:
|
|
|
|
case AArch64::LDRXui:
|
|
|
|
case AArch64::LDURXi:
|
|
|
|
case AArch64::STRSui:
|
|
|
|
case AArch64::STURSi:
|
|
|
|
case AArch64::LDRSui:
|
|
|
|
case AArch64::LDURSi:
|
|
|
|
return Opc;
|
|
|
|
case AArch64::LDRSWui:
|
|
|
|
return AArch64::LDRWui;
|
|
|
|
case AArch64::LDURSWi:
|
|
|
|
return AArch64::LDURWi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-06 04:02:03 +08:00
|
|
|
static unsigned getMatchingWideOpcode(unsigned Opc) {
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Opcode has no wide equivalent!");
|
|
|
|
case AArch64::STRBBui:
|
|
|
|
return AArch64::STRHHui;
|
|
|
|
case AArch64::STRHHui:
|
|
|
|
return AArch64::STRWui;
|
|
|
|
case AArch64::STURBBi:
|
|
|
|
return AArch64::STURHHi;
|
|
|
|
case AArch64::STURHHi:
|
|
|
|
return AArch64::STURWi;
|
[AArch64] Merge two adjacent str WZR into str XZR
Summary:
This change merges adjacent 32 bit zero stores into a 64 bit zero store.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
becomes
str xzr, [x0]
Therefore, four adjacent 32 bit zero stores will be a single stp.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
str wzr, [x0, #8]
str wzr, [x0, #12]
becomes
stp xzr, xzr, [x0]
Reviewers: mcrosier, jmolloy, gberry, t.p.northover
Subscribers: aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D16933
llvm-svn: 260682
2016-02-12 23:25:39 +08:00
|
|
|
case AArch64::STURWi:
|
|
|
|
return AArch64::STURXi;
|
|
|
|
case AArch64::STRWui:
|
|
|
|
return AArch64::STRXui;
|
2016-02-06 04:02:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
static unsigned getMatchingPairOpcode(unsigned Opc) {
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Opcode has no pairwise equivalent!");
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::STRSui:
|
|
|
|
case AArch64::STURSi:
|
|
|
|
return AArch64::STPSi;
|
|
|
|
case AArch64::STRDui:
|
|
|
|
case AArch64::STURDi:
|
|
|
|
return AArch64::STPDi;
|
|
|
|
case AArch64::STRQui:
|
|
|
|
case AArch64::STURQi:
|
|
|
|
return AArch64::STPQi;
|
|
|
|
case AArch64::STRWui:
|
|
|
|
case AArch64::STURWi:
|
|
|
|
return AArch64::STPWi;
|
|
|
|
case AArch64::STRXui:
|
|
|
|
case AArch64::STURXi:
|
|
|
|
return AArch64::STPXi;
|
|
|
|
case AArch64::LDRSui:
|
|
|
|
case AArch64::LDURSi:
|
|
|
|
return AArch64::LDPSi;
|
|
|
|
case AArch64::LDRDui:
|
|
|
|
case AArch64::LDURDi:
|
|
|
|
return AArch64::LDPDi;
|
|
|
|
case AArch64::LDRQui:
|
|
|
|
case AArch64::LDURQi:
|
|
|
|
return AArch64::LDPQi;
|
|
|
|
case AArch64::LDRWui:
|
|
|
|
case AArch64::LDURWi:
|
|
|
|
return AArch64::LDPWi;
|
|
|
|
case AArch64::LDRXui:
|
|
|
|
case AArch64::LDURXi:
|
|
|
|
return AArch64::LDPXi;
|
2015-01-24 09:25:54 +08:00
|
|
|
case AArch64::LDRSWui:
|
|
|
|
case AArch64::LDURSWi:
|
|
|
|
return AArch64::LDPSWi;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
static unsigned isMatchingStore(MachineInstr &LoadInst,
|
|
|
|
MachineInstr &StoreInst) {
|
|
|
|
unsigned LdOpc = LoadInst.getOpcode();
|
|
|
|
unsigned StOpc = StoreInst.getOpcode();
|
2015-12-23 00:36:16 +08:00
|
|
|
switch (LdOpc) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported load instruction!");
|
|
|
|
case AArch64::LDRBBui:
|
|
|
|
return StOpc == AArch64::STRBBui || StOpc == AArch64::STRHHui ||
|
|
|
|
StOpc == AArch64::STRWui || StOpc == AArch64::STRXui;
|
|
|
|
case AArch64::LDURBBi:
|
|
|
|
return StOpc == AArch64::STURBBi || StOpc == AArch64::STURHHi ||
|
|
|
|
StOpc == AArch64::STURWi || StOpc == AArch64::STURXi;
|
|
|
|
case AArch64::LDRHHui:
|
|
|
|
return StOpc == AArch64::STRHHui || StOpc == AArch64::STRWui ||
|
|
|
|
StOpc == AArch64::STRXui;
|
|
|
|
case AArch64::LDURHHi:
|
|
|
|
return StOpc == AArch64::STURHHi || StOpc == AArch64::STURWi ||
|
|
|
|
StOpc == AArch64::STURXi;
|
|
|
|
case AArch64::LDRWui:
|
|
|
|
return StOpc == AArch64::STRWui || StOpc == AArch64::STRXui;
|
|
|
|
case AArch64::LDURWi:
|
|
|
|
return StOpc == AArch64::STURWi || StOpc == AArch64::STURXi;
|
|
|
|
case AArch64::LDRXui:
|
|
|
|
return StOpc == AArch64::STRXui;
|
|
|
|
case AArch64::LDURXi:
|
|
|
|
return StOpc == AArch64::STURXi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
static unsigned getPreIndexedOpcode(unsigned Opc) {
|
2017-08-05 00:44:06 +08:00
|
|
|
// FIXME: We don't currently support creating pre-indexed loads/stores when
|
|
|
|
// the load or store is the unscaled version. If we decide to perform such an
|
|
|
|
// optimization in the future the cases for the unscaled loads/stores will
|
|
|
|
// need to be added here.
|
2014-03-29 18:18:08 +08:00
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Opcode has no pre-indexed equivalent!");
|
2014-06-04 20:40:35 +08:00
|
|
|
case AArch64::STRSui:
|
|
|
|
return AArch64::STRSpre;
|
|
|
|
case AArch64::STRDui:
|
|
|
|
return AArch64::STRDpre;
|
|
|
|
case AArch64::STRQui:
|
|
|
|
return AArch64::STRQpre;
|
2015-09-30 02:26:15 +08:00
|
|
|
case AArch64::STRBBui:
|
|
|
|
return AArch64::STRBBpre;
|
|
|
|
case AArch64::STRHHui:
|
|
|
|
return AArch64::STRHHpre;
|
2014-06-04 20:40:35 +08:00
|
|
|
case AArch64::STRWui:
|
|
|
|
return AArch64::STRWpre;
|
|
|
|
case AArch64::STRXui:
|
|
|
|
return AArch64::STRXpre;
|
|
|
|
case AArch64::LDRSui:
|
|
|
|
return AArch64::LDRSpre;
|
|
|
|
case AArch64::LDRDui:
|
|
|
|
return AArch64::LDRDpre;
|
|
|
|
case AArch64::LDRQui:
|
|
|
|
return AArch64::LDRQpre;
|
2015-09-30 02:26:15 +08:00
|
|
|
case AArch64::LDRBBui:
|
|
|
|
return AArch64::LDRBBpre;
|
|
|
|
case AArch64::LDRHHui:
|
|
|
|
return AArch64::LDRHHpre;
|
2014-06-04 20:40:35 +08:00
|
|
|
case AArch64::LDRWui:
|
|
|
|
return AArch64::LDRWpre;
|
|
|
|
case AArch64::LDRXui:
|
|
|
|
return AArch64::LDRXpre;
|
2015-01-24 09:25:54 +08:00
|
|
|
case AArch64::LDRSWui:
|
|
|
|
return AArch64::LDRSWpre;
|
2015-09-26 01:48:17 +08:00
|
|
|
case AArch64::LDPSi:
|
|
|
|
return AArch64::LDPSpre;
|
2015-09-30 04:39:55 +08:00
|
|
|
case AArch64::LDPSWi:
|
|
|
|
return AArch64::LDPSWpre;
|
2015-09-26 01:48:17 +08:00
|
|
|
case AArch64::LDPDi:
|
|
|
|
return AArch64::LDPDpre;
|
|
|
|
case AArch64::LDPQi:
|
|
|
|
return AArch64::LDPQpre;
|
|
|
|
case AArch64::LDPWi:
|
|
|
|
return AArch64::LDPWpre;
|
|
|
|
case AArch64::LDPXi:
|
|
|
|
return AArch64::LDPXpre;
|
|
|
|
case AArch64::STPSi:
|
|
|
|
return AArch64::STPSpre;
|
|
|
|
case AArch64::STPDi:
|
|
|
|
return AArch64::STPDpre;
|
|
|
|
case AArch64::STPQi:
|
|
|
|
return AArch64::STPQpre;
|
|
|
|
case AArch64::STPWi:
|
|
|
|
return AArch64::STPWpre;
|
|
|
|
case AArch64::STPXi:
|
|
|
|
return AArch64::STPXpre;
|
2019-09-21 01:36:27 +08:00
|
|
|
case AArch64::STGOffset:
|
|
|
|
return AArch64::STGPreIndex;
|
|
|
|
case AArch64::STZGOffset:
|
|
|
|
return AArch64::STZGPreIndex;
|
|
|
|
case AArch64::ST2GOffset:
|
|
|
|
return AArch64::ST2GPreIndex;
|
|
|
|
case AArch64::STZ2GOffset:
|
|
|
|
return AArch64::STZ2GPreIndex;
|
|
|
|
case AArch64::STGPi:
|
|
|
|
return AArch64::STGPpre;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getPostIndexedOpcode(unsigned Opc) {
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Opcode has no post-indexed wise equivalent!");
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::STRSui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::STURSi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::STRSpost;
|
|
|
|
case AArch64::STRDui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::STURDi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::STRDpost;
|
|
|
|
case AArch64::STRQui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::STURQi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::STRQpost;
|
2015-09-30 02:26:15 +08:00
|
|
|
case AArch64::STRBBui:
|
|
|
|
return AArch64::STRBBpost;
|
|
|
|
case AArch64::STRHHui:
|
|
|
|
return AArch64::STRHHpost;
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::STRWui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::STURWi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::STRWpost;
|
|
|
|
case AArch64::STRXui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::STURXi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::STRXpost;
|
|
|
|
case AArch64::LDRSui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::LDURSi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::LDRSpost;
|
|
|
|
case AArch64::LDRDui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::LDURDi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::LDRDpost;
|
|
|
|
case AArch64::LDRQui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::LDURQi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::LDRQpost;
|
2015-09-30 02:26:15 +08:00
|
|
|
case AArch64::LDRBBui:
|
|
|
|
return AArch64::LDRBBpost;
|
|
|
|
case AArch64::LDRHHui:
|
|
|
|
return AArch64::LDRHHpost;
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::LDRWui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::LDURWi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::LDRWpost;
|
|
|
|
case AArch64::LDRXui:
|
2017-08-05 00:44:06 +08:00
|
|
|
case AArch64::LDURXi:
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64::LDRXpost;
|
2015-01-24 09:25:54 +08:00
|
|
|
case AArch64::LDRSWui:
|
|
|
|
return AArch64::LDRSWpost;
|
2015-09-26 01:48:17 +08:00
|
|
|
case AArch64::LDPSi:
|
|
|
|
return AArch64::LDPSpost;
|
2015-09-30 04:39:55 +08:00
|
|
|
case AArch64::LDPSWi:
|
|
|
|
return AArch64::LDPSWpost;
|
2015-09-26 01:48:17 +08:00
|
|
|
case AArch64::LDPDi:
|
|
|
|
return AArch64::LDPDpost;
|
|
|
|
case AArch64::LDPQi:
|
|
|
|
return AArch64::LDPQpost;
|
|
|
|
case AArch64::LDPWi:
|
|
|
|
return AArch64::LDPWpost;
|
|
|
|
case AArch64::LDPXi:
|
|
|
|
return AArch64::LDPXpost;
|
|
|
|
case AArch64::STPSi:
|
|
|
|
return AArch64::STPSpost;
|
|
|
|
case AArch64::STPDi:
|
|
|
|
return AArch64::STPDpost;
|
|
|
|
case AArch64::STPQi:
|
|
|
|
return AArch64::STPQpost;
|
|
|
|
case AArch64::STPWi:
|
|
|
|
return AArch64::STPWpost;
|
|
|
|
case AArch64::STPXi:
|
|
|
|
return AArch64::STPXpost;
|
2019-09-21 01:36:27 +08:00
|
|
|
case AArch64::STGOffset:
|
|
|
|
return AArch64::STGPostIndex;
|
|
|
|
case AArch64::STZGOffset:
|
|
|
|
return AArch64::STZGPostIndex;
|
|
|
|
case AArch64::ST2GOffset:
|
|
|
|
return AArch64::ST2GPostIndex;
|
|
|
|
case AArch64::STZ2GOffset:
|
|
|
|
return AArch64::STZ2GPostIndex;
|
|
|
|
case AArch64::STGPi:
|
|
|
|
return AArch64::STGPpost;
|
2015-09-26 01:48:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
static bool isPairedLdSt(const MachineInstr &MI) {
|
|
|
|
switch (MI.getOpcode()) {
|
2015-09-26 01:48:17 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case AArch64::LDPSi:
|
2015-09-30 04:39:55 +08:00
|
|
|
case AArch64::LDPSWi:
|
2015-09-26 01:48:17 +08:00
|
|
|
case AArch64::LDPDi:
|
|
|
|
case AArch64::LDPQi:
|
|
|
|
case AArch64::LDPWi:
|
|
|
|
case AArch64::LDPXi:
|
|
|
|
case AArch64::STPSi:
|
|
|
|
case AArch64::STPDi:
|
|
|
|
case AArch64::STPQi:
|
|
|
|
case AArch64::STPWi:
|
|
|
|
case AArch64::STPXi:
|
2019-09-21 01:36:27 +08:00
|
|
|
case AArch64::STGPi:
|
2015-09-26 01:48:17 +08:00
|
|
|
return true;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-21 01:36:27 +08:00
|
|
|
// Returns the scale and offset range of pre/post indexed variants of MI.
|
|
|
|
static void getPrePostIndexedMemOpInfo(const MachineInstr &MI, int &Scale,
|
|
|
|
int &MinOffset, int &MaxOffset) {
|
|
|
|
bool IsPaired = isPairedLdSt(MI);
|
|
|
|
bool IsTagStore = isTagStore(MI);
|
|
|
|
// ST*G and all paired ldst have the same scale in pre/post-indexed variants
|
|
|
|
// as in the "unsigned offset" variant.
|
|
|
|
// All other pre/post indexed ldst instructions are unscaled.
|
2019-12-11 18:29:23 +08:00
|
|
|
Scale = (IsTagStore || IsPaired) ? AArch64InstrInfo::getMemScale(MI) : 1;
|
2019-09-21 01:36:27 +08:00
|
|
|
|
|
|
|
if (IsPaired) {
|
|
|
|
MinOffset = -64;
|
|
|
|
MaxOffset = 63;
|
|
|
|
} else {
|
|
|
|
MinOffset = -256;
|
|
|
|
MaxOffset = 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
static MachineOperand &getLdStRegOp(MachineInstr &MI,
|
|
|
|
unsigned PairedRegOp = 0) {
|
2015-09-26 01:48:17 +08:00
|
|
|
assert(PairedRegOp < 2 && "Unexpected register operand idx.");
|
|
|
|
unsigned Idx = isPairedLdSt(MI) ? PairedRegOp : 0;
|
2016-07-09 04:29:42 +08:00
|
|
|
return MI.getOperand(Idx);
|
2015-08-06 23:50:12 +08:00
|
|
|
}
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
static const MachineOperand &getLdStBaseOp(const MachineInstr &MI) {
|
2015-09-26 01:48:17 +08:00
|
|
|
unsigned Idx = isPairedLdSt(MI) ? 2 : 1;
|
2016-07-09 04:29:42 +08:00
|
|
|
return MI.getOperand(Idx);
|
2015-08-06 23:50:12 +08:00
|
|
|
}
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
static const MachineOperand &getLdStOffsetOp(const MachineInstr &MI) {
|
2015-09-26 01:48:17 +08:00
|
|
|
unsigned Idx = isPairedLdSt(MI) ? 3 : 2;
|
2016-07-09 04:29:42 +08:00
|
|
|
return MI.getOperand(Idx);
|
2015-08-06 23:50:12 +08:00
|
|
|
}
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
static bool isLdOffsetInRangeOfSt(MachineInstr &LoadInst,
|
|
|
|
MachineInstr &StoreInst,
|
2016-03-10 01:29:48 +08:00
|
|
|
const AArch64InstrInfo *TII) {
|
2015-12-23 00:36:16 +08:00
|
|
|
assert(isMatchingStore(LoadInst, StoreInst) && "Expect only matched ld/st.");
|
2019-12-11 18:29:23 +08:00
|
|
|
int LoadSize = TII->getMemScale(LoadInst);
|
|
|
|
int StoreSize = TII->getMemScale(StoreInst);
|
2016-07-09 04:29:42 +08:00
|
|
|
int UnscaledStOffset = TII->isUnscaledLdSt(StoreInst)
|
2015-12-23 00:36:16 +08:00
|
|
|
? getLdStOffsetOp(StoreInst).getImm()
|
|
|
|
: getLdStOffsetOp(StoreInst).getImm() * StoreSize;
|
2016-07-09 04:29:42 +08:00
|
|
|
int UnscaledLdOffset = TII->isUnscaledLdSt(LoadInst)
|
2015-12-23 00:36:16 +08:00
|
|
|
? getLdStOffsetOp(LoadInst).getImm()
|
|
|
|
: getLdStOffsetOp(LoadInst).getImm() * LoadSize;
|
|
|
|
return (UnscaledStOffset <= UnscaledLdOffset) &&
|
|
|
|
(UnscaledLdOffset + LoadSize <= (UnscaledStOffset + StoreSize));
|
|
|
|
}
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
static bool isPromotableZeroStoreInst(MachineInstr &MI) {
|
2016-11-07 23:27:22 +08:00
|
|
|
unsigned Opc = MI.getOpcode();
|
|
|
|
return (Opc == AArch64::STRWui || Opc == AArch64::STURWi ||
|
|
|
|
isNarrowStore(Opc)) &&
|
[AArch64] Merge two adjacent str WZR into str XZR
Summary:
This change merges adjacent 32 bit zero stores into a 64 bit zero store.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
becomes
str xzr, [x0]
Therefore, four adjacent 32 bit zero stores will be a single stp.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
str wzr, [x0, #8]
str wzr, [x0, #12]
becomes
stp xzr, xzr, [x0]
Reviewers: mcrosier, jmolloy, gberry, t.p.northover
Subscribers: aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D16933
llvm-svn: 260682
2016-02-12 23:25:39 +08:00
|
|
|
getLdStRegOp(MI).getReg() == AArch64::WZR;
|
|
|
|
}
|
|
|
|
|
2017-11-16 05:06:22 +08:00
|
|
|
static bool isPromotableLoadFromStore(MachineInstr &MI) {
|
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
// Scaled instructions.
|
|
|
|
case AArch64::LDRBBui:
|
|
|
|
case AArch64::LDRHHui:
|
|
|
|
case AArch64::LDRWui:
|
|
|
|
case AArch64::LDRXui:
|
|
|
|
// Unscaled instructions.
|
|
|
|
case AArch64::LDURBBi:
|
|
|
|
case AArch64::LDURHHi:
|
|
|
|
case AArch64::LDURWi:
|
|
|
|
case AArch64::LDURXi:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isMergeableLdStUpdate(MachineInstr &MI) {
|
|
|
|
unsigned Opc = MI.getOpcode();
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
// Scaled instructions.
|
|
|
|
case AArch64::STRSui:
|
|
|
|
case AArch64::STRDui:
|
|
|
|
case AArch64::STRQui:
|
|
|
|
case AArch64::STRXui:
|
|
|
|
case AArch64::STRWui:
|
|
|
|
case AArch64::STRHHui:
|
|
|
|
case AArch64::STRBBui:
|
|
|
|
case AArch64::LDRSui:
|
|
|
|
case AArch64::LDRDui:
|
|
|
|
case AArch64::LDRQui:
|
|
|
|
case AArch64::LDRXui:
|
|
|
|
case AArch64::LDRWui:
|
|
|
|
case AArch64::LDRHHui:
|
|
|
|
case AArch64::LDRBBui:
|
2019-09-21 01:36:27 +08:00
|
|
|
case AArch64::STGOffset:
|
|
|
|
case AArch64::STZGOffset:
|
|
|
|
case AArch64::ST2GOffset:
|
|
|
|
case AArch64::STZ2GOffset:
|
|
|
|
case AArch64::STGPi:
|
2017-11-16 05:06:22 +08:00
|
|
|
// Unscaled instructions.
|
|
|
|
case AArch64::STURSi:
|
|
|
|
case AArch64::STURDi:
|
|
|
|
case AArch64::STURQi:
|
|
|
|
case AArch64::STURWi:
|
|
|
|
case AArch64::STURXi:
|
|
|
|
case AArch64::LDURSi:
|
|
|
|
case AArch64::LDURDi:
|
|
|
|
case AArch64::LDURQi:
|
|
|
|
case AArch64::LDURWi:
|
|
|
|
case AArch64::LDURXi:
|
|
|
|
// Paired instructions.
|
|
|
|
case AArch64::LDPSi:
|
|
|
|
case AArch64::LDPSWi:
|
|
|
|
case AArch64::LDPDi:
|
|
|
|
case AArch64::LDPQi:
|
|
|
|
case AArch64::LDPWi:
|
|
|
|
case AArch64::LDPXi:
|
|
|
|
case AArch64::STPSi:
|
|
|
|
case AArch64::STPDi:
|
|
|
|
case AArch64::STPQi:
|
|
|
|
case AArch64::STPWi:
|
|
|
|
case AArch64::STPXi:
|
|
|
|
// Make sure this is a reg+imm (as opposed to an address reloc).
|
|
|
|
if (!getLdStOffsetOp(MI).isImm())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock::iterator
|
2016-11-07 23:27:22 +08:00
|
|
|
AArch64LoadStoreOpt::mergeNarrowZeroStores(MachineBasicBlock::iterator I,
|
|
|
|
MachineBasicBlock::iterator MergeMI,
|
|
|
|
const LdStPairFlags &Flags) {
|
|
|
|
assert(isPromotableZeroStoreInst(*I) && isPromotableZeroStoreInst(*MergeMI) &&
|
|
|
|
"Expected promotable zero stores.");
|
|
|
|
|
2020-04-18 09:11:46 +08:00
|
|
|
MachineBasicBlock::iterator E = I->getParent()->end();
|
|
|
|
MachineBasicBlock::iterator NextI = next_nodbg(I, E);
|
2014-03-29 18:18:08 +08:00
|
|
|
// If NextI is the second of the two instructions to be merged, we need
|
|
|
|
// to skip one further. Either way we merge will invalidate the iterator,
|
|
|
|
// and we don't need to scan the new instruction, as it's a pairwise
|
|
|
|
// instruction, which we're not considering for further action anyway.
|
2016-02-10 03:09:22 +08:00
|
|
|
if (NextI == MergeMI)
|
2020-04-18 09:11:46 +08:00
|
|
|
NextI = next_nodbg(NextI, E);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-02-10 03:02:12 +08:00
|
|
|
unsigned Opc = I->getOpcode();
|
2016-03-10 01:29:48 +08:00
|
|
|
bool IsScaled = !TII->isUnscaledLdSt(Opc);
|
2019-12-11 18:29:23 +08:00
|
|
|
int OffsetStride = IsScaled ? 1 : TII->getMemScale(*I);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-07-22 01:42:04 +08:00
|
|
|
bool MergeForward = Flags.getMergeForward();
|
2014-03-29 18:18:08 +08:00
|
|
|
// Insert our new paired instruction after whichever of the paired
|
2014-06-04 20:36:28 +08:00
|
|
|
// instructions MergeForward indicates.
|
2016-02-10 03:09:22 +08:00
|
|
|
MachineBasicBlock::iterator InsertionPoint = MergeForward ? MergeMI : I;
|
2014-06-04 20:36:28 +08:00
|
|
|
// Also based on MergeForward is from where we copy the base register operand
|
2014-03-29 18:18:08 +08:00
|
|
|
// so we get the flags compatible with the input code.
|
2015-08-06 23:50:12 +08:00
|
|
|
const MachineOperand &BaseRegOp =
|
2016-07-09 04:29:42 +08:00
|
|
|
MergeForward ? getLdStBaseOp(*MergeMI) : getLdStBaseOp(*I);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Which register is Rt and which is Rt2 depends on the offset order.
|
2016-11-08 03:11:25 +08:00
|
|
|
MachineInstr *RtMI;
|
2016-07-09 04:29:42 +08:00
|
|
|
if (getLdStOffsetOp(*I).getImm() ==
|
2016-11-08 03:11:25 +08:00
|
|
|
getLdStOffsetOp(*MergeMI).getImm() + OffsetStride)
|
2016-07-09 04:29:42 +08:00
|
|
|
RtMI = &*MergeMI;
|
2016-11-08 03:11:25 +08:00
|
|
|
else
|
2016-07-09 04:29:42 +08:00
|
|
|
RtMI = &*I;
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
int OffsetImm = getLdStOffsetOp(*RtMI).getImm();
|
2016-02-10 03:17:18 +08:00
|
|
|
// Change the scaled offset from small to large type.
|
|
|
|
if (IsScaled) {
|
|
|
|
assert(((OffsetImm & 1) == 0) && "Unexpected offset to merge");
|
|
|
|
OffsetImm /= 2;
|
|
|
|
}
|
|
|
|
|
2016-11-07 23:27:22 +08:00
|
|
|
// Construct the new instruction.
|
2016-02-10 03:33:42 +08:00
|
|
|
DebugLoc DL = I->getDebugLoc();
|
|
|
|
MachineBasicBlock *MBB = I->getParent();
|
2015-11-21 05:14:07 +08:00
|
|
|
MachineInstrBuilder MIB;
|
2016-02-10 03:33:42 +08:00
|
|
|
MIB = BuildMI(*MBB, InsertionPoint, DL, TII->get(getMatchingWideOpcode(Opc)))
|
[AArch64] Merge two adjacent str WZR into str XZR
Summary:
This change merges adjacent 32 bit zero stores into a 64 bit zero store.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
becomes
str xzr, [x0]
Therefore, four adjacent 32 bit zero stores will be a single stp.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
str wzr, [x0, #8]
str wzr, [x0, #12]
becomes
stp xzr, xzr, [x0]
Reviewers: mcrosier, jmolloy, gberry, t.p.northover
Subscribers: aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D16933
llvm-svn: 260682
2016-02-12 23:25:39 +08:00
|
|
|
.addReg(isNarrowStore(Opc) ? AArch64::WZR : AArch64::XZR)
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(BaseRegOp)
|
2016-02-10 03:02:12 +08:00
|
|
|
.addImm(OffsetImm)
|
2018-08-17 05:30:05 +08:00
|
|
|
.cloneMergedMemRefs({&*I, &*MergeMI})
|
2018-03-15 01:10:58 +08:00
|
|
|
.setMIFlags(I->mergeFlagsWith(*MergeMI));
|
2014-03-29 18:18:08 +08:00
|
|
|
(void)MIB;
|
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Creating wider store. Replacing instructions:\n ");
|
|
|
|
LLVM_DEBUG(I->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " ");
|
|
|
|
LLVM_DEBUG(MergeMI->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " with instruction:\n ");
|
|
|
|
LLVM_DEBUG(((MachineInstr *)MIB)->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << "\n");
|
2016-02-10 03:02:12 +08:00
|
|
|
|
|
|
|
// Erase the old instructions.
|
|
|
|
I->eraseFromParent();
|
2016-02-10 03:09:22 +08:00
|
|
|
MergeMI->eraseFromParent();
|
2016-02-10 03:02:12 +08:00
|
|
|
return NextI;
|
|
|
|
}
|
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
// Apply Fn to all instructions between MI and the beginning of the block, until
|
|
|
|
// a def for DefReg is reached. Returns true, iff Fn returns true for all
|
|
|
|
// visited instructions. Stop after visiting Limit iterations.
|
|
|
|
static bool forAllMIsUntilDef(MachineInstr &MI, MCPhysReg DefReg,
|
|
|
|
const TargetRegisterInfo *TRI, unsigned Limit,
|
|
|
|
std::function<bool(MachineInstr &, bool)> &Fn) {
|
|
|
|
auto MBB = MI.getParent();
|
2020-04-18 09:11:46 +08:00
|
|
|
for (MachineInstr &I :
|
|
|
|
instructionsWithoutDebug(MI.getReverseIterator(), MBB->instr_rend())) {
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
if (!Limit)
|
|
|
|
return false;
|
|
|
|
--Limit;
|
|
|
|
|
2020-04-18 09:11:46 +08:00
|
|
|
bool isDef = any_of(I.operands(), [DefReg, TRI](MachineOperand &MOP) {
|
2019-12-12 01:17:29 +08:00
|
|
|
return MOP.isReg() && MOP.isDef() && !MOP.isDebug() && MOP.getReg() &&
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
TRI->regsOverlap(MOP.getReg(), DefReg);
|
|
|
|
});
|
2020-04-18 09:11:46 +08:00
|
|
|
if (!Fn(I, isDef))
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
return false;
|
|
|
|
if (isDef)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void updateDefinedRegisters(MachineInstr &MI, LiveRegUnits &Units,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
|
|
|
|
for (const MachineOperand &MOP : phys_regs_and_masks(MI))
|
|
|
|
if (MOP.isReg() && MOP.isKill())
|
|
|
|
Units.removeReg(MOP.getReg());
|
|
|
|
|
|
|
|
for (const MachineOperand &MOP : phys_regs_and_masks(MI))
|
|
|
|
if (MOP.isReg() && !MOP.isKill())
|
|
|
|
Units.addReg(MOP.getReg());
|
|
|
|
}
|
|
|
|
|
2016-02-10 03:02:12 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
AArch64LoadStoreOpt::mergePairedInsns(MachineBasicBlock::iterator I,
|
|
|
|
MachineBasicBlock::iterator Paired,
|
|
|
|
const LdStPairFlags &Flags) {
|
2020-04-18 09:11:46 +08:00
|
|
|
MachineBasicBlock::iterator E = I->getParent()->end();
|
|
|
|
MachineBasicBlock::iterator NextI = next_nodbg(I, E);
|
2016-02-10 03:02:12 +08:00
|
|
|
// If NextI is the second of the two instructions to be merged, we need
|
|
|
|
// to skip one further. Either way we merge will invalidate the iterator,
|
|
|
|
// and we don't need to scan the new instruction, as it's a pairwise
|
|
|
|
// instruction, which we're not considering for further action anyway.
|
|
|
|
if (NextI == Paired)
|
2020-04-18 09:11:46 +08:00
|
|
|
NextI = next_nodbg(NextI, E);
|
2016-02-10 03:02:12 +08:00
|
|
|
|
|
|
|
int SExtIdx = Flags.getSExtIdx();
|
|
|
|
unsigned Opc =
|
|
|
|
SExtIdx == -1 ? I->getOpcode() : getMatchingNonSExtOpcode(I->getOpcode());
|
2016-03-10 01:29:48 +08:00
|
|
|
bool IsUnscaled = TII->isUnscaledLdSt(Opc);
|
2019-12-11 18:29:23 +08:00
|
|
|
int OffsetStride = IsUnscaled ? TII->getMemScale(*I) : 1;
|
2016-02-10 03:02:12 +08:00
|
|
|
|
|
|
|
bool MergeForward = Flags.getMergeForward();
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
|
|
|
|
Optional<MCPhysReg> RenameReg = Flags.getRenameReg();
|
|
|
|
if (MergeForward && RenameReg) {
|
|
|
|
MCRegister RegToRename = getLdStRegOp(*I).getReg();
|
|
|
|
DefinedInBB.addReg(*RenameReg);
|
|
|
|
|
|
|
|
// Return the sub/super register for RenameReg, matching the size of
|
|
|
|
// OriginalReg.
|
|
|
|
auto GetMatchingSubReg = [this,
|
|
|
|
RenameReg](MCPhysReg OriginalReg) -> MCPhysReg {
|
|
|
|
for (MCPhysReg SubOrSuper : TRI->sub_and_superregs_inclusive(*RenameReg))
|
|
|
|
if (TRI->getMinimalPhysRegClass(OriginalReg) ==
|
|
|
|
TRI->getMinimalPhysRegClass(SubOrSuper))
|
|
|
|
return SubOrSuper;
|
|
|
|
llvm_unreachable("Should have found matching sub or super register!");
|
|
|
|
};
|
|
|
|
|
|
|
|
std::function<bool(MachineInstr &, bool)> UpdateMIs =
|
|
|
|
[this, RegToRename, GetMatchingSubReg](MachineInstr &MI, bool IsDef) {
|
|
|
|
if (IsDef) {
|
|
|
|
bool SeenDef = false;
|
|
|
|
for (auto &MOP : MI.operands()) {
|
|
|
|
// Rename the first explicit definition and all implicit
|
|
|
|
// definitions matching RegToRename.
|
2019-12-12 01:17:29 +08:00
|
|
|
if (MOP.isReg() && !MOP.isDebug() && MOP.getReg() &&
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
(!SeenDef || (MOP.isDef() && MOP.isImplicit())) &&
|
|
|
|
TRI->regsOverlap(MOP.getReg(), RegToRename)) {
|
|
|
|
assert((MOP.isImplicit() ||
|
|
|
|
(MOP.isRenamable() && !MOP.isEarlyClobber())) &&
|
|
|
|
"Need renamable operands");
|
|
|
|
MOP.setReg(GetMatchingSubReg(MOP.getReg()));
|
|
|
|
SeenDef = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (auto &MOP : MI.operands()) {
|
2019-12-12 01:17:29 +08:00
|
|
|
if (MOP.isReg() && !MOP.isDebug() && MOP.getReg() &&
|
|
|
|
TRI->regsOverlap(MOP.getReg(), RegToRename)) {
|
2019-12-21 04:47:38 +08:00
|
|
|
assert((MOP.isImplicit() ||
|
|
|
|
(MOP.isRenamable() && !MOP.isEarlyClobber())) &&
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
"Need renamable operands");
|
|
|
|
MOP.setReg(GetMatchingSubReg(MOP.getReg()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LLVM_DEBUG(dbgs() << "Renamed " << MI << "\n");
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
forAllMIsUntilDef(*I, RegToRename, TRI, LdStLimit, UpdateMIs);
|
|
|
|
|
2019-12-12 02:59:45 +08:00
|
|
|
#if !defined(NDEBUG)
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
// Make sure the register used for renaming is not used between the paired
|
|
|
|
// instructions. That would trash the content before the new paired
|
|
|
|
// instruction.
|
|
|
|
for (auto &MI :
|
|
|
|
iterator_range<MachineInstrBundleIterator<llvm::MachineInstr>>(
|
|
|
|
std::next(I), std::next(Paired)))
|
|
|
|
assert(all_of(MI.operands(),
|
|
|
|
[this, &RenameReg](const MachineOperand &MOP) {
|
2019-12-12 01:17:29 +08:00
|
|
|
return !MOP.isReg() || MOP.isDebug() || !MOP.getReg() ||
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
!TRI->regsOverlap(MOP.getReg(), *RenameReg);
|
|
|
|
}) &&
|
|
|
|
"Rename register used between paired instruction, trashing the "
|
|
|
|
"content");
|
2019-12-12 02:59:45 +08:00
|
|
|
#endif
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
}
|
|
|
|
|
2016-02-10 03:02:12 +08:00
|
|
|
// Insert our new paired instruction after whichever of the paired
|
|
|
|
// instructions MergeForward indicates.
|
|
|
|
MachineBasicBlock::iterator InsertionPoint = MergeForward ? Paired : I;
|
|
|
|
// Also based on MergeForward is from where we copy the base register operand
|
|
|
|
// so we get the flags compatible with the input code.
|
|
|
|
const MachineOperand &BaseRegOp =
|
2016-07-09 04:29:42 +08:00
|
|
|
MergeForward ? getLdStBaseOp(*Paired) : getLdStBaseOp(*I);
|
2016-02-10 03:02:12 +08:00
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
int Offset = getLdStOffsetOp(*I).getImm();
|
|
|
|
int PairedOffset = getLdStOffsetOp(*Paired).getImm();
|
2016-03-10 01:29:48 +08:00
|
|
|
bool PairedIsUnscaled = TII->isUnscaledLdSt(Paired->getOpcode());
|
2016-02-11 22:25:08 +08:00
|
|
|
if (IsUnscaled != PairedIsUnscaled) {
|
|
|
|
// We're trying to pair instructions that differ in how they are scaled. If
|
|
|
|
// I is scaled then scale the offset of Paired accordingly. Otherwise, do
|
|
|
|
// the opposite (i.e., make Paired's offset unscaled).
|
2019-12-11 18:29:23 +08:00
|
|
|
int MemSize = TII->getMemScale(*Paired);
|
2016-02-11 22:25:08 +08:00
|
|
|
if (PairedIsUnscaled) {
|
|
|
|
// If the unscaled offset isn't a multiple of the MemSize, we can't
|
|
|
|
// pair the operations together.
|
2019-12-11 18:29:23 +08:00
|
|
|
assert(!(PairedOffset % TII->getMemScale(*Paired)) &&
|
2016-02-11 22:25:08 +08:00
|
|
|
"Offset should be a multiple of the stride!");
|
|
|
|
PairedOffset /= MemSize;
|
|
|
|
} else {
|
|
|
|
PairedOffset *= MemSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 03:02:12 +08:00
|
|
|
// Which register is Rt and which is Rt2 depends on the offset order.
|
|
|
|
MachineInstr *RtMI, *Rt2MI;
|
2016-02-11 22:25:08 +08:00
|
|
|
if (Offset == PairedOffset + OffsetStride) {
|
2016-07-09 04:29:42 +08:00
|
|
|
RtMI = &*Paired;
|
|
|
|
Rt2MI = &*I;
|
2016-02-10 03:02:12 +08:00
|
|
|
// Here we swapped the assumption made for SExtIdx.
|
|
|
|
// I.e., we turn ldp I, Paired into ldp Paired, I.
|
|
|
|
// Update the index accordingly.
|
|
|
|
if (SExtIdx != -1)
|
|
|
|
SExtIdx = (SExtIdx + 1) % 2;
|
|
|
|
} else {
|
2016-07-09 04:29:42 +08:00
|
|
|
RtMI = &*I;
|
|
|
|
Rt2MI = &*Paired;
|
2016-02-10 03:02:12 +08:00
|
|
|
}
|
2016-07-09 04:29:42 +08:00
|
|
|
int OffsetImm = getLdStOffsetOp(*RtMI).getImm();
|
2016-02-11 22:25:08 +08:00
|
|
|
// Scale the immediate offset, if necessary.
|
2016-03-10 01:29:48 +08:00
|
|
|
if (TII->isUnscaledLdSt(RtMI->getOpcode())) {
|
2019-12-11 18:29:23 +08:00
|
|
|
assert(!(OffsetImm % TII->getMemScale(*RtMI)) &&
|
2016-02-11 22:25:08 +08:00
|
|
|
"Unscaled offset cannot be scaled.");
|
2019-12-11 18:29:23 +08:00
|
|
|
OffsetImm /= TII->getMemScale(*RtMI);
|
2016-02-10 04:18:07 +08:00
|
|
|
}
|
2016-02-10 03:02:12 +08:00
|
|
|
|
|
|
|
// Construct the new instruction.
|
|
|
|
MachineInstrBuilder MIB;
|
2016-02-10 03:33:42 +08:00
|
|
|
DebugLoc DL = I->getDebugLoc();
|
|
|
|
MachineBasicBlock *MBB = I->getParent();
|
2017-01-21 02:04:27 +08:00
|
|
|
MachineOperand RegOp0 = getLdStRegOp(*RtMI);
|
|
|
|
MachineOperand RegOp1 = getLdStRegOp(*Rt2MI);
|
|
|
|
// Kill flags may become invalid when moving stores for pairing.
|
|
|
|
if (RegOp0.isUse()) {
|
|
|
|
if (!MergeForward) {
|
|
|
|
// Clear kill flags on store if moving upwards. Example:
|
|
|
|
// STRWui %w0, ...
|
|
|
|
// USE %w1
|
|
|
|
// STRWui kill %w1 ; need to clear kill flag when moving STRWui upwards
|
|
|
|
RegOp0.setIsKill(false);
|
|
|
|
RegOp1.setIsKill(false);
|
|
|
|
} else {
|
|
|
|
// Clear kill flags of the first stores register. Example:
|
|
|
|
// STRWui %w1, ...
|
|
|
|
// USE kill %w1 ; need to clear kill flag when moving STRWui downwards
|
|
|
|
// STRW %w0
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register Reg = getLdStRegOp(*I).getReg();
|
2017-01-21 02:04:27 +08:00
|
|
|
for (MachineInstr &MI : make_range(std::next(I), Paired))
|
|
|
|
MI.clearRegisterKills(Reg, TRI);
|
|
|
|
}
|
|
|
|
}
|
2016-02-10 03:33:42 +08:00
|
|
|
MIB = BuildMI(*MBB, InsertionPoint, DL, TII->get(getMatchingPairOpcode(Opc)))
|
2017-01-21 02:04:27 +08:00
|
|
|
.add(RegOp0)
|
|
|
|
.add(RegOp1)
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(BaseRegOp)
|
2016-03-09 01:16:38 +08:00
|
|
|
.addImm(OffsetImm)
|
2018-08-17 05:30:05 +08:00
|
|
|
.cloneMergedMemRefs({&*I, &*Paired})
|
2018-03-15 01:10:58 +08:00
|
|
|
.setMIFlags(I->mergeFlagsWith(*Paired));
|
2016-02-10 03:02:12 +08:00
|
|
|
|
|
|
|
(void)MIB;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(
|
|
|
|
dbgs() << "Creating pair load/store. Replacing instructions:\n ");
|
|
|
|
LLVM_DEBUG(I->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " ");
|
|
|
|
LLVM_DEBUG(Paired->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " with instruction:\n ");
|
2015-03-07 06:42:10 +08:00
|
|
|
if (SExtIdx != -1) {
|
|
|
|
// Generate the sign extension for the proper result of the ldp.
|
|
|
|
// I.e., with X1, that would be:
|
2017-12-07 18:40:31 +08:00
|
|
|
// %w1 = KILL %w1, implicit-def %x1
|
|
|
|
// %x1 = SBFMXri killed %x1, 0, 31
|
2015-03-07 06:42:10 +08:00
|
|
|
MachineOperand &DstMO = MIB->getOperand(SExtIdx);
|
|
|
|
// Right now, DstMO has the extended register, since it comes from an
|
|
|
|
// extended opcode.
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register DstRegX = DstMO.getReg();
|
2015-03-07 06:42:10 +08:00
|
|
|
// Get the W variant of that register.
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register DstRegW = TRI->getSubReg(DstRegX, AArch64::sub_32);
|
2015-03-07 06:42:10 +08:00
|
|
|
// Update the result of LDP to use the W instead of the X variant.
|
|
|
|
DstMO.setReg(DstRegW);
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(((MachineInstr *)MIB)->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << "\n");
|
2015-03-07 06:42:10 +08:00
|
|
|
// Make the machine verifier happy by providing a definition for
|
|
|
|
// the X register.
|
|
|
|
// Insert this definition right after the generated LDP, i.e., before
|
|
|
|
// InsertionPoint.
|
|
|
|
MachineInstrBuilder MIBKill =
|
2016-02-10 03:33:42 +08:00
|
|
|
BuildMI(*MBB, InsertionPoint, DL, TII->get(TargetOpcode::KILL), DstRegW)
|
2015-03-07 06:42:10 +08:00
|
|
|
.addReg(DstRegW)
|
|
|
|
.addReg(DstRegX, RegState::Define);
|
|
|
|
MIBKill->getOperand(2).setImplicit();
|
|
|
|
// Create the sign extension.
|
|
|
|
MachineInstrBuilder MIBSXTW =
|
2016-02-10 03:33:42 +08:00
|
|
|
BuildMI(*MBB, InsertionPoint, DL, TII->get(AArch64::SBFMXri), DstRegX)
|
2015-03-07 06:42:10 +08:00
|
|
|
.addReg(DstRegX)
|
|
|
|
.addImm(0)
|
|
|
|
.addImm(31);
|
|
|
|
(void)MIBSXTW;
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << " Extend operand:\n ");
|
|
|
|
LLVM_DEBUG(((MachineInstr *)MIBSXTW)->print(dbgs()));
|
2015-03-07 06:42:10 +08:00
|
|
|
} else {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(((MachineInstr *)MIB)->print(dbgs()));
|
2015-03-07 06:42:10 +08:00
|
|
|
}
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "\n");
|
2014-03-29 18:18:08 +08:00
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
if (MergeForward)
|
|
|
|
for (const MachineOperand &MOP : phys_regs_and_masks(*I))
|
|
|
|
if (MOP.isReg() && MOP.isKill())
|
|
|
|
DefinedInBB.addReg(MOP.getReg());
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// Erase the old instructions.
|
|
|
|
I->eraseFromParent();
|
|
|
|
Paired->eraseFromParent();
|
|
|
|
|
|
|
|
return NextI;
|
|
|
|
}
|
|
|
|
|
2015-12-23 00:36:16 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
AArch64LoadStoreOpt::promoteLoadFromStore(MachineBasicBlock::iterator LoadI,
|
|
|
|
MachineBasicBlock::iterator StoreI) {
|
2020-04-18 09:11:46 +08:00
|
|
|
MachineBasicBlock::iterator NextI =
|
|
|
|
next_nodbg(LoadI, LoadI->getParent()->end());
|
2015-12-23 00:36:16 +08:00
|
|
|
|
2019-12-11 18:29:23 +08:00
|
|
|
int LoadSize = TII->getMemScale(*LoadI);
|
|
|
|
int StoreSize = TII->getMemScale(*StoreI);
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register LdRt = getLdStRegOp(*LoadI).getReg();
|
2017-06-21 16:47:23 +08:00
|
|
|
const MachineOperand &StMO = getLdStRegOp(*StoreI);
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register StRt = getLdStRegOp(*StoreI).getReg();
|
2015-12-23 00:36:16 +08:00
|
|
|
bool IsStoreXReg = TRI->getRegClass(AArch64::GPR64RegClassID)->contains(StRt);
|
|
|
|
|
|
|
|
assert((IsStoreXReg ||
|
|
|
|
TRI->getRegClass(AArch64::GPR32RegClassID)->contains(StRt)) &&
|
|
|
|
"Unexpected RegClass");
|
|
|
|
|
|
|
|
MachineInstr *BitExtMI;
|
|
|
|
if (LoadSize == StoreSize && (LoadSize == 4 || LoadSize == 8)) {
|
|
|
|
// Remove the load, if the destination register of the loads is the same
|
|
|
|
// register for stored value.
|
|
|
|
if (StRt == LdRt && LoadSize == 8) {
|
2017-06-27 02:49:25 +08:00
|
|
|
for (MachineInstr &MI : make_range(StoreI->getIterator(),
|
|
|
|
LoadI->getIterator())) {
|
|
|
|
if (MI.killsRegister(StRt, TRI)) {
|
|
|
|
MI.clearRegisterKills(StRt, TRI);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Remove load instruction:\n ");
|
|
|
|
LLVM_DEBUG(LoadI->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << "\n");
|
2015-12-23 00:36:16 +08:00
|
|
|
LoadI->eraseFromParent();
|
|
|
|
return NextI;
|
|
|
|
}
|
|
|
|
// Replace the load with a mov if the load and store are in the same size.
|
|
|
|
BitExtMI =
|
|
|
|
BuildMI(*LoadI->getParent(), LoadI, LoadI->getDebugLoc(),
|
|
|
|
TII->get(IsStoreXReg ? AArch64::ORRXrs : AArch64::ORRWrs), LdRt)
|
|
|
|
.addReg(IsStoreXReg ? AArch64::XZR : AArch64::WZR)
|
2017-06-21 16:47:23 +08:00
|
|
|
.add(StMO)
|
2018-03-15 01:10:58 +08:00
|
|
|
.addImm(AArch64_AM::getShifterImm(AArch64_AM::LSL, 0))
|
|
|
|
.setMIFlags(LoadI->getFlags());
|
2015-12-23 00:36:16 +08:00
|
|
|
} else {
|
|
|
|
// FIXME: Currently we disable this transformation in big-endian targets as
|
|
|
|
// performance and correctness are verified only in little-endian.
|
|
|
|
if (!Subtarget->isLittleEndian())
|
|
|
|
return NextI;
|
2016-06-30 08:01:54 +08:00
|
|
|
bool IsUnscaled = TII->isUnscaledLdSt(*LoadI);
|
|
|
|
assert(IsUnscaled == TII->isUnscaledLdSt(*StoreI) &&
|
2016-03-10 01:29:48 +08:00
|
|
|
"Unsupported ld/st match");
|
2015-12-23 00:36:16 +08:00
|
|
|
assert(LoadSize <= StoreSize && "Invalid load size");
|
|
|
|
int UnscaledLdOffset = IsUnscaled
|
2016-07-09 04:29:42 +08:00
|
|
|
? getLdStOffsetOp(*LoadI).getImm()
|
|
|
|
: getLdStOffsetOp(*LoadI).getImm() * LoadSize;
|
2015-12-23 00:36:16 +08:00
|
|
|
int UnscaledStOffset = IsUnscaled
|
2016-07-09 04:29:42 +08:00
|
|
|
? getLdStOffsetOp(*StoreI).getImm()
|
|
|
|
: getLdStOffsetOp(*StoreI).getImm() * StoreSize;
|
2015-12-23 00:36:16 +08:00
|
|
|
int Width = LoadSize * 8;
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
unsigned DestReg =
|
|
|
|
IsStoreXReg ? Register(TRI->getMatchingSuperReg(
|
|
|
|
LdRt, AArch64::sub_32, &AArch64::GPR64RegClass))
|
|
|
|
: LdRt;
|
2015-12-23 00:36:16 +08:00
|
|
|
|
|
|
|
assert((UnscaledLdOffset >= UnscaledStOffset &&
|
|
|
|
(UnscaledLdOffset + LoadSize) <= UnscaledStOffset + StoreSize) &&
|
|
|
|
"Invalid offset");
|
|
|
|
|
2019-05-09 00:29:39 +08:00
|
|
|
int Immr = 8 * (UnscaledLdOffset - UnscaledStOffset);
|
|
|
|
int Imms = Immr + Width - 1;
|
2015-12-23 00:36:16 +08:00
|
|
|
if (UnscaledLdOffset == UnscaledStOffset) {
|
|
|
|
uint32_t AndMaskEncoded = ((IsStoreXReg ? 1 : 0) << 12) // N
|
|
|
|
| ((Immr) << 6) // immr
|
|
|
|
| ((Imms) << 0) // imms
|
|
|
|
;
|
|
|
|
|
|
|
|
BitExtMI =
|
|
|
|
BuildMI(*LoadI->getParent(), LoadI, LoadI->getDebugLoc(),
|
|
|
|
TII->get(IsStoreXReg ? AArch64::ANDXri : AArch64::ANDWri),
|
|
|
|
DestReg)
|
2017-06-21 16:47:23 +08:00
|
|
|
.add(StMO)
|
2018-03-15 01:10:58 +08:00
|
|
|
.addImm(AndMaskEncoded)
|
|
|
|
.setMIFlags(LoadI->getFlags());
|
2015-12-23 00:36:16 +08:00
|
|
|
} else {
|
|
|
|
BitExtMI =
|
|
|
|
BuildMI(*LoadI->getParent(), LoadI, LoadI->getDebugLoc(),
|
|
|
|
TII->get(IsStoreXReg ? AArch64::UBFMXri : AArch64::UBFMWri),
|
|
|
|
DestReg)
|
2017-06-21 16:47:23 +08:00
|
|
|
.add(StMO)
|
2015-12-23 00:36:16 +08:00
|
|
|
.addImm(Immr)
|
2018-03-15 01:10:58 +08:00
|
|
|
.addImm(Imms)
|
|
|
|
.setMIFlags(LoadI->getFlags());
|
2015-12-23 00:36:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-17 07:55:43 +08:00
|
|
|
|
2017-02-18 07:15:03 +08:00
|
|
|
// Clear kill flags between store and load.
|
|
|
|
for (MachineInstr &MI : make_range(StoreI->getIterator(),
|
|
|
|
BitExtMI->getIterator()))
|
2017-06-21 17:51:52 +08:00
|
|
|
if (MI.killsRegister(StRt, TRI)) {
|
|
|
|
MI.clearRegisterKills(StRt, TRI);
|
|
|
|
break;
|
|
|
|
}
|
2015-12-23 00:36:16 +08:00
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Promoting load by replacing :\n ");
|
|
|
|
LLVM_DEBUG(StoreI->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " ");
|
|
|
|
LLVM_DEBUG(LoadI->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " with instructions:\n ");
|
|
|
|
LLVM_DEBUG(StoreI->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " ");
|
|
|
|
LLVM_DEBUG((BitExtMI)->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << "\n");
|
2015-12-23 00:36:16 +08:00
|
|
|
|
|
|
|
// Erase the old instructions.
|
|
|
|
LoadI->eraseFromParent();
|
|
|
|
return NextI;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
static bool inBoundsForPair(bool IsUnscaled, int Offset, int OffsetStride) {
|
2015-08-19 00:20:03 +08:00
|
|
|
// Convert the byte-offset used by unscaled into an "element" offset used
|
|
|
|
// by the scaled pair load/store instructions.
|
2016-02-11 22:25:08 +08:00
|
|
|
if (IsUnscaled) {
|
|
|
|
// If the byte-offset isn't a multiple of the stride, there's no point
|
|
|
|
// trying to match it.
|
|
|
|
if (Offset % OffsetStride)
|
|
|
|
return false;
|
2015-08-19 00:20:03 +08:00
|
|
|
Offset /= OffsetStride;
|
2016-02-11 22:25:08 +08:00
|
|
|
}
|
2015-08-19 00:20:03 +08:00
|
|
|
return Offset <= 63 && Offset >= -64;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do alignment, specialized to power of 2 and for signed ints,
|
|
|
|
// avoiding having to do a C-style cast from uint_64t to int when
|
2016-01-15 05:06:47 +08:00
|
|
|
// using alignTo from include/llvm/Support/MathExtras.h.
|
2014-03-29 18:18:08 +08:00
|
|
|
// FIXME: Move this function to include/MathExtras.h?
|
|
|
|
static int alignTo(int Num, int PowOf2) {
|
|
|
|
return (Num + PowOf2 - 1) & ~(PowOf2 - 1);
|
|
|
|
}
|
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
static bool mayAlias(MachineInstr &MIa,
|
2015-05-22 05:36:46 +08:00
|
|
|
SmallVectorImpl<MachineInstr *> &MemInsns,
|
2017-03-17 22:19:55 +08:00
|
|
|
AliasAnalysis *AA) {
|
2016-06-30 08:01:54 +08:00
|
|
|
for (MachineInstr *MIb : MemInsns)
|
2020-04-25 04:52:31 +08:00
|
|
|
if (MIa.mayAlias(AA, *MIb, /*UseTBAA*/ false))
|
2015-05-22 05:36:46 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-23 00:36:16 +08:00
|
|
|
bool AArch64LoadStoreOpt::findMatchingStore(
|
|
|
|
MachineBasicBlock::iterator I, unsigned Limit,
|
|
|
|
MachineBasicBlock::iterator &StoreI) {
|
2016-02-12 00:18:24 +08:00
|
|
|
MachineBasicBlock::iterator B = I->getParent()->begin();
|
2015-12-23 00:36:16 +08:00
|
|
|
MachineBasicBlock::iterator MBBI = I;
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &LoadMI = *I;
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register BaseReg = getLdStBaseOp(LoadMI).getReg();
|
2015-12-23 00:36:16 +08:00
|
|
|
|
2016-02-12 00:18:24 +08:00
|
|
|
// If the load is the first instruction in the block, there's obviously
|
|
|
|
// not any matching store.
|
|
|
|
if (MBBI == B)
|
|
|
|
return false;
|
|
|
|
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
// Track which register units have been modified and used between the first
|
|
|
|
// insn and the second insn.
|
|
|
|
ModifiedRegUnits.clear();
|
|
|
|
UsedRegUnits.clear();
|
2015-12-23 00:36:16 +08:00
|
|
|
|
2016-02-12 00:18:24 +08:00
|
|
|
unsigned Count = 0;
|
|
|
|
do {
|
2020-04-18 09:11:46 +08:00
|
|
|
MBBI = prev_nodbg(MBBI, B);
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MI = *MBBI;
|
2016-02-12 00:18:24 +08:00
|
|
|
|
2016-07-21 23:20:25 +08:00
|
|
|
// Don't count transient instructions towards the search limit since there
|
|
|
|
// may be different numbers of them if e.g. debug information is present.
|
|
|
|
if (!MI.isTransient())
|
2016-02-12 00:18:24 +08:00
|
|
|
++Count;
|
2015-12-23 00:36:16 +08:00
|
|
|
|
|
|
|
// If the load instruction reads directly from the address to which the
|
|
|
|
// store instruction writes and the stored value is not modified, we can
|
|
|
|
// promote the load. Since we do not handle stores with pre-/post-index,
|
|
|
|
// it's unnecessary to check if BaseReg is modified by the store itself.
|
2020-09-23 22:44:30 +08:00
|
|
|
// Also we can't handle stores without an immediate offset operand,
|
|
|
|
// while the operand might be the address for a global variable.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (MI.mayStore() && isMatchingStore(LoadMI, MI) &&
|
2020-09-23 22:44:30 +08:00
|
|
|
BaseReg == getLdStBaseOp(MI).getReg() && getLdStOffsetOp(MI).isImm() &&
|
2016-03-10 01:29:48 +08:00
|
|
|
isLdOffsetInRangeOfSt(LoadMI, MI, TII) &&
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
ModifiedRegUnits.available(getLdStRegOp(MI).getReg())) {
|
2015-12-23 00:36:16 +08:00
|
|
|
StoreI = MBBI;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
if (MI.isCall())
|
2015-12-23 00:36:16 +08:00
|
|
|
return false;
|
|
|
|
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
// Update modified / uses register units.
|
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits, TRI);
|
2015-12-23 00:36:16 +08:00
|
|
|
|
|
|
|
// Otherwise, if the base register is modified, we have no match, so
|
|
|
|
// return early.
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
if (!ModifiedRegUnits.available(BaseReg))
|
2015-12-23 00:36:16 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// If we encounter a store aliased with the load, return early.
|
2020-04-25 04:52:31 +08:00
|
|
|
if (MI.mayStore() && LoadMI.mayAlias(AA, MI, /*UseTBAA*/ false))
|
2015-12-23 00:36:16 +08:00
|
|
|
return false;
|
2016-02-12 00:18:24 +08:00
|
|
|
} while (MBBI != B && Count < Limit);
|
2015-12-23 00:36:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-11 04:47:14 +08:00
|
|
|
// Returns true if FirstMI and MI are candidates for merging or pairing.
|
|
|
|
// Otherwise, returns false.
|
2016-07-09 04:29:42 +08:00
|
|
|
static bool areCandidatesToMergeOrPair(MachineInstr &FirstMI, MachineInstr &MI,
|
2016-06-11 04:47:14 +08:00
|
|
|
LdStPairFlags &Flags,
|
|
|
|
const AArch64InstrInfo *TII) {
|
|
|
|
// If this is volatile or if pairing is suppressed, not a candidate.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (MI.hasOrderedMemoryRef() || TII->isLdStPairSuppressed(MI))
|
2016-06-11 04:47:14 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// We should have already checked FirstMI for pair suppression and volatility.
|
2016-07-09 04:29:42 +08:00
|
|
|
assert(!FirstMI.hasOrderedMemoryRef() &&
|
|
|
|
!TII->isLdStPairSuppressed(FirstMI) &&
|
2016-06-11 04:47:14 +08:00
|
|
|
"FirstMI shouldn't get here if either of these checks are true.");
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
unsigned OpcA = FirstMI.getOpcode();
|
|
|
|
unsigned OpcB = MI.getOpcode();
|
2016-06-11 04:47:14 +08:00
|
|
|
|
2016-02-11 03:45:48 +08:00
|
|
|
// Opcodes match: nothing more to check.
|
|
|
|
if (OpcA == OpcB)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Try to match a sign-extended load/store with a zero-extended load/store.
|
|
|
|
bool IsValidLdStrOpc, PairIsValidLdStrOpc;
|
|
|
|
unsigned NonSExtOpc = getMatchingNonSExtOpcode(OpcA, &IsValidLdStrOpc);
|
|
|
|
assert(IsValidLdStrOpc &&
|
|
|
|
"Given Opc should be a Load or Store with an immediate");
|
|
|
|
// OpcA will be the first instruction in the pair.
|
|
|
|
if (NonSExtOpc == getMatchingNonSExtOpcode(OpcB, &PairIsValidLdStrOpc)) {
|
|
|
|
Flags.setSExtIdx(NonSExtOpc == (unsigned)OpcA ? 1 : 0);
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-11 22:25:08 +08:00
|
|
|
|
2016-11-07 23:27:22 +08:00
|
|
|
// If the second instruction isn't even a mergable/pairable load/store, bail
|
|
|
|
// out.
|
2016-02-11 22:25:08 +08:00
|
|
|
if (!PairIsValidLdStrOpc)
|
|
|
|
return false;
|
|
|
|
|
2016-11-07 23:27:22 +08:00
|
|
|
// FIXME: We don't support merging narrow stores with mixed scaled/unscaled
|
|
|
|
// offsets.
|
|
|
|
if (isNarrowStore(OpcA) || isNarrowStore(OpcB))
|
2016-02-11 22:25:08 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Try to match an unscaled load/store with a scaled load/store.
|
2016-03-10 01:29:48 +08:00
|
|
|
return TII->isUnscaledLdSt(OpcA) != TII->isUnscaledLdSt(OpcB) &&
|
2016-02-11 22:25:08 +08:00
|
|
|
getMatchingPairOpcode(OpcA) == getMatchingPairOpcode(OpcB);
|
|
|
|
|
|
|
|
// FIXME: Can we also match a mixed sext/zext unscaled/scaled pair?
|
2016-02-11 03:45:48 +08:00
|
|
|
}
|
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
static bool
|
|
|
|
canRenameUpToDef(MachineInstr &FirstMI, LiveRegUnits &UsedInBetween,
|
|
|
|
SmallPtrSetImpl<const TargetRegisterClass *> &RequiredClasses,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
if (!FirstMI.mayStore())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check if we can find an unused register which we can use to rename
|
|
|
|
// the register used by the first load/store.
|
|
|
|
auto *RegClass = TRI->getMinimalPhysRegClass(getLdStRegOp(FirstMI).getReg());
|
|
|
|
MachineFunction &MF = *FirstMI.getParent()->getParent();
|
|
|
|
if (!RegClass || !MF.getRegInfo().tracksLiveness())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto RegToRename = getLdStRegOp(FirstMI).getReg();
|
|
|
|
// For now, we only rename if the store operand gets killed at the store.
|
|
|
|
if (!getLdStRegOp(FirstMI).isKill() &&
|
|
|
|
!any_of(FirstMI.operands(),
|
|
|
|
[TRI, RegToRename](const MachineOperand &MOP) {
|
2019-12-12 01:17:29 +08:00
|
|
|
return MOP.isReg() && !MOP.isDebug() && MOP.getReg() &&
|
|
|
|
MOP.isImplicit() && MOP.isKill() &&
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
TRI->regsOverlap(RegToRename, MOP.getReg());
|
|
|
|
})) {
|
|
|
|
LLVM_DEBUG(dbgs() << " Operand not killed at " << FirstMI << "\n");
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-09 02:25:14 +08:00
|
|
|
auto canRenameMOP = [TRI](const MachineOperand &MOP) {
|
|
|
|
if (MOP.isReg()) {
|
|
|
|
auto *RegClass = TRI->getMinimalPhysRegClass(MOP.getReg());
|
|
|
|
// Renaming registers with multiple disjunct sub-registers (e.g. the
|
|
|
|
// result of a LD3) means that all sub-registers are renamed, potentially
|
|
|
|
// impacting other instructions we did not check. Bail out.
|
|
|
|
// Note that this relies on the structure of the AArch64 register file. In
|
|
|
|
// particular, a subregister cannot be written without overwriting the
|
|
|
|
// whole register.
|
|
|
|
if (RegClass->HasDisjunctSubRegs) {
|
|
|
|
LLVM_DEBUG(
|
|
|
|
dbgs()
|
|
|
|
<< " Cannot rename operands with multiple disjunct subregisters ("
|
|
|
|
<< MOP << ")\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
return MOP.isImplicit() ||
|
|
|
|
(MOP.isRenamable() && !MOP.isEarlyClobber() && !MOP.isTied());
|
|
|
|
};
|
|
|
|
|
|
|
|
bool FoundDef = false;
|
|
|
|
|
|
|
|
// For each instruction between FirstMI and the previous def for RegToRename,
|
|
|
|
// we
|
|
|
|
// * check if we can rename RegToRename in this instruction
|
|
|
|
// * collect the registers used and required register classes for RegToRename.
|
|
|
|
std::function<bool(MachineInstr &, bool)> CheckMIs = [&](MachineInstr &MI,
|
|
|
|
bool IsDef) {
|
|
|
|
LLVM_DEBUG(dbgs() << "Checking " << MI << "\n");
|
|
|
|
// Currently we do not try to rename across frame-setup instructions.
|
|
|
|
if (MI.getFlag(MachineInstr::FrameSetup)) {
|
|
|
|
LLVM_DEBUG(dbgs() << " Cannot rename framesetup instructions currently ("
|
|
|
|
<< MI << ")\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
UsedInBetween.accumulate(MI);
|
|
|
|
|
|
|
|
// For a definition, check that we can rename the definition and exit the
|
|
|
|
// loop.
|
|
|
|
FoundDef = IsDef;
|
|
|
|
|
|
|
|
// For defs, check if we can rename the first def of RegToRename.
|
|
|
|
if (FoundDef) {
|
2020-01-23 01:16:40 +08:00
|
|
|
// For some pseudo instructions, we might not generate code in the end
|
|
|
|
// (e.g. KILL) and we would end up without a correct def for the rename
|
|
|
|
// register.
|
|
|
|
// TODO: This might be overly conservative and we could handle those cases
|
|
|
|
// in multiple ways:
|
|
|
|
// 1. Insert an extra copy, to materialize the def.
|
|
|
|
// 2. Skip pseudo-defs until we find an non-pseudo def.
|
|
|
|
if (MI.isPseudo()) {
|
|
|
|
LLVM_DEBUG(dbgs() << " Cannot rename pseudo instruction " << MI
|
|
|
|
<< "\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
for (auto &MOP : MI.operands()) {
|
2019-12-12 01:17:29 +08:00
|
|
|
if (!MOP.isReg() || !MOP.isDef() || MOP.isDebug() || !MOP.getReg() ||
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
!TRI->regsOverlap(MOP.getReg(), RegToRename))
|
|
|
|
continue;
|
|
|
|
if (!canRenameMOP(MOP)) {
|
|
|
|
LLVM_DEBUG(dbgs()
|
|
|
|
<< " Cannot rename " << MOP << " in " << MI << "\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
RequiredClasses.insert(TRI->getMinimalPhysRegClass(MOP.getReg()));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
for (auto &MOP : MI.operands()) {
|
2019-12-12 01:17:29 +08:00
|
|
|
if (!MOP.isReg() || MOP.isDebug() || !MOP.getReg() ||
|
|
|
|
!TRI->regsOverlap(MOP.getReg(), RegToRename))
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!canRenameMOP(MOP)) {
|
|
|
|
LLVM_DEBUG(dbgs()
|
|
|
|
<< " Cannot rename " << MOP << " in " << MI << "\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
RequiredClasses.insert(TRI->getMinimalPhysRegClass(MOP.getReg()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!forAllMIsUntilDef(FirstMI, RegToRename, TRI, LdStLimit, CheckMIs))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!FoundDef) {
|
|
|
|
LLVM_DEBUG(dbgs() << " Did not find definition for register in BB\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we can find a physical register for renaming. This register must:
|
|
|
|
// * not be defined up to FirstMI (checking DefinedInBB)
|
|
|
|
// * not used between the MI and the defining instruction of the register to
|
|
|
|
// rename (checked using UsedInBetween).
|
|
|
|
// * is available in all used register classes (checked using RequiredClasses).
|
|
|
|
static Optional<MCPhysReg> tryToFindRegisterToRename(
|
|
|
|
MachineInstr &FirstMI, MachineInstr &MI, LiveRegUnits &DefinedInBB,
|
|
|
|
LiveRegUnits &UsedInBetween,
|
|
|
|
SmallPtrSetImpl<const TargetRegisterClass *> &RequiredClasses,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
auto &MF = *FirstMI.getParent()->getParent();
|
2019-12-21 21:47:08 +08:00
|
|
|
MachineRegisterInfo &RegInfo = MF.getRegInfo();
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
|
|
|
|
// Checks if any sub- or super-register of PR is callee saved.
|
|
|
|
auto AnySubOrSuperRegCalleePreserved = [&MF, TRI](MCPhysReg PR) {
|
|
|
|
return any_of(TRI->sub_and_superregs_inclusive(PR),
|
|
|
|
[&MF, TRI](MCPhysReg SubOrSuper) {
|
|
|
|
return TRI->isCalleeSavedPhysReg(SubOrSuper, MF);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check if PR or one of its sub- or super-registers can be used for all
|
|
|
|
// required register classes.
|
|
|
|
auto CanBeUsedForAllClasses = [&RequiredClasses, TRI](MCPhysReg PR) {
|
|
|
|
return all_of(RequiredClasses, [PR, TRI](const TargetRegisterClass *C) {
|
|
|
|
return any_of(TRI->sub_and_superregs_inclusive(PR),
|
|
|
|
[C, TRI](MCPhysReg SubOrSuper) {
|
|
|
|
return C == TRI->getMinimalPhysRegClass(SubOrSuper);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
auto *RegClass = TRI->getMinimalPhysRegClass(getLdStRegOp(FirstMI).getReg());
|
|
|
|
for (const MCPhysReg &PR : *RegClass) {
|
|
|
|
if (DefinedInBB.available(PR) && UsedInBetween.available(PR) &&
|
2019-12-21 21:47:08 +08:00
|
|
|
!RegInfo.isReserved(PR) && !AnySubOrSuperRegCalleePreserved(PR) &&
|
|
|
|
CanBeUsedForAllClasses(PR)) {
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
DefinedInBB.addReg(PR);
|
|
|
|
LLVM_DEBUG(dbgs() << "Found rename register " << printReg(PR, TRI)
|
|
|
|
<< "\n");
|
|
|
|
return {PR};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LLVM_DEBUG(dbgs() << "No rename register found from "
|
|
|
|
<< TRI->getRegClassName(RegClass) << "\n");
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2016-02-11 02:49:28 +08:00
|
|
|
/// Scan the instructions looking for a load/store that can be combined with the
|
|
|
|
/// current instruction into a wider equivalent or a load/store pair.
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock::iterator
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
|
[AArch64] Handle missing store pair opportunity
Summary:
This change will handle missing store pair opportunity where the first store
instruction stores zero followed by the non-zero store. For example, this change
will convert :
str wzr, [x8]
str w1, [x8, #4]
into:
stp wzr, w1, [x8]
Reviewers: jmolloy, t.p.northover, mcrosier
Subscribers: flyingforyou, aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18570
llvm-svn: 265021
2016-03-31 22:47:24 +08:00
|
|
|
LdStPairFlags &Flags, unsigned Limit,
|
|
|
|
bool FindNarrowMerge) {
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock::iterator E = I->getParent()->end();
|
|
|
|
MachineBasicBlock::iterator MBBI = I;
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
MachineBasicBlock::iterator MBBIWithRenameReg;
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &FirstMI = *I;
|
2020-04-18 09:11:46 +08:00
|
|
|
MBBI = next_nodbg(MBBI, E);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
bool MayLoad = FirstMI.mayLoad();
|
|
|
|
bool IsUnscaled = TII->isUnscaledLdSt(FirstMI);
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register Reg = getLdStRegOp(FirstMI).getReg();
|
|
|
|
Register BaseReg = getLdStBaseOp(FirstMI).getReg();
|
2015-08-06 23:50:12 +08:00
|
|
|
int Offset = getLdStOffsetOp(FirstMI).getImm();
|
2019-12-11 18:29:23 +08:00
|
|
|
int OffsetStride = IsUnscaled ? TII->getMemScale(FirstMI) : 1;
|
[AArch64] Merge two adjacent str WZR into str XZR
Summary:
This change merges adjacent 32 bit zero stores into a 64 bit zero store.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
becomes
str xzr, [x0]
Therefore, four adjacent 32 bit zero stores will be a single stp.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
str wzr, [x0, #8]
str wzr, [x0, #12]
becomes
stp xzr, xzr, [x0]
Reviewers: mcrosier, jmolloy, gberry, t.p.northover
Subscribers: aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D16933
llvm-svn: 260682
2016-02-12 23:25:39 +08:00
|
|
|
bool IsPromotableZeroStore = isPromotableZeroStoreInst(FirstMI);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
Optional<bool> MaybeCanRename = None;
|
2020-01-28 07:11:45 +08:00
|
|
|
if (!EnableRenaming)
|
|
|
|
MaybeCanRename = {false};
|
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
SmallPtrSet<const TargetRegisterClass *, 5> RequiredClasses;
|
|
|
|
LiveRegUnits UsedInBetween;
|
|
|
|
UsedInBetween.init(*TRI);
|
|
|
|
|
|
|
|
Flags.clearRenameReg();
|
|
|
|
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
// Track which register units have been modified and used between the first
|
|
|
|
// insn (inclusive) and the second insn.
|
|
|
|
ModifiedRegUnits.clear();
|
|
|
|
UsedRegUnits.clear();
|
2015-05-22 05:36:46 +08:00
|
|
|
|
|
|
|
// Remember any instructions that read/write memory between FirstMI and MI.
|
|
|
|
SmallVector<MachineInstr *, 4> MemInsns;
|
|
|
|
|
2020-04-18 09:11:46 +08:00
|
|
|
for (unsigned Count = 0; MBBI != E && Count < Limit;
|
|
|
|
MBBI = next_nodbg(MBBI, E)) {
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MI = *MBBI;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
UsedInBetween.accumulate(MI);
|
|
|
|
|
2016-07-21 23:20:25 +08:00
|
|
|
// Don't count transient instructions towards the search limit since there
|
|
|
|
// may be different numbers of them if e.g. debug information is present.
|
|
|
|
if (!MI.isTransient())
|
|
|
|
++Count;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-02-05 00:01:40 +08:00
|
|
|
Flags.setSExtIdx(-1);
|
2016-06-11 04:47:14 +08:00
|
|
|
if (areCandidatesToMergeOrPair(FirstMI, MI, Flags, TII) &&
|
2016-02-11 03:45:48 +08:00
|
|
|
getLdStOffsetOp(MI).isImm()) {
|
2016-07-09 04:29:42 +08:00
|
|
|
assert(MI.mayLoadOrStore() && "Expected memory operation.");
|
2014-03-29 18:18:08 +08:00
|
|
|
// If we've found another instruction with the same opcode, check to see
|
|
|
|
// if the base and offset are compatible with our starting instruction.
|
|
|
|
// These instructions all have scaled immediate operands, so we just
|
|
|
|
// check for +1/-1. Make sure to check the new instruction offset is
|
|
|
|
// actually an immediate and not a symbolic reference destined for
|
|
|
|
// a relocation.
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register MIBaseReg = getLdStBaseOp(MI).getReg();
|
2015-08-06 23:50:12 +08:00
|
|
|
int MIOffset = getLdStOffsetOp(MI).getImm();
|
2016-07-09 04:29:42 +08:00
|
|
|
bool MIIsUnscaled = TII->isUnscaledLdSt(MI);
|
2016-02-11 22:25:08 +08:00
|
|
|
if (IsUnscaled != MIIsUnscaled) {
|
|
|
|
// We're trying to pair instructions that differ in how they are scaled.
|
|
|
|
// If FirstMI is scaled then scale the offset of MI accordingly.
|
|
|
|
// Otherwise, do the opposite (i.e., make MI's offset unscaled).
|
2019-12-11 18:29:23 +08:00
|
|
|
int MemSize = TII->getMemScale(MI);
|
2016-02-11 22:25:08 +08:00
|
|
|
if (MIIsUnscaled) {
|
|
|
|
// If the unscaled offset isn't a multiple of the MemSize, we can't
|
|
|
|
// pair the operations together: bail and keep looking.
|
2016-08-13 04:39:51 +08:00
|
|
|
if (MIOffset % MemSize) {
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits,
|
|
|
|
UsedRegUnits, TRI);
|
2016-08-13 04:39:51 +08:00
|
|
|
MemInsns.push_back(&MI);
|
2016-02-11 22:25:08 +08:00
|
|
|
continue;
|
2016-08-13 04:39:51 +08:00
|
|
|
}
|
2016-02-11 22:25:08 +08:00
|
|
|
MIOffset /= MemSize;
|
|
|
|
} else {
|
|
|
|
MIOffset *= MemSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
if (BaseReg == MIBaseReg && ((Offset == MIOffset + OffsetStride) ||
|
|
|
|
(Offset + OffsetStride == MIOffset))) {
|
|
|
|
int MinOffset = Offset < MIOffset ? Offset : MIOffset;
|
[AArch64] Handle missing store pair opportunity
Summary:
This change will handle missing store pair opportunity where the first store
instruction stores zero followed by the non-zero store. For example, this change
will convert :
str wzr, [x8]
str w1, [x8, #4]
into:
stp wzr, w1, [x8]
Reviewers: jmolloy, t.p.northover, mcrosier
Subscribers: flyingforyou, aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18570
llvm-svn: 265021
2016-03-31 22:47:24 +08:00
|
|
|
if (FindNarrowMerge) {
|
2015-11-21 05:14:07 +08:00
|
|
|
// If the alignment requirements of the scaled wide load/store
|
[AArch64] Handle missing store pair opportunity
Summary:
This change will handle missing store pair opportunity where the first store
instruction stores zero followed by the non-zero store. For example, this change
will convert :
str wzr, [x8]
str w1, [x8, #4]
into:
stp wzr, w1, [x8]
Reviewers: jmolloy, t.p.northover, mcrosier
Subscribers: flyingforyou, aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18570
llvm-svn: 265021
2016-03-31 22:47:24 +08:00
|
|
|
// instruction can't express the offset of the scaled narrow input,
|
|
|
|
// bail and keep looking. For promotable zero stores, allow only when
|
|
|
|
// the stored value is the same (i.e., WZR).
|
|
|
|
if ((!IsUnscaled && alignTo(MinOffset, 2) != MinOffset) ||
|
|
|
|
(IsPromotableZeroStore && Reg != getLdStRegOp(MI).getReg())) {
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits,
|
|
|
|
UsedRegUnits, TRI);
|
2016-07-09 04:29:42 +08:00
|
|
|
MemInsns.push_back(&MI);
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2016-06-11 04:49:18 +08:00
|
|
|
// Pairwise instructions have a 7-bit signed offset field. Single
|
|
|
|
// insns have a 12-bit unsigned offset field. If the resultant
|
|
|
|
// immediate offset of merging these instructions is out of range for
|
|
|
|
// a pairwise instruction, bail and keep looking.
|
[AArch64] Handle missing store pair opportunity
Summary:
This change will handle missing store pair opportunity where the first store
instruction stores zero followed by the non-zero store. For example, this change
will convert :
str wzr, [x8]
str w1, [x8, #4]
into:
stp wzr, w1, [x8]
Reviewers: jmolloy, t.p.northover, mcrosier
Subscribers: flyingforyou, aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18570
llvm-svn: 265021
2016-03-31 22:47:24 +08:00
|
|
|
if (!inBoundsForPair(IsUnscaled, MinOffset, OffsetStride)) {
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits,
|
|
|
|
UsedRegUnits, TRI);
|
2016-07-09 04:29:42 +08:00
|
|
|
MemInsns.push_back(&MI);
|
[AArch64] Handle missing store pair opportunity
Summary:
This change will handle missing store pair opportunity where the first store
instruction stores zero followed by the non-zero store. For example, this change
will convert :
str wzr, [x8]
str w1, [x8, #4]
into:
stp wzr, w1, [x8]
Reviewers: jmolloy, t.p.northover, mcrosier
Subscribers: flyingforyou, aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18570
llvm-svn: 265021
2016-03-31 22:47:24 +08:00
|
|
|
continue;
|
|
|
|
}
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
// If the alignment requirements of the paired (scaled) instruction
|
|
|
|
// can't express the offset of the unscaled input, bail and keep
|
|
|
|
// looking.
|
|
|
|
if (IsUnscaled && (alignTo(MinOffset, OffsetStride) != MinOffset)) {
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits,
|
|
|
|
UsedRegUnits, TRI);
|
2016-07-09 04:29:42 +08:00
|
|
|
MemInsns.push_back(&MI);
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
continue;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
2020-09-23 04:21:27 +08:00
|
|
|
// If the destination register of one load is the same register or a
|
|
|
|
// sub/super register of the other load, bail and keep looking. A
|
|
|
|
// load-pair instruction with both destination registers the same is
|
|
|
|
// UNPREDICTABLE and will result in an exception.
|
|
|
|
if (MayLoad &&
|
|
|
|
TRI->isSuperOrSubRegisterEq(Reg, getLdStRegOp(MI).getReg())) {
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits,
|
|
|
|
TRI);
|
2016-07-09 04:29:42 +08:00
|
|
|
MemInsns.push_back(&MI);
|
2014-03-29 18:18:08 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-01 01:03:14 +08:00
|
|
|
// If the BaseReg has been modified, then we cannot do the optimization.
|
|
|
|
// For example, in the following pattern
|
|
|
|
// ldr x1 [x2]
|
|
|
|
// ldr x2 [x3]
|
|
|
|
// ldr x4 [x2, #8],
|
|
|
|
// the first and third ldr cannot be converted to ldp x1, x4, [x2]
|
|
|
|
if (!ModifiedRegUnits.available(BaseReg))
|
|
|
|
return E;
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// If the Rt of the second instruction was not modified or used between
|
2015-05-22 05:36:46 +08:00
|
|
|
// the two instructions and none of the instructions between the second
|
|
|
|
// and first alias with the second, we can combine the second into the
|
|
|
|
// first.
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
if (ModifiedRegUnits.available(getLdStRegOp(MI).getReg()) &&
|
|
|
|
!(MI.mayLoad() &&
|
|
|
|
!UsedRegUnits.available(getLdStRegOp(MI).getReg())) &&
|
2017-03-17 22:19:55 +08:00
|
|
|
!mayAlias(MI, MemInsns, AA)) {
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
|
2015-07-22 01:42:04 +08:00
|
|
|
Flags.setMergeForward(false);
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
Flags.clearRenameReg();
|
2014-03-29 18:18:08 +08:00
|
|
|
return MBBI;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Likewise, if the Rt of the first instruction is not modified or used
|
2015-05-22 05:36:46 +08:00
|
|
|
// between the two instructions and none of the instructions between the
|
|
|
|
// first and the second alias with the first, we can combine the first
|
|
|
|
// into the second.
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
if (!(MayLoad &&
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
!UsedRegUnits.available(getLdStRegOp(FirstMI).getReg())) &&
|
2017-03-17 22:19:55 +08:00
|
|
|
!mayAlias(FirstMI, MemInsns, AA)) {
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
|
|
|
|
if (ModifiedRegUnits.available(getLdStRegOp(FirstMI).getReg())) {
|
|
|
|
Flags.setMergeForward(true);
|
|
|
|
Flags.clearRenameReg();
|
|
|
|
return MBBI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DebugCounter::shouldExecute(RegRenamingCounter)) {
|
|
|
|
if (!MaybeCanRename)
|
|
|
|
MaybeCanRename = {canRenameUpToDef(FirstMI, UsedInBetween,
|
|
|
|
RequiredClasses, TRI)};
|
|
|
|
|
|
|
|
if (*MaybeCanRename) {
|
|
|
|
Optional<MCPhysReg> MaybeRenameReg = tryToFindRegisterToRename(
|
|
|
|
FirstMI, MI, DefinedInBB, UsedInBetween, RequiredClasses,
|
|
|
|
TRI);
|
|
|
|
if (MaybeRenameReg) {
|
|
|
|
Flags.setRenameReg(*MaybeRenameReg);
|
|
|
|
Flags.setMergeForward(true);
|
|
|
|
MBBIWithRenameReg = MBBI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
// Unable to combine these instructions due to interference in between.
|
|
|
|
// Keep looking.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
if (Flags.getRenameReg())
|
|
|
|
return MBBIWithRenameReg;
|
|
|
|
|
2015-05-22 05:36:46 +08:00
|
|
|
// If the instruction wasn't a matching load or store. Stop searching if we
|
|
|
|
// encounter a call instruction that might modify memory.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (MI.isCall())
|
2014-03-29 18:18:08 +08:00
|
|
|
return E;
|
|
|
|
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
// Update modified / uses register units.
|
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits, TRI);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Otherwise, if the base register is modified, we have no match, so
|
|
|
|
// return early.
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
if (!ModifiedRegUnits.available(BaseReg))
|
2014-03-29 18:18:08 +08:00
|
|
|
return E;
|
2015-05-22 05:36:46 +08:00
|
|
|
|
|
|
|
// Update list of instructions that read/write memory.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (MI.mayLoadOrStore())
|
|
|
|
MemInsns.push_back(&MI);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
return E;
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineBasicBlock::iterator
|
2015-09-23 21:51:44 +08:00
|
|
|
AArch64LoadStoreOpt::mergeUpdateInsn(MachineBasicBlock::iterator I,
|
|
|
|
MachineBasicBlock::iterator Update,
|
|
|
|
bool IsPreIdx) {
|
2014-05-24 20:50:23 +08:00
|
|
|
assert((Update->getOpcode() == AArch64::ADDXri ||
|
|
|
|
Update->getOpcode() == AArch64::SUBXri) &&
|
2014-03-29 18:18:08 +08:00
|
|
|
"Unexpected base register update instruction to merge!");
|
2020-04-18 09:11:46 +08:00
|
|
|
MachineBasicBlock::iterator E = I->getParent()->end();
|
|
|
|
MachineBasicBlock::iterator NextI = next_nodbg(I, E);
|
2014-03-29 18:18:08 +08:00
|
|
|
// Return the instruction following the merged instruction, which is
|
|
|
|
// the instruction following our unmerged load. Unless that's the add/sub
|
|
|
|
// instruction we're merging, in which case it's the one after that.
|
2020-04-18 09:11:46 +08:00
|
|
|
if (NextI == Update)
|
|
|
|
NextI = next_nodbg(NextI, E);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
int Value = Update->getOperand(2).getImm();
|
2014-05-24 20:50:23 +08:00
|
|
|
assert(AArch64_AM::getShiftValue(Update->getOperand(3).getImm()) == 0 &&
|
2015-09-23 21:51:44 +08:00
|
|
|
"Can't merge 1 << 12 offset into pre-/post-indexed load / store");
|
2014-05-24 20:50:23 +08:00
|
|
|
if (Update->getOpcode() == AArch64::SUBXri)
|
2014-03-29 18:18:08 +08:00
|
|
|
Value = -Value;
|
|
|
|
|
2015-09-23 21:51:44 +08:00
|
|
|
unsigned NewOpc = IsPreIdx ? getPreIndexedOpcode(I->getOpcode())
|
|
|
|
: getPostIndexedOpcode(I->getOpcode());
|
2015-09-26 01:48:17 +08:00
|
|
|
MachineInstrBuilder MIB;
|
2019-09-21 01:36:27 +08:00
|
|
|
int Scale, MinOffset, MaxOffset;
|
|
|
|
getPrePostIndexedMemOpInfo(*I, Scale, MinOffset, MaxOffset);
|
2016-07-09 04:29:42 +08:00
|
|
|
if (!isPairedLdSt(*I)) {
|
2015-09-26 01:48:17 +08:00
|
|
|
// Non-paired instruction.
|
|
|
|
MIB = BuildMI(*I->getParent(), I, I->getDebugLoc(), TII->get(NewOpc))
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(getLdStRegOp(*Update))
|
|
|
|
.add(getLdStRegOp(*I))
|
|
|
|
.add(getLdStBaseOp(*I))
|
2019-09-21 01:36:27 +08:00
|
|
|
.addImm(Value / Scale)
|
2018-08-17 05:30:05 +08:00
|
|
|
.setMemRefs(I->memoperands())
|
2018-03-15 01:10:58 +08:00
|
|
|
.setMIFlags(I->mergeFlagsWith(*Update));
|
2015-09-26 01:48:17 +08:00
|
|
|
} else {
|
|
|
|
// Paired instruction.
|
|
|
|
MIB = BuildMI(*I->getParent(), I, I->getDebugLoc(), TII->get(NewOpc))
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(getLdStRegOp(*Update))
|
|
|
|
.add(getLdStRegOp(*I, 0))
|
|
|
|
.add(getLdStRegOp(*I, 1))
|
|
|
|
.add(getLdStBaseOp(*I))
|
2016-01-28 23:38:24 +08:00
|
|
|
.addImm(Value / Scale)
|
2018-08-17 05:30:05 +08:00
|
|
|
.setMemRefs(I->memoperands())
|
2018-03-15 01:10:58 +08:00
|
|
|
.setMIFlags(I->mergeFlagsWith(*Update));
|
2015-09-26 01:48:17 +08:00
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
(void)MIB;
|
|
|
|
|
2017-11-16 05:06:22 +08:00
|
|
|
if (IsPreIdx) {
|
|
|
|
++NumPreFolded;
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Creating pre-indexed load/store.");
|
2017-11-16 05:06:22 +08:00
|
|
|
} else {
|
|
|
|
++NumPostFolded;
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Creating post-indexed load/store.");
|
2017-11-16 05:06:22 +08:00
|
|
|
}
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << " Replacing instructions:\n ");
|
|
|
|
LLVM_DEBUG(I->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " ");
|
|
|
|
LLVM_DEBUG(Update->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << " with instruction:\n ");
|
|
|
|
LLVM_DEBUG(((MachineInstr *)MIB)->print(dbgs()));
|
|
|
|
LLVM_DEBUG(dbgs() << "\n");
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Erase the old instructions for the block.
|
|
|
|
I->eraseFromParent();
|
|
|
|
Update->eraseFromParent();
|
|
|
|
|
|
|
|
return NextI;
|
|
|
|
}
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
bool AArch64LoadStoreOpt::isMatchingUpdateInsn(MachineInstr &MemMI,
|
|
|
|
MachineInstr &MI,
|
2015-09-26 01:48:17 +08:00
|
|
|
unsigned BaseReg, int Offset) {
|
2016-07-09 04:29:42 +08:00
|
|
|
switch (MI.getOpcode()) {
|
2014-03-29 18:18:08 +08:00
|
|
|
default:
|
|
|
|
break;
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::SUBXri:
|
|
|
|
case AArch64::ADDXri:
|
2014-03-29 18:18:08 +08:00
|
|
|
// Make sure it's a vanilla immediate operand, not a relocation or
|
|
|
|
// anything else we can't handle.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (!MI.getOperand(2).isImm())
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
|
|
|
// Watch out for 1 << 12 shifted value.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (AArch64_AM::getShiftValue(MI.getOperand(3).getImm()))
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
2015-09-26 01:48:17 +08:00
|
|
|
|
|
|
|
// The update instruction source and destination register must be the
|
|
|
|
// same as the load/store base register.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (MI.getOperand(0).getReg() != BaseReg ||
|
|
|
|
MI.getOperand(1).getReg() != BaseReg)
|
2015-09-26 01:48:17 +08:00
|
|
|
break;
|
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
int UpdateOffset = MI.getOperand(2).getImm();
|
2016-08-13 04:28:02 +08:00
|
|
|
if (MI.getOpcode() == AArch64::SUBXri)
|
|
|
|
UpdateOffset = -UpdateOffset;
|
|
|
|
|
2019-09-21 01:36:27 +08:00
|
|
|
// The immediate must be a multiple of the scaling factor of the pre/post
|
|
|
|
// indexed instruction.
|
|
|
|
int Scale, MinOffset, MaxOffset;
|
|
|
|
getPrePostIndexedMemOpInfo(MemMI, Scale, MinOffset, MaxOffset);
|
|
|
|
if (UpdateOffset % Scale != 0)
|
2015-09-26 01:48:17 +08:00
|
|
|
break;
|
|
|
|
|
2019-09-21 01:36:27 +08:00
|
|
|
// Scaled offset must fit in the instruction immediate.
|
|
|
|
int ScaledOffset = UpdateOffset / Scale;
|
|
|
|
if (ScaledOffset > MaxOffset || ScaledOffset < MinOffset)
|
|
|
|
break;
|
2015-09-26 01:48:17 +08:00
|
|
|
|
|
|
|
// If we have a non-zero Offset, we check that it matches the amount
|
|
|
|
// we're adding to the register.
|
2016-08-13 04:28:02 +08:00
|
|
|
if (!Offset || Offset == UpdateOffset)
|
2015-09-26 01:48:17 +08:00
|
|
|
return true;
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:09:22 +08:00
|
|
|
static bool needsWinCFI(const MachineFunction *MF) {
|
|
|
|
return MF->getTarget().getMCAsmInfo()->usesWindowsCFI() &&
|
|
|
|
MF->getFunction().needsUnwindTableEntry();
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
MachineBasicBlock::iterator AArch64LoadStoreOpt::findMatchingUpdateInsnForward(
|
2016-02-05 05:26:02 +08:00
|
|
|
MachineBasicBlock::iterator I, int UnscaledOffset, unsigned Limit) {
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock::iterator E = I->getParent()->end();
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MemMI = *I;
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock::iterator MBBI = I;
|
|
|
|
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register BaseReg = getLdStBaseOp(MemMI).getReg();
|
2019-12-11 18:29:23 +08:00
|
|
|
int MIUnscaledOffset = getLdStOffsetOp(MemMI).getImm() * TII->getMemScale(MemMI);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-10-01 21:43:05 +08:00
|
|
|
// Scan forward looking for post-index opportunities. Updating instructions
|
|
|
|
// can't be formed if the memory instruction doesn't have the offset we're
|
|
|
|
// looking for.
|
|
|
|
if (MIUnscaledOffset != UnscaledOffset)
|
|
|
|
return E;
|
|
|
|
|
2019-09-21 01:36:27 +08:00
|
|
|
// If the base register overlaps a source/destination register, we can't
|
|
|
|
// merge the update. This does not apply to tag store instructions which
|
|
|
|
// ignore the address part of the source register.
|
|
|
|
// This does not apply to STGPi as well, which does not have unpredictable
|
|
|
|
// behavior in this case unlike normal stores, and always performs writeback
|
|
|
|
// after reading the source register value.
|
|
|
|
if (!isTagStore(MemMI) && MemMI.getOpcode() != AArch64::STGPi) {
|
|
|
|
bool IsPairedInsn = isPairedLdSt(MemMI);
|
|
|
|
for (unsigned i = 0, e = IsPairedInsn ? 2 : 1; i != e; ++i) {
|
|
|
|
Register DestReg = getLdStRegOp(MemMI, i).getReg();
|
|
|
|
if (DestReg == BaseReg || TRI->isSubRegister(BaseReg, DestReg))
|
|
|
|
return E;
|
|
|
|
}
|
2015-09-26 01:48:17 +08:00
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
// Track which register units have been modified and used between the first
|
|
|
|
// insn (inclusive) and the second insn.
|
|
|
|
ModifiedRegUnits.clear();
|
|
|
|
UsedRegUnits.clear();
|
2020-04-18 09:11:46 +08:00
|
|
|
MBBI = next_nodbg(MBBI, E);
|
[AArch64][Fix] LdSt optimization generate premature stack-popping
Summary:
When moving add and sub to memory operand instructions,
aarch64-ldst-opt would prematurally pop the stack pointer,
before memory instructions that do access the stack using
indirect loads.
e.g.
```
int foo(int offset){
int local[4] = {0};
return local[offset];
}
```
would generate:
```
sub sp, sp, #16 ; Push the stack
mov x8, sp ; Save stack in register
stp xzr, xzr, [sp], #16 ; Zero initialize stack, and post-increment, making it invalid
------ If an exception goes here, the stack value might be corrupted
ldr w0, [x8, w0, sxtw #2] ; Access correct position, but it is not guarded by SP
```
Reviewers: fhahn, foad, thegameg, eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, kristof.beyls, hiraditya, danielkiss, llvm-commits, simon_tatham
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75755
2020-03-14 01:32:31 +08:00
|
|
|
|
|
|
|
// We can't post-increment the stack pointer if any instruction between
|
|
|
|
// the memory access (I) and the increment (MBBI) can access the memory
|
|
|
|
// region defined by [SP, MBBI].
|
|
|
|
const bool BaseRegSP = BaseReg == AArch64::SP;
|
2020-09-29 15:09:22 +08:00
|
|
|
if (BaseRegSP && needsWinCFI(I->getMF())) {
|
[AArch64][Fix] LdSt optimization generate premature stack-popping
Summary:
When moving add and sub to memory operand instructions,
aarch64-ldst-opt would prematurally pop the stack pointer,
before memory instructions that do access the stack using
indirect loads.
e.g.
```
int foo(int offset){
int local[4] = {0};
return local[offset];
}
```
would generate:
```
sub sp, sp, #16 ; Push the stack
mov x8, sp ; Save stack in register
stp xzr, xzr, [sp], #16 ; Zero initialize stack, and post-increment, making it invalid
------ If an exception goes here, the stack value might be corrupted
ldr w0, [x8, w0, sxtw #2] ; Access correct position, but it is not guarded by SP
```
Reviewers: fhahn, foad, thegameg, eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, kristof.beyls, hiraditya, danielkiss, llvm-commits, simon_tatham
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75755
2020-03-14 01:32:31 +08:00
|
|
|
// FIXME: For now, we always block the optimization over SP in windows
|
|
|
|
// targets as it requires to adjust the unwind/debug info, messing up
|
|
|
|
// the unwind info can actually cause a miscompile.
|
2020-09-29 15:09:22 +08:00
|
|
|
return E;
|
[AArch64][Fix] LdSt optimization generate premature stack-popping
Summary:
When moving add and sub to memory operand instructions,
aarch64-ldst-opt would prematurally pop the stack pointer,
before memory instructions that do access the stack using
indirect loads.
e.g.
```
int foo(int offset){
int local[4] = {0};
return local[offset];
}
```
would generate:
```
sub sp, sp, #16 ; Push the stack
mov x8, sp ; Save stack in register
stp xzr, xzr, [sp], #16 ; Zero initialize stack, and post-increment, making it invalid
------ If an exception goes here, the stack value might be corrupted
ldr w0, [x8, w0, sxtw #2] ; Access correct position, but it is not guarded by SP
```
Reviewers: fhahn, foad, thegameg, eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, kristof.beyls, hiraditya, danielkiss, llvm-commits, simon_tatham
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75755
2020-03-14 01:32:31 +08:00
|
|
|
}
|
|
|
|
|
2020-04-18 09:11:46 +08:00
|
|
|
for (unsigned Count = 0; MBBI != E && Count < Limit;
|
|
|
|
MBBI = next_nodbg(MBBI, E)) {
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MI = *MBBI;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-07-21 23:20:25 +08:00
|
|
|
// Don't count transient instructions towards the search limit since there
|
|
|
|
// may be different numbers of them if e.g. debug information is present.
|
|
|
|
if (!MI.isTransient())
|
|
|
|
++Count;
|
2016-02-05 05:26:02 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// If we found a match, return it.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (isMatchingUpdateInsn(*I, MI, BaseReg, UnscaledOffset))
|
2014-03-29 18:18:08 +08:00
|
|
|
return MBBI;
|
|
|
|
|
|
|
|
// Update the status of what the instruction clobbered and used.
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits, TRI);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Otherwise, if the base register is used or modified, we have no match, so
|
|
|
|
// return early.
|
[AArch64][Fix] LdSt optimization generate premature stack-popping
Summary:
When moving add and sub to memory operand instructions,
aarch64-ldst-opt would prematurally pop the stack pointer,
before memory instructions that do access the stack using
indirect loads.
e.g.
```
int foo(int offset){
int local[4] = {0};
return local[offset];
}
```
would generate:
```
sub sp, sp, #16 ; Push the stack
mov x8, sp ; Save stack in register
stp xzr, xzr, [sp], #16 ; Zero initialize stack, and post-increment, making it invalid
------ If an exception goes here, the stack value might be corrupted
ldr w0, [x8, w0, sxtw #2] ; Access correct position, but it is not guarded by SP
```
Reviewers: fhahn, foad, thegameg, eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, kristof.beyls, hiraditya, danielkiss, llvm-commits, simon_tatham
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75755
2020-03-14 01:32:31 +08:00
|
|
|
// If we are optimizing SP, do not allow instructions that may load or store
|
|
|
|
// in between the load and the optimized value update.
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
if (!ModifiedRegUnits.available(BaseReg) ||
|
[AArch64][Fix] LdSt optimization generate premature stack-popping
Summary:
When moving add and sub to memory operand instructions,
aarch64-ldst-opt would prematurally pop the stack pointer,
before memory instructions that do access the stack using
indirect loads.
e.g.
```
int foo(int offset){
int local[4] = {0};
return local[offset];
}
```
would generate:
```
sub sp, sp, #16 ; Push the stack
mov x8, sp ; Save stack in register
stp xzr, xzr, [sp], #16 ; Zero initialize stack, and post-increment, making it invalid
------ If an exception goes here, the stack value might be corrupted
ldr w0, [x8, w0, sxtw #2] ; Access correct position, but it is not guarded by SP
```
Reviewers: fhahn, foad, thegameg, eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, kristof.beyls, hiraditya, danielkiss, llvm-commits, simon_tatham
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75755
2020-03-14 01:32:31 +08:00
|
|
|
!UsedRegUnits.available(BaseReg) ||
|
|
|
|
(BaseRegSP && MBBI->mayLoadOrStore()))
|
2014-03-29 18:18:08 +08:00
|
|
|
return E;
|
|
|
|
}
|
|
|
|
return E;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
MachineBasicBlock::iterator AArch64LoadStoreOpt::findMatchingUpdateInsnBackward(
|
2016-02-05 05:26:02 +08:00
|
|
|
MachineBasicBlock::iterator I, unsigned Limit) {
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock::iterator B = I->getParent()->begin();
|
|
|
|
MachineBasicBlock::iterator E = I->getParent()->end();
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MemMI = *I;
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock::iterator MBBI = I;
|
|
|
|
|
[aarch64] 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).
Manual fixups in:
AArch64InstrInfo.cpp - genFusedMultiply() now takes a Register* instead of unsigned*
AArch64LoadStoreOptimizer.cpp - Ternary operator was ambiguous between Register/MCRegister. Settled on Register
Depends on D65919
Reviewers: aemerson
Subscribers: 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 for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368628
2019-08-13 06:40:53 +08:00
|
|
|
Register BaseReg = getLdStBaseOp(MemMI).getReg();
|
2015-08-06 23:50:12 +08:00
|
|
|
int Offset = getLdStOffsetOp(MemMI).getImm();
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// If the load/store is the first instruction in the block, there's obviously
|
|
|
|
// not any matching update. Ditto if the memory offset isn't zero.
|
|
|
|
if (MBBI == B || Offset != 0)
|
|
|
|
return E;
|
2015-09-26 01:48:17 +08:00
|
|
|
// If the base register overlaps a destination register, we can't
|
2014-03-29 18:18:08 +08:00
|
|
|
// merge the update.
|
2019-09-21 01:36:27 +08:00
|
|
|
if (!isTagStore(MemMI)) {
|
|
|
|
bool IsPairedInsn = isPairedLdSt(MemMI);
|
|
|
|
for (unsigned i = 0, e = IsPairedInsn ? 2 : 1; i != e; ++i) {
|
|
|
|
Register DestReg = getLdStRegOp(MemMI, i).getReg();
|
|
|
|
if (DestReg == BaseReg || TRI->isSubRegister(BaseReg, DestReg))
|
|
|
|
return E;
|
|
|
|
}
|
2015-09-26 01:48:17 +08:00
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2020-09-29 15:09:22 +08:00
|
|
|
const bool BaseRegSP = BaseReg == AArch64::SP;
|
|
|
|
if (BaseRegSP && needsWinCFI(I->getMF())) {
|
|
|
|
// FIXME: For now, we always block the optimization over SP in windows
|
|
|
|
// targets as it requires to adjust the unwind/debug info, messing up
|
|
|
|
// the unwind info can actually cause a miscompile.
|
|
|
|
return E;
|
|
|
|
}
|
|
|
|
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
// Track which register units have been modified and used between the first
|
|
|
|
// insn (inclusive) and the second insn.
|
|
|
|
ModifiedRegUnits.clear();
|
|
|
|
UsedRegUnits.clear();
|
2016-02-10 04:47:21 +08:00
|
|
|
unsigned Count = 0;
|
|
|
|
do {
|
2020-04-18 09:11:46 +08:00
|
|
|
MBBI = prev_nodbg(MBBI, B);
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MI = *MBBI;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-07-21 23:20:25 +08:00
|
|
|
// Don't count transient instructions towards the search limit since there
|
|
|
|
// may be different numbers of them if e.g. debug information is present.
|
|
|
|
if (!MI.isTransient())
|
2016-02-10 04:47:21 +08:00
|
|
|
++Count;
|
2016-02-05 05:26:02 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// If we found a match, return it.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (isMatchingUpdateInsn(*I, MI, BaseReg, Offset))
|
2014-03-29 18:18:08 +08:00
|
|
|
return MBBI;
|
|
|
|
|
|
|
|
// Update the status of what the instruction clobbered and used.
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits, TRI);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Otherwise, if the base register is used or modified, we have no match, so
|
|
|
|
// return early.
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
if (!ModifiedRegUnits.available(BaseReg) ||
|
|
|
|
!UsedRegUnits.available(BaseReg))
|
2014-03-29 18:18:08 +08:00
|
|
|
return E;
|
2016-02-10 04:47:21 +08:00
|
|
|
} while (MBBI != B && Count < Limit);
|
2014-03-29 18:18:08 +08:00
|
|
|
return E;
|
|
|
|
}
|
|
|
|
|
2015-12-23 00:36:16 +08:00
|
|
|
bool AArch64LoadStoreOpt::tryToPromoteLoadFromStore(
|
|
|
|
MachineBasicBlock::iterator &MBBI) {
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MI = *MBBI;
|
2015-12-23 00:36:16 +08:00
|
|
|
// If this is a volatile load, don't mess with it.
|
2016-07-09 04:29:42 +08:00
|
|
|
if (MI.hasOrderedMemoryRef())
|
2015-12-23 00:36:16 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Make sure this is a reg+imm.
|
|
|
|
// FIXME: It is possible to extend it to handle reg+reg cases.
|
|
|
|
if (!getLdStOffsetOp(MI).isImm())
|
|
|
|
return false;
|
|
|
|
|
2016-02-05 05:26:02 +08:00
|
|
|
// Look backward up to LdStLimit instructions.
|
2015-12-23 00:36:16 +08:00
|
|
|
MachineBasicBlock::iterator StoreI;
|
2016-02-05 05:26:02 +08:00
|
|
|
if (findMatchingStore(MBBI, LdStLimit, StoreI)) {
|
2015-12-23 00:36:16 +08:00
|
|
|
++NumLoadsFromStoresPromoted;
|
|
|
|
// Promote the load. Keeping the iterator straight is a
|
|
|
|
// pain, so we let the merge routine tell us what the next instruction
|
|
|
|
// is after it's done mucking about.
|
|
|
|
MBBI = promoteLoadFromStore(MBBI, StoreI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-07 23:27:22 +08:00
|
|
|
// Merge adjacent zero stores into a wider store.
|
|
|
|
bool AArch64LoadStoreOpt::tryToMergeZeroStInst(
|
2016-02-10 02:10:20 +08:00
|
|
|
MachineBasicBlock::iterator &MBBI) {
|
2016-11-07 23:27:22 +08:00
|
|
|
assert(isPromotableZeroStoreInst(*MBBI) && "Expected narrow store.");
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MI = *MBBI;
|
|
|
|
MachineBasicBlock::iterator E = MI.getParent()->end();
|
2016-02-10 02:10:20 +08:00
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
if (!TII->isCandidateToMergeOrPair(MI))
|
2016-02-10 02:10:20 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Look ahead up to LdStLimit instructions for a mergable instruction.
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
LdStPairFlags Flags;
|
[AArch64] Merge two adjacent str WZR into str XZR
Summary:
This change merges adjacent 32 bit zero stores into a 64 bit zero store.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
becomes
str xzr, [x0]
Therefore, four adjacent 32 bit zero stores will be a single stp.
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
str wzr, [x0, #8]
str wzr, [x0, #12]
becomes
stp xzr, xzr, [x0]
Reviewers: mcrosier, jmolloy, gberry, t.p.northover
Subscribers: aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D16933
llvm-svn: 260682
2016-02-12 23:25:39 +08:00
|
|
|
MachineBasicBlock::iterator MergeMI =
|
[AArch64] Handle missing store pair opportunity
Summary:
This change will handle missing store pair opportunity where the first store
instruction stores zero followed by the non-zero store. For example, this change
will convert :
str wzr, [x8]
str w1, [x8, #4]
into:
stp wzr, w1, [x8]
Reviewers: jmolloy, t.p.northover, mcrosier
Subscribers: flyingforyou, aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18570
llvm-svn: 265021
2016-03-31 22:47:24 +08:00
|
|
|
findMatchingInsn(MBBI, Flags, LdStLimit, /* FindNarrowMerge = */ true);
|
2016-02-10 03:09:22 +08:00
|
|
|
if (MergeMI != E) {
|
2016-11-07 23:27:22 +08:00
|
|
|
++NumZeroStoresPromoted;
|
|
|
|
|
2016-02-10 02:10:20 +08:00
|
|
|
// Keeping the iterator straight is a pain, so we let the merge routine tell
|
|
|
|
// us what the next instruction is after it's done mucking about.
|
2016-11-07 23:27:22 +08:00
|
|
|
MBBI = mergeNarrowZeroStores(MBBI, MergeMI, Flags);
|
2016-02-10 02:10:20 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
|
2016-02-10 02:10:20 +08:00
|
|
|
// Find loads and stores that can be merged into a single load or store pair
|
|
|
|
// instruction.
|
|
|
|
bool AArch64LoadStoreOpt::tryToPairLdStInst(MachineBasicBlock::iterator &MBBI) {
|
2016-07-09 04:29:42 +08:00
|
|
|
MachineInstr &MI = *MBBI;
|
|
|
|
MachineBasicBlock::iterator E = MI.getParent()->end();
|
2016-02-10 02:10:20 +08:00
|
|
|
|
2016-07-09 04:29:42 +08:00
|
|
|
if (!TII->isCandidateToMergeOrPair(MI))
|
2016-02-10 02:10:20 +08:00
|
|
|
return false;
|
|
|
|
|
2016-02-10 23:52:46 +08:00
|
|
|
// Early exit if the offset is not possible to match. (6 bits of positive
|
|
|
|
// range, plus allow an extra one in case we find a later insn that matches
|
|
|
|
// with Offset-1)
|
2016-07-09 04:29:42 +08:00
|
|
|
bool IsUnscaled = TII->isUnscaledLdSt(MI);
|
2016-02-10 23:52:46 +08:00
|
|
|
int Offset = getLdStOffsetOp(MI).getImm();
|
2019-12-11 18:29:23 +08:00
|
|
|
int OffsetStride = IsUnscaled ? TII->getMemScale(MI) : 1;
|
2017-01-05 05:21:46 +08:00
|
|
|
// Allow one more for offset.
|
|
|
|
if (Offset > 0)
|
|
|
|
Offset -= OffsetStride;
|
2016-02-10 23:52:46 +08:00
|
|
|
if (!inBoundsForPair(IsUnscaled, Offset, OffsetStride))
|
|
|
|
return false;
|
|
|
|
|
2016-02-10 02:10:20 +08:00
|
|
|
// Look ahead up to LdStLimit instructions for a pairable instruction.
|
|
|
|
LdStPairFlags Flags;
|
[AArch64] Handle missing store pair opportunity
Summary:
This change will handle missing store pair opportunity where the first store
instruction stores zero followed by the non-zero store. For example, this change
will convert :
str wzr, [x8]
str w1, [x8, #4]
into:
stp wzr, w1, [x8]
Reviewers: jmolloy, t.p.northover, mcrosier
Subscribers: flyingforyou, aemerson, rengolin, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D18570
llvm-svn: 265021
2016-03-31 22:47:24 +08:00
|
|
|
MachineBasicBlock::iterator Paired =
|
|
|
|
findMatchingInsn(MBBI, Flags, LdStLimit, /* FindNarrowMerge = */ false);
|
2016-02-10 02:10:20 +08:00
|
|
|
if (Paired != E) {
|
|
|
|
++NumPairCreated;
|
2016-07-09 04:29:42 +08:00
|
|
|
if (TII->isUnscaledLdSt(MI))
|
2016-02-10 02:10:20 +08:00
|
|
|
++NumUnscaledPairCreated;
|
|
|
|
// Keeping the iterator straight is a pain, so we let the merge routine tell
|
|
|
|
// us what the next instruction is after it's done mucking about.
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
auto Prev = std::prev(MBBI);
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
MBBI = mergePairedInsns(MBBI, Paired, Flags);
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
// Collect liveness info for instructions between Prev and the new position
|
|
|
|
// MBBI.
|
|
|
|
for (auto I = std::next(Prev); I != MBBI; I++)
|
|
|
|
updateDefinedRegisters(*I, DefinedInBB, TRI);
|
|
|
|
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-16 05:06:22 +08:00
|
|
|
bool AArch64LoadStoreOpt::tryToMergeLdStUpdate
|
|
|
|
(MachineBasicBlock::iterator &MBBI) {
|
|
|
|
MachineInstr &MI = *MBBI;
|
|
|
|
MachineBasicBlock::iterator E = MI.getParent()->end();
|
|
|
|
MachineBasicBlock::iterator Update;
|
|
|
|
|
|
|
|
// Look forward to try to form a post-index instruction. For example,
|
|
|
|
// ldr x0, [x20]
|
|
|
|
// add x20, x20, #32
|
|
|
|
// merged into:
|
|
|
|
// ldr x0, [x20], #32
|
|
|
|
Update = findMatchingUpdateInsnForward(MBBI, 0, UpdateLimit);
|
|
|
|
if (Update != E) {
|
|
|
|
// Merge the update into the ld/st.
|
|
|
|
MBBI = mergeUpdateInsn(MBBI, Update, /*IsPreIdx=*/false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't know how to handle unscaled pre/post-index versions below, so bail.
|
|
|
|
if (TII->isUnscaledLdSt(MI.getOpcode()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Look back to try to find a pre-index instruction. For example,
|
|
|
|
// add x0, x0, #8
|
|
|
|
// ldr x1, [x0]
|
|
|
|
// merged into:
|
|
|
|
// ldr x1, [x0, #8]!
|
|
|
|
Update = findMatchingUpdateInsnBackward(MBBI, UpdateLimit);
|
|
|
|
if (Update != E) {
|
|
|
|
// Merge the update into the ld/st.
|
|
|
|
MBBI = mergeUpdateInsn(MBBI, Update, /*IsPreIdx=*/true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The immediate in the load/store is scaled by the size of the memory
|
|
|
|
// operation. The immediate in the add we're looking for,
|
|
|
|
// however, is not, so adjust here.
|
2019-12-11 18:29:23 +08:00
|
|
|
int UnscaledOffset = getLdStOffsetOp(MI).getImm() * TII->getMemScale(MI);
|
2017-11-16 05:06:22 +08:00
|
|
|
|
2019-09-21 01:36:27 +08:00
|
|
|
// Look forward to try to find a pre-index instruction. For example,
|
2017-11-16 05:06:22 +08:00
|
|
|
// ldr x1, [x0, #64]
|
|
|
|
// add x0, x0, #64
|
|
|
|
// merged into:
|
|
|
|
// ldr x1, [x0, #64]!
|
|
|
|
Update = findMatchingUpdateInsnForward(MBBI, UnscaledOffset, UpdateLimit);
|
|
|
|
if (Update != E) {
|
|
|
|
// Merge the update into the ld/st.
|
|
|
|
MBBI = mergeUpdateInsn(MBBI, Update, /*IsPreIdx=*/true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-07 00:27:47 +08:00
|
|
|
bool AArch64LoadStoreOpt::optimizeBlock(MachineBasicBlock &MBB,
|
2016-11-07 23:27:22 +08:00
|
|
|
bool EnableNarrowZeroStOpt) {
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool Modified = false;
|
2016-02-02 05:38:31 +08:00
|
|
|
// Four tranformations to do here:
|
2015-12-23 00:36:16 +08:00
|
|
|
// 1) Find loads that directly read from stores and promote them by
|
|
|
|
// replacing with mov instructions. If the store is wider than the load,
|
|
|
|
// the load will be replaced with a bitfield extract.
|
|
|
|
// e.g.,
|
|
|
|
// str w1, [x0, #4]
|
|
|
|
// ldrh w2, [x0, #6]
|
|
|
|
// ; becomes
|
|
|
|
// str w1, [x0, #4]
|
2016-06-20 08:37:41 +08:00
|
|
|
// lsr w2, w1, #16
|
2015-12-23 00:36:16 +08:00
|
|
|
for (MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
|
|
|
|
MBBI != E;) {
|
2017-11-16 05:06:22 +08:00
|
|
|
if (isPromotableLoadFromStore(*MBBI) && tryToPromoteLoadFromStore(MBBI))
|
|
|
|
Modified = true;
|
|
|
|
else
|
2015-12-23 00:36:16 +08:00
|
|
|
++MBBI;
|
|
|
|
}
|
2016-11-07 23:27:22 +08:00
|
|
|
// 2) Merge adjacent zero stores into a wider store.
|
2016-02-06 04:02:03 +08:00
|
|
|
// e.g.,
|
|
|
|
// strh wzr, [x0]
|
|
|
|
// strh wzr, [x0, #2]
|
|
|
|
// ; becomes
|
|
|
|
// str wzr, [x0]
|
2016-11-07 23:27:22 +08:00
|
|
|
// e.g.,
|
|
|
|
// str wzr, [x0]
|
|
|
|
// str wzr, [x0, #4]
|
|
|
|
// ; becomes
|
|
|
|
// str xzr, [x0]
|
2017-11-16 05:06:22 +08:00
|
|
|
if (EnableNarrowZeroStOpt)
|
|
|
|
for (MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
|
|
|
|
MBBI != E;) {
|
|
|
|
if (isPromotableZeroStoreInst(*MBBI) && tryToMergeZeroStInst(MBBI))
|
[AArch64]Merge halfword loads into a 32-bit load
This recommits r250719, which caused a failure in SPEC2000.gcc
because of the incorrect insert point for the new wider load.
Convert two halfword loads into a single 32-bit word load with bitfield extract
instructions. For example :
ldrh w0, [x2]
ldrh w1, [x2, #2]
becomes
ldr w0, [x2]
ubfx w1, w0, #16, #16
and w0, w0, #ffff
llvm-svn: 251438
2015-10-28 03:16:03 +08:00
|
|
|
Modified = true;
|
2017-11-16 05:06:22 +08:00
|
|
|
else
|
2016-05-06 23:08:57 +08:00
|
|
|
++MBBI;
|
2017-11-16 05:06:22 +08:00
|
|
|
}
|
2016-02-02 05:38:31 +08:00
|
|
|
// 3) Find loads and stores that can be merged into a single load or store
|
|
|
|
// pair instruction.
|
|
|
|
// e.g.,
|
|
|
|
// ldr x0, [x2]
|
|
|
|
// ldr x1, [x2, #8]
|
|
|
|
// ; becomes
|
|
|
|
// ldp x0, x1, [x2]
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
|
|
|
|
if (MBB.getParent()->getRegInfo().tracksLiveness()) {
|
|
|
|
DefinedInBB.clear();
|
|
|
|
DefinedInBB.addLiveIns(MBB);
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
for (MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
|
|
|
|
MBBI != E;) {
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
// Track currently live registers up to this point, to help with
|
|
|
|
// searching for a rename register on demand.
|
|
|
|
updateDefinedRegisters(*MBBI, DefinedInBB, TRI);
|
2016-08-12 23:26:00 +08:00
|
|
|
if (TII->isPairableLdStInst(*MBBI) && tryToPairLdStInst(MBBI))
|
|
|
|
Modified = true;
|
|
|
|
else
|
2014-03-29 18:18:08 +08:00
|
|
|
++MBBI;
|
|
|
|
}
|
2016-02-02 05:38:31 +08:00
|
|
|
// 4) Find base register updates that can be merged into the load or store
|
|
|
|
// as a base-reg writeback.
|
|
|
|
// e.g.,
|
|
|
|
// ldr x0, [x2]
|
|
|
|
// add x2, x2, #4
|
|
|
|
// ; becomes
|
|
|
|
// ldr x0, [x2], #4
|
2014-03-29 18:18:08 +08:00
|
|
|
for (MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
|
|
|
|
MBBI != E;) {
|
2017-11-16 05:06:22 +08:00
|
|
|
if (isMergeableLdStUpdate(*MBBI) && tryToMergeLdStUpdate(MBBI))
|
|
|
|
Modified = true;
|
|
|
|
else
|
2014-03-29 18:18:08 +08:00
|
|
|
++MBBI;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64LoadStoreOpt::runOnMachineFunction(MachineFunction &Fn) {
|
2017-12-16 06:22:58 +08:00
|
|
|
if (skipFunction(Fn.getFunction()))
|
2016-04-26 05:58:52 +08:00
|
|
|
return false;
|
|
|
|
|
2015-11-10 19:04:18 +08:00
|
|
|
Subtarget = &static_cast<const AArch64Subtarget &>(Fn.getSubtarget());
|
|
|
|
TII = static_cast<const AArch64InstrInfo *>(Subtarget->getInstrInfo());
|
|
|
|
TRI = Subtarget->getRegisterInfo();
|
2017-03-17 22:19:55 +08:00
|
|
|
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
2014-03-29 18:18:08 +08:00
|
|
|
|
[CodeGen] Use RegUnits to track register aliases (NFC)
Summary: Use RegUnits to track register aliases in PostRASink and AArch64LoadStoreOptimizer.
Reviewers: thegameg, mcrosier, gberry, qcolombet, sebpop, MatzeB, t.p.northover, javed.absar
Reviewed By: thegameg, sebpop
Subscribers: javed.absar, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D45695
llvm-svn: 331066
2018-04-28 02:44:37 +08:00
|
|
|
// Resize the modified and used register unit trackers. We do this once
|
|
|
|
// per function and then clear the register units each time we optimize a load
|
|
|
|
// or store.
|
|
|
|
ModifiedRegUnits.init(*TRI);
|
|
|
|
UsedRegUnits.init(*TRI);
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
DefinedInBB.init(*TRI);
|
2016-02-02 23:02:30 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool Modified = false;
|
[AArch64] Enable merging of adjacent zero stores for all subtargets.
This optimization merges adjacent zero stores into a wider store.
e.g.,
strh wzr, [x0]
strh wzr, [x0, #2]
; becomes
str wzr, [x0]
e.g.,
str wzr, [x0]
str wzr, [x0, #4]
; becomes
str xzr, [x0]
Previously, this was only enabled for Kryo and Cortex-A57.
Differential Revision: https://reviews.llvm.org/D26396
llvm-svn: 286592
2016-11-11 22:10:12 +08:00
|
|
|
bool enableNarrowZeroStOpt = !Subtarget->requiresStrictAlign();
|
[AArch64] Teach Load/Store optimizier to rename store operands for pairing.
In some cases, we can rename a store operand, in order to enable pairing
of stores. For store pairs, that cannot be merged because the first
tored register is defined in between the second store, we try to find
suitable rename register.
First, we check if we can rename the given register:
1. The first store register must be killed at the store, which means we
do not have to rename instructions after the first store.
2. We scan backwards from the first store, to find the definition of the
stored register and check all uses in between are renamable. Along
they way, we collect the minimal register classes of the uses for
overlapping (sub/super)registers.
Second, we try to find an available register from the minimal physical
register class of the original register. A suitable register must not be
1. defined before FirstMI
2. between the previous definition of the register to rename
3. a callee saved register.
We use KILL flags to clear defined registers while scanning from the
beginning to the end of the block.
This triggers quite often, here are the top changes for MultiSource,
SPEC2000, SPEC2006 compiled with -O3 for iOS:
Metric: aarch64-ldst-opt.NumPairCreated
Program base patch diff
test-suite...nch/fourinarow/fourinarow.test 2.00 39.00 1850.0%
test-suite...s/ASC_Sequoia/IRSmk/IRSmk.test 46.00 80.00 73.9%
test-suite...chmarks/Olden/power/power.test 70.00 96.00 37.1%
test-suite...cations/hexxagon/hexxagon.test 29.00 39.00 34.5%
test-suite...nchmarks/McCat/05-eks/eks.test 100.00 132.00 32.0%
test-suite.../Trimaran/enc-rc4/enc-rc4.test 46.00 59.00 28.3%
test-suite...T2006/473.astar/473.astar.test 160.00 200.00 25.0%
test-suite.../Trimaran/enc-md5/enc-md5.test 8.00 10.00 25.0%
test-suite...telecomm-gsm/telecomm-gsm.test 113.00 139.00 23.0%
test-suite...ediabench/gsm/toast/toast.test 113.00 139.00 23.0%
test-suite...Source/Benchmarks/sim/sim.test 91.00 111.00 22.0%
test-suite...C/CFP2000/179.art/179.art.test 41.00 49.00 19.5%
test-suite...peg2/mpeg2dec/mpeg2decode.test 245.00 279.00 13.9%
test-suite...marks/Olden/health/health.test 16.00 18.00 12.5%
test-suite...ks/Prolangs-C/cdecl/cdecl.test 90.00 101.00 12.2%
test-suite...fice-ispell/office-ispell.test 91.00 100.00 9.9%
test-suite...oxyApps-C/miniGMG/miniGMG.test 430.00 465.00 8.1%
test-suite...lowfish/security-blowfish.test 39.00 42.00 7.7%
test-suite.../Applications/spiff/spiff.test 42.00 45.00 7.1%
test-suite...arks/mafft/pairlocalalign.test 2473.00 2646.00 7.0%
test-suite.../VersaBench/ecbdes/ecbdes.test 29.00 31.00 6.9%
test-suite...nch/beamformer/beamformer.test 220.00 235.00 6.8%
test-suite...CFP2000/177.mesa/177.mesa.test 2110.00 2252.00 6.7%
test-suite...ve-susan/automotive-susan.test 109.00 116.00 6.4%
test-suite...s-C/unix-smail/unix-smail.test 65.00 69.00 6.2%
test-suite...CI_Purple/SMG2000/smg2000.test 1194.00 1265.00 5.9%
test-suite.../Benchmarks/nbench/nbench.test 472.00 500.00 5.9%
test-suite...oxyApps-C/miniAMR/miniAMR.test 248.00 262.00 5.6%
test-suite...quoia/CrystalMk/CrystalMk.test 18.00 19.00 5.6%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 7331.00 7710.00 5.2%
test-suite.../Benchmarks/Bullet/bullet.test 5651.00 5938.00 5.1%
test-suite...ternal/HMMER/hmmcalibrate.test 750.00 788.00 5.1%
test-suite...T2006/456.hmmer/456.hmmer.test 764.00 802.00 5.0%
test-suite...ications/JM/ldecod/ldecod.test 1028.00 1079.00 5.0%
test-suite...CFP2006/444.namd/444.namd.test 1368.00 1434.00 4.8%
test-suite...marks/7zip/7zip-benchmark.test 4471.00 4685.00 4.8%
test-suite...6/464.h264ref/464.h264ref.test 3122.00 3271.00 4.8%
test-suite...pplications/oggenc/oggenc.test 1497.00 1565.00 4.5%
test-suite...T2000/300.twolf/300.twolf.test 742.00 774.00 4.3%
test-suite.../Prolangs-C/loader/loader.test 24.00 25.00 4.2%
test-suite...0.perlbench/400.perlbench.test 1983.00 2058.00 3.8%
test-suite...ications/JM/lencod/lencod.test 4612.00 4785.00 3.8%
test-suite...yApps-C++/PENNANT/PENNANT.test 995.00 1032.00 3.7%
test-suite...arks/VersaBench/dbms/dbms.test 54.00 56.00 3.7%
Reviewers: efriedma, thegameg, samparker, dmgreen, paquette, evandro
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D70450
2019-12-11 17:59:18 +08:00
|
|
|
for (auto &MBB : Fn) {
|
|
|
|
auto M = optimizeBlock(MBB, enableNarrowZeroStOpt);
|
|
|
|
Modified |= M;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
2016-11-12 03:52:45 +08:00
|
|
|
// FIXME: Do we need/want a pre-alloc pass like ARM has to try to keep loads and
|
|
|
|
// stores near one another? Note: The pre-RA instruction scheduler already has
|
|
|
|
// hooks to try and schedule pairable loads/stores together to improve pairing
|
|
|
|
// opportunities. Thus, pre-RA pairing pass may not be worth the effort.
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-02-10 03:42:19 +08:00
|
|
|
// FIXME: When pairing store instructions it's very possible for this pass to
|
|
|
|
// hoist a store with a KILL marker above another use (without a KILL marker).
|
|
|
|
// The resulting IR is invalid, but nothing uses the KILL markers after this
|
|
|
|
// pass, so it's never caused a problem in practice.
|
|
|
|
|
2015-08-05 20:40:13 +08:00
|
|
|
/// createAArch64LoadStoreOptimizationPass - returns an instance of the
|
|
|
|
/// load / store optimization pass.
|
2014-05-24 20:50:23 +08:00
|
|
|
FunctionPass *llvm::createAArch64LoadStoreOptimizationPass() {
|
|
|
|
return new AArch64LoadStoreOpt();
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|