2012-02-15 19:52:27 +01:00
|
|
|
//===-- HexagonPeephole.cpp - Hexagon Peephole Optimiztions ---------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01: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
|
2012-02-15 19:52:27 +01:00
|
|
|
//
|
|
|
|
// This peephole pass optimizes in the following cases.
|
|
|
|
// 1. Optimizes redundant sign extends for the following case
|
|
|
|
// Transform the following pattern
|
2017-12-07 11:40:31 +01:00
|
|
|
// %170 = SXTW %166
|
2012-02-15 19:52:27 +01:00
|
|
|
// ...
|
2017-12-07 11:40:31 +01:00
|
|
|
// %176 = COPY %170:isub_lo
|
2012-02-15 19:52:27 +01:00
|
|
|
//
|
|
|
|
// Into
|
2017-12-07 11:40:31 +01:00
|
|
|
// %176 = COPY %166
|
2012-02-15 19:52:27 +01:00
|
|
|
//
|
|
|
|
// 2. Optimizes redundant negation of predicates.
|
2017-12-07 11:40:31 +01:00
|
|
|
// %15 = CMPGTrr %6, %2
|
2012-02-15 19:52:27 +01:00
|
|
|
// ...
|
2017-12-07 11:40:31 +01:00
|
|
|
// %16 = NOT_p killed %15
|
2012-02-15 19:52:27 +01:00
|
|
|
// ...
|
2017-12-07 11:40:31 +01:00
|
|
|
// JMP_c killed %16, <%bb.1>, implicit dead %pc
|
2012-02-15 19:52:27 +01:00
|
|
|
//
|
|
|
|
// Into
|
2017-12-07 11:40:31 +01:00
|
|
|
// %15 = CMPGTrr %6, %2;
|
2012-02-15 19:52:27 +01:00
|
|
|
// ...
|
2017-12-07 11:40:31 +01:00
|
|
|
// JMP_cNot killed %15, <%bb.1>, implicit dead %pc;
|
2012-02-15 19:52:27 +01:00
|
|
|
//
|
|
|
|
// Note: The peephole pass makes the instrucstions like
|
2017-12-07 11:40:31 +01:00
|
|
|
// %170 = SXTW %166 or %16 = NOT_p killed %15
|
2013-09-28 15:42:22 +02:00
|
|
|
// redundant and relies on some form of dead removal instructions, like
|
2012-02-15 19:52:27 +01:00
|
|
|
// DCE or DIE to actually eliminate them.
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-03-17 19:46:09 +01:00
|
|
|
#include "Hexagon.h"
|
|
|
|
#include "HexagonTargetMachine.h"
|
2012-02-15 19:52:27 +01:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2017-11-08 02:01:31 +01:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-11-17 02:07:10 +01:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Constants.h"
|
2020-04-26 13:57:57 +02:00
|
|
|
#include "llvm/Pass.h"
|
2012-03-17 19:46:09 +01:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2012-02-15 19:52:27 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 04:41:26 +02:00
|
|
|
#define DEBUG_TYPE "hexagon-peephole"
|
|
|
|
|
2012-02-15 19:52:27 +01:00
|
|
|
static cl::opt<bool> DisableHexagonPeephole("disable-hexagon-peephole",
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Peephole Optimization"));
|
|
|
|
|
|
|
|
static cl::opt<bool> DisablePNotP("disable-hexagon-pnotp",
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Optimization of PNotP"));
|
|
|
|
|
|
|
|
static cl::opt<bool> DisableOptSZExt("disable-hexagon-optszext",
|
2016-04-19 23:36:24 +02:00
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(true),
|
2012-02-15 19:52:27 +01:00
|
|
|
cl::desc("Disable Optimization of Sign/Zero Extends"));
|
|
|
|
|
2013-05-02 22:22:51 +02:00
|
|
|
static cl::opt<bool> DisableOptExtTo64("disable-hexagon-opt-ext-to-64",
|
2016-04-19 23:36:24 +02:00
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(true),
|
2013-05-02 22:22:51 +02:00
|
|
|
cl::desc("Disable Optimization of extensions to i64."));
|
|
|
|
|
2013-05-06 23:58:00 +02:00
|
|
|
namespace llvm {
|
2015-06-15 21:05:35 +02:00
|
|
|
FunctionPass *createHexagonPeephole();
|
2013-05-06 23:58:00 +02:00
|
|
|
void initializeHexagonPeepholePass(PassRegistry&);
|
|
|
|
}
|
|
|
|
|
2012-02-15 19:52:27 +01:00
|
|
|
namespace {
|
|
|
|
struct HexagonPeephole : public MachineFunctionPass {
|
|
|
|
const HexagonInstrInfo *QII;
|
|
|
|
const HexagonRegisterInfo *QRI;
|
|
|
|
const MachineRegisterInfo *MRI;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
2013-05-06 23:58:00 +02:00
|
|
|
HexagonPeephole() : MachineFunctionPass(ID) {
|
|
|
|
initializeHexagonPeepholePass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2012-02-15 19:52:27 +01:00
|
|
|
|
2014-04-29 09:58:16 +02:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2012-02-15 19:52:27 +01:00
|
|
|
|
2016-10-01 04:56:57 +02:00
|
|
|
StringRef getPassName() const override {
|
2012-02-15 19:52:27 +01:00
|
|
|
return "Hexagon optimize redundant zero and size extends";
|
|
|
|
}
|
|
|
|
|
2014-04-29 09:58:16 +02:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2012-02-15 19:52:27 +01:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 11:49:53 +02:00
|
|
|
}
|
2012-02-15 19:52:27 +01:00
|
|
|
|
|
|
|
char HexagonPeephole::ID = 0;
|
|
|
|
|
2013-05-06 23:58:00 +02:00
|
|
|
INITIALIZE_PASS(HexagonPeephole, "hexagon-peephole", "Hexagon Peephole",
|
|
|
|
false, false)
|
2012-02-15 19:52:27 +01:00
|
|
|
|
2013-05-06 23:58:00 +02:00
|
|
|
bool HexagonPeephole::runOnMachineFunction(MachineFunction &MF) {
|
2017-12-15 23:22:58 +01:00
|
|
|
if (skipFunction(MF.getFunction()))
|
2016-04-26 21:46:28 +02:00
|
|
|
return false;
|
|
|
|
|
2014-08-05 04:39:49 +02:00
|
|
|
QII = static_cast<const HexagonInstrInfo *>(MF.getSubtarget().getInstrInfo());
|
2015-02-02 23:40:56 +01:00
|
|
|
QRI = MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
|
2012-02-15 19:52:27 +01:00
|
|
|
MRI = &MF.getRegInfo();
|
|
|
|
|
|
|
|
DenseMap<unsigned, unsigned> PeepholeMap;
|
2012-09-05 18:01:40 +02:00
|
|
|
DenseMap<unsigned, std::pair<unsigned, unsigned> > PeepholeDoubleRegsMap;
|
2012-02-15 19:52:27 +01:00
|
|
|
|
|
|
|
if (DisableHexagonPeephole) return false;
|
|
|
|
|
|
|
|
// Loop over all of the basic blocks.
|
|
|
|
for (MachineFunction::iterator MBBb = MF.begin(), MBBe = MF.end();
|
|
|
|
MBBb != MBBe; ++MBBb) {
|
Hexagon: Remove implicit ilist iterator conversions, NFC
There are two things out of the ordinary in this commit. First, I made
a loop obviously "infinite" in HexagonInstrInfo.cpp. After checking if
an instruction was at the beginning of a basic block (in which case,
`break`), the loop decremented and checked the iterator for `nullptr` as
the loop condition. This has never been possible (the prev pointers are
always been circular, so even with the weird ilist/iplist
implementation, this isn't been possible), so I removed the condition.
Second, in HexagonAsmPrinter.cpp there was another case of comparing a
`MachineBasicBlock::instr_iterator` against `MachineBasicBlock::end()`
(which returns `MachineBasicBlock::iterator`). While not incorrect,
it's fragile. I switched this to `::instr_end()`.
All that said, no functionality change intended here.
llvm-svn: 250778
2015-10-20 02:46:39 +02:00
|
|
|
MachineBasicBlock *MBB = &*MBBb;
|
2012-02-15 19:52:27 +01:00
|
|
|
PeepholeMap.clear();
|
2012-09-05 18:01:40 +02:00
|
|
|
PeepholeDoubleRegsMap.clear();
|
2012-02-15 19:52:27 +01:00
|
|
|
|
|
|
|
// Traverse the basic block.
|
2017-06-21 23:03:34 +02:00
|
|
|
for (auto I = MBB->begin(), E = MBB->end(), NextI = I; I != E; I = NextI) {
|
|
|
|
NextI = std::next(I);
|
|
|
|
MachineInstr &MI = *I;
|
2012-02-15 19:52:27 +01:00
|
|
|
// Look for sign extends:
|
2017-12-07 11:40:31 +01:00
|
|
|
// %170 = SXTW %166
|
2016-07-12 03:55:32 +02:00
|
|
|
if (!DisableOptSZExt && MI.getOpcode() == Hexagon::A2_sxtw) {
|
|
|
|
assert(MI.getNumOperands() == 2);
|
|
|
|
MachineOperand &Dst = MI.getOperand(0);
|
|
|
|
MachineOperand &Src = MI.getOperand(1);
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-15 21:22:08 +02:00
|
|
|
Register DstReg = Dst.getReg();
|
|
|
|
Register SrcReg = Src.getReg();
|
2012-02-15 19:52:27 +01:00
|
|
|
// Just handle virtual registers.
|
2019-08-02 01:27:28 +02:00
|
|
|
if (Register::isVirtualRegister(DstReg) &&
|
|
|
|
Register::isVirtualRegister(SrcReg)) {
|
2012-02-15 19:52:27 +01:00
|
|
|
// Map the following:
|
2017-12-07 11:40:31 +01:00
|
|
|
// %170 = SXTW %166
|
2017-11-30 13:12:19 +01:00
|
|
|
// PeepholeMap[170] = %166
|
2012-02-15 19:52:27 +01:00
|
|
|
PeepholeMap[DstReg] = SrcReg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 11:40:31 +01:00
|
|
|
// Look for %170 = COMBINE_ir_V4 (0, %169)
|
2017-11-30 13:12:19 +01:00
|
|
|
// %170:DoublRegs, %169:IntRegs
|
2016-07-12 03:55:32 +02:00
|
|
|
if (!DisableOptExtTo64 && MI.getOpcode() == Hexagon::A4_combineir) {
|
|
|
|
assert(MI.getNumOperands() == 3);
|
|
|
|
MachineOperand &Dst = MI.getOperand(0);
|
|
|
|
MachineOperand &Src1 = MI.getOperand(1);
|
|
|
|
MachineOperand &Src2 = MI.getOperand(2);
|
2013-05-02 22:22:51 +02:00
|
|
|
if (Src1.getImm() != 0)
|
|
|
|
continue;
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-15 21:22:08 +02:00
|
|
|
Register DstReg = Dst.getReg();
|
|
|
|
Register SrcReg = Src2.getReg();
|
2013-05-02 22:22:51 +02:00
|
|
|
PeepholeMap[DstReg] = SrcReg;
|
|
|
|
}
|
|
|
|
|
2012-09-05 18:01:40 +02:00
|
|
|
// Look for this sequence below
|
2017-11-30 13:12:19 +01:00
|
|
|
// %DoubleReg1 = LSRd_ri %DoubleReg0, 32
|
|
|
|
// %IntReg = COPY %DoubleReg1:isub_lo.
|
2012-09-05 18:01:40 +02:00
|
|
|
// and convert into
|
2017-11-30 13:12:19 +01:00
|
|
|
// %IntReg = COPY %DoubleReg0:isub_hi.
|
2016-07-12 03:55:32 +02:00
|
|
|
if (MI.getOpcode() == Hexagon::S2_lsr_i_p) {
|
|
|
|
assert(MI.getNumOperands() == 3);
|
|
|
|
MachineOperand &Dst = MI.getOperand(0);
|
|
|
|
MachineOperand &Src1 = MI.getOperand(1);
|
|
|
|
MachineOperand &Src2 = MI.getOperand(2);
|
2012-09-05 18:01:40 +02:00
|
|
|
if (Src2.getImm() != 32)
|
|
|
|
continue;
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-15 21:22:08 +02:00
|
|
|
Register DstReg = Dst.getReg();
|
|
|
|
Register SrcReg = Src1.getReg();
|
2012-09-05 18:01:40 +02:00
|
|
|
PeepholeDoubleRegsMap[DstReg] =
|
2016-11-09 17:19:08 +01:00
|
|
|
std::make_pair(*&SrcReg, Hexagon::isub_hi);
|
2012-09-05 18:01:40 +02:00
|
|
|
}
|
|
|
|
|
2012-02-15 19:52:27 +01:00
|
|
|
// Look for P=NOT(P).
|
2016-07-12 03:55:32 +02:00
|
|
|
if (!DisablePNotP && MI.getOpcode() == Hexagon::C2_not) {
|
|
|
|
assert(MI.getNumOperands() == 2);
|
|
|
|
MachineOperand &Dst = MI.getOperand(0);
|
|
|
|
MachineOperand &Src = MI.getOperand(1);
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-15 21:22:08 +02:00
|
|
|
Register DstReg = Dst.getReg();
|
|
|
|
Register SrcReg = Src.getReg();
|
2012-02-15 19:52:27 +01:00
|
|
|
// Just handle virtual registers.
|
2019-08-02 01:27:28 +02:00
|
|
|
if (Register::isVirtualRegister(DstReg) &&
|
|
|
|
Register::isVirtualRegister(SrcReg)) {
|
2012-02-15 19:52:27 +01:00
|
|
|
// Map the following:
|
2017-12-07 11:40:31 +01:00
|
|
|
// %170 = NOT_xx %166
|
2017-11-30 13:12:19 +01:00
|
|
|
// PeepholeMap[170] = %166
|
2012-02-15 19:52:27 +01:00
|
|
|
PeepholeMap[DstReg] = SrcReg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for copy:
|
2017-12-07 11:40:31 +01:00
|
|
|
// %176 = COPY %170:isub_lo
|
2016-07-12 03:55:32 +02:00
|
|
|
if (!DisableOptSZExt && MI.isCopy()) {
|
|
|
|
assert(MI.getNumOperands() == 2);
|
|
|
|
MachineOperand &Dst = MI.getOperand(0);
|
|
|
|
MachineOperand &Src = MI.getOperand(1);
|
2012-02-15 19:52:27 +01:00
|
|
|
|
|
|
|
// Make sure we are copying the lower 32 bits.
|
2016-11-09 17:19:08 +01:00
|
|
|
if (Src.getSubReg() != Hexagon::isub_lo)
|
2012-02-15 19:52:27 +01:00
|
|
|
continue;
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-15 21:22:08 +02:00
|
|
|
Register DstReg = Dst.getReg();
|
|
|
|
Register SrcReg = Src.getReg();
|
2019-08-02 01:27:28 +02:00
|
|
|
if (Register::isVirtualRegister(DstReg) &&
|
|
|
|
Register::isVirtualRegister(SrcReg)) {
|
2012-02-15 19:52:27 +01:00
|
|
|
// Try to find in the map.
|
|
|
|
if (unsigned PeepholeSrc = PeepholeMap.lookup(SrcReg)) {
|
|
|
|
// Change the 1st operand.
|
2016-07-12 03:55:32 +02:00
|
|
|
MI.RemoveOperand(1);
|
|
|
|
MI.addOperand(MachineOperand::CreateReg(PeepholeSrc, false));
|
2012-09-05 18:01:40 +02:00
|
|
|
} else {
|
|
|
|
DenseMap<unsigned, std::pair<unsigned, unsigned> >::iterator DI =
|
|
|
|
PeepholeDoubleRegsMap.find(SrcReg);
|
|
|
|
if (DI != PeepholeDoubleRegsMap.end()) {
|
|
|
|
std::pair<unsigned,unsigned> PeepholeSrc = DI->second;
|
2016-07-12 03:55:32 +02:00
|
|
|
MI.RemoveOperand(1);
|
|
|
|
MI.addOperand(MachineOperand::CreateReg(
|
|
|
|
PeepholeSrc.first, false /*isDef*/, false /*isImp*/,
|
|
|
|
false /*isKill*/, false /*isDead*/, false /*isUndef*/,
|
|
|
|
false /*isEarlyClobber*/, PeepholeSrc.second));
|
2012-09-05 18:01:40 +02:00
|
|
|
}
|
2012-02-15 19:52:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for Predicated instructions.
|
|
|
|
if (!DisablePNotP) {
|
|
|
|
bool Done = false;
|
2016-07-12 03:55:32 +02:00
|
|
|
if (QII->isPredicated(MI)) {
|
|
|
|
MachineOperand &Op0 = MI.getOperand(0);
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-15 21:22:08 +02:00
|
|
|
Register Reg0 = Op0.getReg();
|
2012-02-15 19:52:27 +01:00
|
|
|
const TargetRegisterClass *RC0 = MRI->getRegClass(Reg0);
|
|
|
|
if (RC0->getID() == Hexagon::PredRegsRegClassID) {
|
|
|
|
// Handle instructions that have a prediate register in op0
|
|
|
|
// (most cases of predicable instructions).
|
2019-08-02 01:27:28 +02:00
|
|
|
if (Register::isVirtualRegister(Reg0)) {
|
2012-02-15 19:52:27 +01:00
|
|
|
// Try to find in the map.
|
|
|
|
if (unsigned PeepholeSrc = PeepholeMap.lookup(Reg0)) {
|
|
|
|
// Change the 1st operand and, flip the opcode.
|
2016-07-12 03:55:32 +02:00
|
|
|
MI.getOperand(0).setReg(PeepholeSrc);
|
2016-08-04 16:17:16 +02:00
|
|
|
MRI->clearKillFlags(PeepholeSrc);
|
2016-07-12 03:55:32 +02:00
|
|
|
int NewOp = QII->getInvertedPredicatedOpcode(MI.getOpcode());
|
|
|
|
MI.setDesc(QII->get(NewOp));
|
2012-02-15 19:52:27 +01:00
|
|
|
Done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Done) {
|
|
|
|
// Handle special instructions.
|
2016-07-12 03:55:32 +02:00
|
|
|
unsigned Op = MI.getOpcode();
|
2012-02-15 19:52:27 +01:00
|
|
|
unsigned NewOp = 0;
|
|
|
|
unsigned PR = 1, S1 = 2, S2 = 3; // Operand indices.
|
|
|
|
|
|
|
|
switch (Op) {
|
2014-11-25 21:20:09 +01:00
|
|
|
case Hexagon::C2_mux:
|
2014-12-05 22:09:27 +01:00
|
|
|
case Hexagon::C2_muxii:
|
2012-02-15 19:52:27 +01:00
|
|
|
NewOp = Op;
|
|
|
|
break;
|
2014-12-05 22:09:27 +01:00
|
|
|
case Hexagon::C2_muxri:
|
|
|
|
NewOp = Hexagon::C2_muxir;
|
2012-02-15 19:52:27 +01:00
|
|
|
break;
|
2014-12-05 22:09:27 +01:00
|
|
|
case Hexagon::C2_muxir:
|
|
|
|
NewOp = Hexagon::C2_muxri;
|
2012-02-15 19:52:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NewOp) {
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-15 21:22:08 +02:00
|
|
|
Register PSrc = MI.getOperand(PR).getReg();
|
2012-02-15 19:52:27 +01:00
|
|
|
if (unsigned POrig = PeepholeMap.lookup(PSrc)) {
|
2017-06-21 23:03:34 +02:00
|
|
|
BuildMI(*MBB, MI.getIterator(), MI.getDebugLoc(),
|
|
|
|
QII->get(NewOp), MI.getOperand(0).getReg())
|
|
|
|
.addReg(POrig)
|
|
|
|
.add(MI.getOperand(S2))
|
|
|
|
.add(MI.getOperand(S1));
|
2016-08-04 16:17:16 +02:00
|
|
|
MRI->clearKillFlags(POrig);
|
2017-06-21 23:03:34 +02:00
|
|
|
MI.eraseFromParent();
|
2012-02-15 19:52:27 +01:00
|
|
|
}
|
|
|
|
} // if (NewOp)
|
|
|
|
} // if (!Done)
|
|
|
|
|
|
|
|
} // if (!DisablePNotP)
|
|
|
|
|
|
|
|
} // Instruction
|
|
|
|
} // Basic Block
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionPass *llvm::createHexagonPeephole() {
|
|
|
|
return new HexagonPeephole();
|
|
|
|
}
|