23#define DEBUG_TYPE "systemz-shorten-inst"
51char SystemZShortenInst::ID = 0;
55 "SystemZ Instruction Shortening",
false,
false)
58 return new SystemZShortenInst();
61SystemZShortenInst::SystemZShortenInst()
67 !
MI.getOperand(0).isTied())
74bool SystemZShortenInst::shortenIIF(
MachineInstr &
MI,
unsigned LLIxL,
79 unsigned thisSubRegIdx =
80 (SystemZ::GRH32BitRegClass.contains(
Reg) ? SystemZ::subreg_h32
81 : SystemZ::subreg_l32);
82 unsigned otherSubRegIdx =
83 (thisSubRegIdx == SystemZ::subreg_l32 ? SystemZ::subreg_h32
84 : SystemZ::subreg_l32);
86 TRI->getMatchingSuperReg(
Reg, thisSubRegIdx, &SystemZ::GR64BitRegClass);
87 Register OtherReg =
TRI->getSubReg(GR64BitReg, otherSubRegIdx);
91 uint64_t
Imm =
MI.getOperand(1).getImm();
93 MI.setDesc(
TII->get(LLIxL));
98 MI.setDesc(
TII->get(LLIxH));
100 MI.getOperand(1).setImm(Imm >> 16);
107bool SystemZShortenInst::shortenOn0(MachineInstr &
MI,
unsigned Opcode) {
109 MI.setDesc(
TII->get(Opcode));
117bool SystemZShortenInst::shortenOn01(MachineInstr &
MI,
unsigned Opcode) {
120 MI.setDesc(
TII->get(Opcode));
129bool SystemZShortenInst::shortenOn001(MachineInstr &
MI,
unsigned Opcode) {
131 MI.getOperand(1).getReg() ==
MI.getOperand(0).getReg() &&
133 MI.setDesc(
TII->get(Opcode));
142bool SystemZShortenInst::shortenOn001AddCC(MachineInstr &
MI,
unsigned Opcode) {
143 if (LiveRegs.
available(SystemZ::CC) && shortenOn001(
MI, Opcode)) {
144 MachineInstrBuilder(*
MI.getParent()->getParent(), &
MI)
155bool SystemZShortenInst::shortenFPConv(MachineInstr &
MI,
unsigned Opcode) {
158 MachineOperand Dest(
MI.getOperand(0));
159 MachineOperand Src(
MI.getOperand(1));
160 MachineOperand Suppress(
MI.getOperand(2));
161 MachineOperand
Mode(
MI.getOperand(3));
166 MI.setDesc(
TII->get(Opcode));
167 MachineInstrBuilder(*
MI.getParent()->getParent(), &
MI)
177bool SystemZShortenInst::shortenFusedFPOp(MachineInstr &
MI,
unsigned Opcode) {
178 MachineOperand &DstMO =
MI.getOperand(0);
179 MachineOperand &LHSMO =
MI.getOperand(1);
180 MachineOperand &RHSMO =
MI.getOperand(2);
181 MachineOperand &AccMO =
MI.getOperand(3);
187 MachineOperand Lhs(LHSMO);
188 MachineOperand Rhs(RHSMO);
189 MachineOperand Src(AccMO);
193 MI.setDesc(
TII->get(Opcode));
194 MachineInstrBuilder(*
MI.getParent()->getParent(), &
MI)
204bool SystemZShortenInst::processBlock(MachineBasicBlock &
MBB) {
213 switch (
MI.getOpcode()) {
215 Changed |= shortenIIF(
MI, SystemZ::LLILL, SystemZ::LLILH);
219 Changed |= shortenIIF(
MI, SystemZ::LLIHL, SystemZ::LLIHH);
223 Changed |= shortenOn001AddCC(
MI, SystemZ::ADBR);
227 Changed |= shortenOn001AddCC(
MI, SystemZ::AEBR);
231 Changed |= shortenOn001(
MI, SystemZ::DDBR);
235 Changed |= shortenOn001(
MI, SystemZ::DEBR);
239 Changed |= shortenFPConv(
MI, SystemZ::FIDBRA);
243 Changed |= shortenFPConv(
MI, SystemZ::FIEBRA);
247 Changed |= shortenOn01(
MI, SystemZ::LDEBR);
251 Changed |= shortenFPConv(
MI, SystemZ::LEDBRA);
255 Changed |= shortenOn001(
MI, SystemZ::MDBR);
259 Changed |= shortenOn001(
MI, SystemZ::MEEBR);
262 case SystemZ::WFMADB:
263 Changed |= shortenFusedFPOp(
MI, SystemZ::MADBR);
266 case SystemZ::WFMASB:
267 Changed |= shortenFusedFPOp(
MI, SystemZ::MAEBR);
270 case SystemZ::WFMSDB:
271 Changed |= shortenFusedFPOp(
MI, SystemZ::MSDBR);
274 case SystemZ::WFMSSB:
275 Changed |= shortenFusedFPOp(
MI, SystemZ::MSEBR);
278 case SystemZ::WFLCDB:
279 Changed |= shortenOn01(
MI, SystemZ::LCDFR);
282 case SystemZ::WFLCSB:
283 Changed |= shortenOn01(
MI, SystemZ::LCDFR_32);
286 case SystemZ::WFLNDB:
287 Changed |= shortenOn01(
MI, SystemZ::LNDFR);
290 case SystemZ::WFLNSB:
291 Changed |= shortenOn01(
MI, SystemZ::LNDFR_32);
294 case SystemZ::WFLPDB:
295 Changed |= shortenOn01(
MI, SystemZ::LPDFR);
298 case SystemZ::WFLPSB:
299 Changed |= shortenOn01(
MI, SystemZ::LPDFR_32);
302 case SystemZ::WFSQDB:
303 Changed |= shortenOn01(
MI, SystemZ::SQDBR);
306 case SystemZ::WFSQSB:
307 Changed |= shortenOn01(
MI, SystemZ::SQEBR);
311 Changed |= shortenOn001AddCC(
MI, SystemZ::SDBR);
315 Changed |= shortenOn001AddCC(
MI, SystemZ::SEBR);
319 Changed |= shortenOn01(
MI, SystemZ::CDBR);
323 Changed |= shortenOn01(
MI, SystemZ::CEBR);
327 Changed |= shortenOn01(
MI, SystemZ::KDBR);
331 Changed |= shortenOn01(
MI, SystemZ::KEBR);
336 Changed |= shortenOn0(
MI, SystemZ::LDE32);
353 if (TwoOperandOpcode == -1)
356 if ((
MI.getOperand(0).getReg() !=
MI.getOperand(1).getReg()) &&
357 (!
MI.isCommutable() ||
358 MI.getOperand(0).getReg() !=
MI.getOperand(2).getReg() ||
359 !
TII->commuteInstruction(
MI,
false, 1, 2)))
362 MI.setDesc(
TII->get(TwoOperandOpcode));
363 MI.tieOperands(0, 1);
364 if (TwoOperandOpcode == SystemZ::SLL ||
365 TwoOperandOpcode == SystemZ::SLA ||
366 TwoOperandOpcode == SystemZ::SRL ||
367 TwoOperandOpcode == SystemZ::SRA) {
369 MachineOperand &ImmMO =
MI.getOperand(3);
383bool SystemZShortenInst::runOnMachineFunction(MachineFunction &
F) {
384 if (skipFunction(
F.getFunction()))
387 const SystemZSubtarget &
ST =
F.getSubtarget<SystemZSubtarget>();
388 TII =
ST.getInstrInfo();
389 TRI =
ST.getRegisterInfo();
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static void tieOpsIfNeeded(MachineInstr &MI)
FunctionPass class - This class is used to implement most global optimizations.
A set of register units used to track register liveness.
bool available(MCRegister Reg) const
Returns true if no part of physical register Reg is live.
void init(const TargetRegisterInfo &TRI)
Initialize and clear the set.
LLVM_ABI void stepBackward(const MachineInstr &MI)
Updates liveness when stepping backwards over the instruction MI.
LLVM_ABI void addLiveOuts(const MachineBasicBlock &MBB)
Adds registers living out of block MBB.
void clear()
Clears the set.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Properties which a MachineFunction may have at a given point in time.
Representation of each machine instruction.
void setImm(int64_t immVal)
Register getReg() const
getReg - Returns the register number.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
unsigned getFirstReg(unsigned Reg)
unsigned getRegAsGR64(unsigned Reg)
static bool isImmLL(uint64_t Val)
static bool isImmLH(uint64_t Val)
int getTwoOperandOpcode(uint16_t Opcode)
This is an optimization pass for GlobalISel generic memory operations.
auto reverse(ContainerTy &&C)
FunctionPass * createSystemZShortenInstPass(SystemZTargetMachine &TM)