23#define DEBUG_TYPE "systemz-shorten-inst"
35 MachineFunctionProperties::Property::NoVRegs);
52char SystemZShortenInst::ID = 0;
56 "SystemZ Instruction Shortening",
false,
false)
59 return new SystemZShortenInst();
62SystemZShortenInst::SystemZShortenInst()
70 !
MI.getOperand(0).isTied())
77bool SystemZShortenInst::shortenIIF(
MachineInstr &
MI,
unsigned LLIxL,
82 unsigned thisSubRegIdx =
83 (SystemZ::GRH32BitRegClass.contains(Reg) ? SystemZ::subreg_h32
84 : SystemZ::subreg_l32);
85 unsigned otherSubRegIdx =
86 (thisSubRegIdx == SystemZ::subreg_l32 ? SystemZ::subreg_h32
87 : SystemZ::subreg_l32);
89 TRI->getMatchingSuperReg(Reg, thisSubRegIdx, &SystemZ::GR64BitRegClass);
90 Register OtherReg =
TRI->getSubReg(GR64BitReg, otherSubRegIdx);
91 if (!LiveRegs.available(OtherReg))
96 MI.setDesc(
TII->get(LLIxL));
101 MI.setDesc(
TII->get(LLIxH));
103 MI.getOperand(1).setImm(Imm >> 16);
110bool SystemZShortenInst::shortenOn0(
MachineInstr &
MI,
unsigned Opcode) {
112 MI.setDesc(
TII->get(Opcode));
120bool SystemZShortenInst::shortenOn01(
MachineInstr &
MI,
unsigned Opcode) {
123 MI.setDesc(
TII->get(Opcode));
132bool SystemZShortenInst::shortenOn001(
MachineInstr &
MI,
unsigned Opcode) {
134 MI.getOperand(1).getReg() ==
MI.getOperand(0).getReg() &&
136 MI.setDesc(
TII->get(Opcode));
145bool SystemZShortenInst::shortenOn001AddCC(
MachineInstr &
MI,
unsigned Opcode) {
146 if (LiveRegs.available(SystemZ::CC) && shortenOn001(
MI, Opcode)) {
158bool SystemZShortenInst::shortenFPConv(
MachineInstr &
MI,
unsigned Opcode) {
169 MI.setDesc(
TII->get(Opcode));
180bool SystemZShortenInst::shortenFusedFPOp(
MachineInstr &
MI,
unsigned Opcode) {
196 MI.setDesc(
TII->get(Opcode));
208 bool Changed =
false;
212 LiveRegs.addLiveOuts(
MBB);
216 switch (
MI.getOpcode()) {
218 Changed |= shortenIIF(
MI, SystemZ::LLILL, SystemZ::LLILH);
222 Changed |= shortenIIF(
MI, SystemZ::LLIHL, SystemZ::LLIHH);
226 Changed |= shortenOn001AddCC(
MI, SystemZ::ADBR);
230 Changed |= shortenOn001AddCC(
MI, SystemZ::AEBR);
234 Changed |= shortenOn001(
MI, SystemZ::DDBR);
238 Changed |= shortenOn001(
MI, SystemZ::DEBR);
242 Changed |= shortenFPConv(
MI, SystemZ::FIDBRA);
246 Changed |= shortenFPConv(
MI, SystemZ::FIEBRA);
250 Changed |= shortenOn01(
MI, SystemZ::LDEBR);
254 Changed |= shortenFPConv(
MI, SystemZ::LEDBRA);
258 Changed |= shortenOn001(
MI, SystemZ::MDBR);
262 Changed |= shortenOn001(
MI, SystemZ::MEEBR);
265 case SystemZ::WFMADB:
266 Changed |= shortenFusedFPOp(
MI, SystemZ::MADBR);
269 case SystemZ::WFMASB:
270 Changed |= shortenFusedFPOp(
MI, SystemZ::MAEBR);
273 case SystemZ::WFMSDB:
274 Changed |= shortenFusedFPOp(
MI, SystemZ::MSDBR);
277 case SystemZ::WFMSSB:
278 Changed |= shortenFusedFPOp(
MI, SystemZ::MSEBR);
281 case SystemZ::WFLCDB:
282 Changed |= shortenOn01(
MI, SystemZ::LCDFR);
285 case SystemZ::WFLCSB:
286 Changed |= shortenOn01(
MI, SystemZ::LCDFR_32);
289 case SystemZ::WFLNDB:
290 Changed |= shortenOn01(
MI, SystemZ::LNDFR);
293 case SystemZ::WFLNSB:
294 Changed |= shortenOn01(
MI, SystemZ::LNDFR_32);
297 case SystemZ::WFLPDB:
298 Changed |= shortenOn01(
MI, SystemZ::LPDFR);
301 case SystemZ::WFLPSB:
302 Changed |= shortenOn01(
MI, SystemZ::LPDFR_32);
305 case SystemZ::WFSQDB:
306 Changed |= shortenOn01(
MI, SystemZ::SQDBR);
309 case SystemZ::WFSQSB:
310 Changed |= shortenOn01(
MI, SystemZ::SQEBR);
314 Changed |= shortenOn001AddCC(
MI, SystemZ::SDBR);
318 Changed |= shortenOn001AddCC(
MI, SystemZ::SEBR);
322 Changed |= shortenOn01(
MI, SystemZ::CDBR);
326 Changed |= shortenOn01(
MI, SystemZ::CEBR);
330 Changed |= shortenOn01(
MI, SystemZ::KDBR);
334 Changed |= shortenOn01(
MI, SystemZ::KEBR);
339 Changed |= shortenOn0(
MI, SystemZ::LDE32);
343 Changed |= shortenOn0(
MI, SystemZ::STE);
347 Changed |= shortenOn0(
MI, SystemZ::LD);
351 Changed |= shortenOn0(
MI, SystemZ::STD);
356 if (TwoOperandOpcode == -1)
359 if ((
MI.getOperand(0).getReg() !=
MI.getOperand(1).getReg()) &&
360 (!
MI.isCommutable() ||
361 MI.getOperand(0).getReg() !=
MI.getOperand(2).getReg() ||
362 !
TII->commuteInstruction(
MI,
false, 1, 2)))
365 MI.setDesc(
TII->get(TwoOperandOpcode));
366 MI.tieOperands(0, 1);
367 if (TwoOperandOpcode == SystemZ::SLL ||
368 TwoOperandOpcode == SystemZ::SLA ||
369 TwoOperandOpcode == SystemZ::SRL ||
370 TwoOperandOpcode == SystemZ::SRA) {
380 LiveRegs.stepBackward(
MI);
387 if (skipFunction(
F.getFunction()))
391 TII =
ST.getInstrInfo();
392 TRI =
ST.getRegisterInfo();
395 bool Changed =
false;
397 Changed |= processBlock(
MBB);
const HexagonInstrInfo * TII
unsigned 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.
MachineFunctionProperties & set(Property P)
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.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
void initializeSystemZShortenInstPass(PassRegistry &)
auto reverse(ContainerTy &&C)
FunctionPass * createSystemZShortenInstPass(SystemZTargetMachine &TM)