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);
88 if (!LiveRegs.available(OtherReg))
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)) {
155bool SystemZShortenInst::shortenFPConv(
MachineInstr &
MI,
unsigned Opcode) {
166 MI.setDesc(
TII->get(Opcode));
177bool SystemZShortenInst::shortenFusedFPOp(
MachineInstr &
MI,
unsigned Opcode) {
193 MI.setDesc(
TII->get(Opcode));
205 bool Changed =
false;
209 LiveRegs.addLiveOuts(
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);
340 Changed |= shortenOn0(
MI, SystemZ::STE);
344 Changed |= shortenOn0(
MI, SystemZ::LD);
348 Changed |= shortenOn0(
MI, SystemZ::STD);
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) {
377 LiveRegs.stepBackward(
MI);
384 if (skipFunction(
F.getFunction()))
388 TII =
ST.getInstrInfo();
389 TRI =
ST.getRegisterInfo();
392 bool Changed =
false;
394 Changed |= processBlock(
MBB);
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
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.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
void setImm(int64_t immVal)
Register getReg() const
getReg - Returns the register number.
Wrapper class representing virtual and physical registers.
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)
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
auto reverse(ContainerTy &&C)
FunctionPass * createSystemZShortenInstPass(SystemZTargetMachine &TM)