1 //===-- SystemZInstrInfo.cpp - SystemZ instruction information ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the SystemZ implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "SystemZInstrInfo.h"
15 #include "SystemZInstrBuilder.h"
16 #include "SystemZTargetMachine.h"
17 #include "llvm/CodeGen/LiveVariables.h"
18 #include "llvm/CodeGen/MachineRegisterInfo.h"
22 #define GET_INSTRINFO_CTOR_DTOR
23 #define GET_INSTRMAP_INFO
24 #include "SystemZGenInstrInfo.inc"
26 // Return a mask with Count low bits set.
27 static uint64_t allOnes(unsigned int Count) {
28 return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1;
31 // Reg should be a 32-bit GPR. Return true if it is a high register rather
32 // than a low register.
33 static bool isHighReg(unsigned int Reg) {
34 if (SystemZ::GRH32BitRegClass.contains(Reg))
36 assert(SystemZ::GR32BitRegClass.contains(Reg) && "Invalid GRX32");
40 // Pin the vtable to this file.
41 void SystemZInstrInfo::anchor() {}
43 SystemZInstrInfo::SystemZInstrInfo(SystemZSubtarget &sti)
44 : SystemZGenInstrInfo(SystemZ::ADJCALLSTACKDOWN, SystemZ::ADJCALLSTACKUP),
48 // MI is a 128-bit load or store. Split it into two 64-bit loads or stores,
49 // each having the opcode given by NewOpcode.
50 void SystemZInstrInfo::splitMove(MachineBasicBlock::iterator MI,
51 unsigned NewOpcode) const {
52 MachineBasicBlock *MBB = MI->getParent();
53 MachineFunction &MF = *MBB->getParent();
55 // Get two load or store instructions. Use the original instruction for one
56 // of them (arbitrarily the second here) and create a clone for the other.
57 MachineInstr *EarlierMI = MF.CloneMachineInstr(MI);
58 MBB->insert(MI, EarlierMI);
60 // Set up the two 64-bit registers.
61 MachineOperand &HighRegOp = EarlierMI->getOperand(0);
62 MachineOperand &LowRegOp = MI->getOperand(0);
63 HighRegOp.setReg(RI.getSubReg(HighRegOp.getReg(), SystemZ::subreg_h64));
64 LowRegOp.setReg(RI.getSubReg(LowRegOp.getReg(), SystemZ::subreg_l64));
66 // The address in the first (high) instruction is already correct.
67 // Adjust the offset in the second (low) instruction.
68 MachineOperand &HighOffsetOp = EarlierMI->getOperand(2);
69 MachineOperand &LowOffsetOp = MI->getOperand(2);
70 LowOffsetOp.setImm(LowOffsetOp.getImm() + 8);
73 unsigned HighOpcode = getOpcodeForOffset(NewOpcode, HighOffsetOp.getImm());
74 unsigned LowOpcode = getOpcodeForOffset(NewOpcode, LowOffsetOp.getImm());
75 assert(HighOpcode && LowOpcode && "Both offsets should be in range");
77 EarlierMI->setDesc(get(HighOpcode));
78 MI->setDesc(get(LowOpcode));
81 // Split ADJDYNALLOC instruction MI.
82 void SystemZInstrInfo::splitAdjDynAlloc(MachineBasicBlock::iterator MI) const {
83 MachineBasicBlock *MBB = MI->getParent();
84 MachineFunction &MF = *MBB->getParent();
85 MachineFrameInfo *MFFrame = MF.getFrameInfo();
86 MachineOperand &OffsetMO = MI->getOperand(2);
88 uint64_t Offset = (MFFrame->getMaxCallFrameSize() +
89 SystemZMC::CallFrameSize +
91 unsigned NewOpcode = getOpcodeForOffset(SystemZ::LA, Offset);
92 assert(NewOpcode && "No support for huge argument lists yet");
93 MI->setDesc(get(NewOpcode));
94 OffsetMO.setImm(Offset);
97 // MI is an RI-style pseudo instruction. Replace it with LowOpcode
98 // if the first operand is a low GR32 and HighOpcode if the first operand
99 // is a high GR32. ConvertHigh is true if LowOpcode takes a signed operand
100 // and HighOpcode takes an unsigned 32-bit operand. In those cases,
101 // MI has the same kind of operand as LowOpcode, so needs to be converted
102 // if HighOpcode is used.
103 void SystemZInstrInfo::expandRIPseudo(MachineInstr *MI, unsigned LowOpcode,
105 bool ConvertHigh) const {
106 unsigned Reg = MI->getOperand(0).getReg();
107 bool IsHigh = isHighReg(Reg);
108 MI->setDesc(get(IsHigh ? HighOpcode : LowOpcode));
109 if (IsHigh && ConvertHigh)
110 MI->getOperand(1).setImm(uint32_t(MI->getOperand(1).getImm()));
113 // MI is a three-operand RIE-style pseudo instruction. Replace it with
114 // LowOpcodeK if the registers are both low GR32s, otherwise use a move
115 // followed by HighOpcode or LowOpcode, depending on whether the target
116 // is a high or low GR32.
117 void SystemZInstrInfo::expandRIEPseudo(MachineInstr *MI, unsigned LowOpcode,
119 unsigned HighOpcode) const {
120 unsigned DestReg = MI->getOperand(0).getReg();
121 unsigned SrcReg = MI->getOperand(1).getReg();
122 bool DestIsHigh = isHighReg(DestReg);
123 bool SrcIsHigh = isHighReg(SrcReg);
124 if (!DestIsHigh && !SrcIsHigh)
125 MI->setDesc(get(LowOpcodeK));
127 emitGRX32Move(*MI->getParent(), MI, MI->getDebugLoc(),
128 DestReg, SrcReg, SystemZ::LR, 32,
129 MI->getOperand(1).isKill());
130 MI->setDesc(get(DestIsHigh ? HighOpcode : LowOpcode));
131 MI->getOperand(1).setReg(DestReg);
132 MI->tieOperands(0, 1);
136 // MI is an RXY-style pseudo instruction. Replace it with LowOpcode
137 // if the first operand is a low GR32 and HighOpcode if the first operand
139 void SystemZInstrInfo::expandRXYPseudo(MachineInstr *MI, unsigned LowOpcode,
140 unsigned HighOpcode) const {
141 unsigned Reg = MI->getOperand(0).getReg();
142 unsigned Opcode = getOpcodeForOffset(isHighReg(Reg) ? HighOpcode : LowOpcode,
143 MI->getOperand(2).getImm());
144 MI->setDesc(get(Opcode));
147 // MI is an RR-style pseudo instruction that zero-extends the low Size bits
148 // of one GRX32 into another. Replace it with LowOpcode if both operands
149 // are low registers, otherwise use RISB[LH]G.
150 void SystemZInstrInfo::expandZExtPseudo(MachineInstr *MI, unsigned LowOpcode,
151 unsigned Size) const {
152 emitGRX32Move(*MI->getParent(), MI, MI->getDebugLoc(),
153 MI->getOperand(0).getReg(), MI->getOperand(1).getReg(),
154 LowOpcode, Size, MI->getOperand(1).isKill());
155 MI->eraseFromParent();
158 // Emit a zero-extending move from 32-bit GPR SrcReg to 32-bit GPR
159 // DestReg before MBBI in MBB. Use LowLowOpcode when both DestReg and SrcReg
160 // are low registers, otherwise use RISB[LH]G. Size is the number of bits
161 // taken from the low end of SrcReg (8 for LLCR, 16 for LLHR and 32 for LR).
162 // KillSrc is true if this move is the last use of SrcReg.
163 void SystemZInstrInfo::emitGRX32Move(MachineBasicBlock &MBB,
164 MachineBasicBlock::iterator MBBI,
165 DebugLoc DL, unsigned DestReg,
166 unsigned SrcReg, unsigned LowLowOpcode,
167 unsigned Size, bool KillSrc) const {
169 bool DestIsHigh = isHighReg(DestReg);
170 bool SrcIsHigh = isHighReg(SrcReg);
171 if (DestIsHigh && SrcIsHigh)
172 Opcode = SystemZ::RISBHH;
173 else if (DestIsHigh && !SrcIsHigh)
174 Opcode = SystemZ::RISBHL;
175 else if (!DestIsHigh && SrcIsHigh)
176 Opcode = SystemZ::RISBLH;
178 BuildMI(MBB, MBBI, DL, get(LowLowOpcode), DestReg)
179 .addReg(SrcReg, getKillRegState(KillSrc));
182 unsigned Rotate = (DestIsHigh != SrcIsHigh ? 32 : 0);
183 BuildMI(MBB, MBBI, DL, get(Opcode), DestReg)
184 .addReg(DestReg, RegState::Undef)
185 .addReg(SrcReg, getKillRegState(KillSrc))
186 .addImm(32 - Size).addImm(128 + 31).addImm(Rotate);
189 // If MI is a simple load or store for a frame object, return the register
190 // it loads or stores and set FrameIndex to the index of the frame object.
191 // Return 0 otherwise.
193 // Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores.
194 static int isSimpleMove(const MachineInstr *MI, int &FrameIndex,
196 const MCInstrDesc &MCID = MI->getDesc();
197 if ((MCID.TSFlags & Flag) &&
198 MI->getOperand(1).isFI() &&
199 MI->getOperand(2).getImm() == 0 &&
200 MI->getOperand(3).getReg() == 0) {
201 FrameIndex = MI->getOperand(1).getIndex();
202 return MI->getOperand(0).getReg();
207 unsigned SystemZInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
208 int &FrameIndex) const {
209 return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXLoad);
212 unsigned SystemZInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
213 int &FrameIndex) const {
214 return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXStore);
217 bool SystemZInstrInfo::isStackSlotCopy(const MachineInstr *MI,
219 int &SrcFrameIndex) const {
220 // Check for MVC 0(Length,FI1),0(FI2)
221 const MachineFrameInfo *MFI = MI->getParent()->getParent()->getFrameInfo();
222 if (MI->getOpcode() != SystemZ::MVC ||
223 !MI->getOperand(0).isFI() ||
224 MI->getOperand(1).getImm() != 0 ||
225 !MI->getOperand(3).isFI() ||
226 MI->getOperand(4).getImm() != 0)
229 // Check that Length covers the full slots.
230 int64_t Length = MI->getOperand(2).getImm();
231 unsigned FI1 = MI->getOperand(0).getIndex();
232 unsigned FI2 = MI->getOperand(3).getIndex();
233 if (MFI->getObjectSize(FI1) != Length ||
234 MFI->getObjectSize(FI2) != Length)
237 DestFrameIndex = FI1;
242 bool SystemZInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
243 MachineBasicBlock *&TBB,
244 MachineBasicBlock *&FBB,
245 SmallVectorImpl<MachineOperand> &Cond,
246 bool AllowModify) const {
247 // Most of the code and comments here are boilerplate.
249 // Start from the bottom of the block and work up, examining the
250 // terminator instructions.
251 MachineBasicBlock::iterator I = MBB.end();
252 while (I != MBB.begin()) {
254 if (I->isDebugValue())
257 // Working from the bottom, when we see a non-terminator instruction, we're
259 if (!isUnpredicatedTerminator(I))
262 // A terminator that isn't a branch can't easily be handled by this
267 // Can't handle indirect branches.
268 SystemZII::Branch Branch(getBranchInfo(I));
269 if (!Branch.Target->isMBB())
272 // Punt on compound branches.
273 if (Branch.Type != SystemZII::BranchNormal)
276 if (Branch.CCMask == SystemZ::CCMASK_ANY) {
277 // Handle unconditional branches.
279 TBB = Branch.Target->getMBB();
283 // If the block has any instructions after a JMP, delete them.
284 while (std::next(I) != MBB.end())
285 std::next(I)->eraseFromParent();
290 // Delete the JMP if it's equivalent to a fall-through.
291 if (MBB.isLayoutSuccessor(Branch.Target->getMBB())) {
293 I->eraseFromParent();
298 // TBB is used to indicate the unconditinal destination.
299 TBB = Branch.Target->getMBB();
303 // Working from the bottom, handle the first conditional branch.
305 // FIXME: add X86-style branch swap
307 TBB = Branch.Target->getMBB();
308 Cond.push_back(MachineOperand::CreateImm(Branch.CCValid));
309 Cond.push_back(MachineOperand::CreateImm(Branch.CCMask));
313 // Handle subsequent conditional branches.
314 assert(Cond.size() == 2 && TBB && "Should have seen a conditional branch");
316 // Only handle the case where all conditional branches branch to the same
318 if (TBB != Branch.Target->getMBB())
321 // If the conditions are the same, we can leave them alone.
322 unsigned OldCCValid = Cond[0].getImm();
323 unsigned OldCCMask = Cond[1].getImm();
324 if (OldCCValid == Branch.CCValid && OldCCMask == Branch.CCMask)
327 // FIXME: Try combining conditions like X86 does. Should be easy on Z!
334 unsigned SystemZInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
335 // Most of the code and comments here are boilerplate.
336 MachineBasicBlock::iterator I = MBB.end();
339 while (I != MBB.begin()) {
341 if (I->isDebugValue())
345 if (!getBranchInfo(I).Target->isMBB())
347 // Remove the branch.
348 I->eraseFromParent();
356 bool SystemZInstrInfo::
357 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
358 assert(Cond.size() == 2 && "Invalid condition");
359 Cond[1].setImm(Cond[1].getImm() ^ Cond[0].getImm());
364 SystemZInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
365 MachineBasicBlock *FBB,
366 ArrayRef<MachineOperand> Cond,
368 // In this function we output 32-bit branches, which should always
369 // have enough range. They can be shortened and relaxed by later code
370 // in the pipeline, if desired.
372 // Shouldn't be a fall through.
373 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
374 assert((Cond.size() == 2 || Cond.size() == 0) &&
375 "SystemZ branch conditions have one component!");
378 // Unconditional branch?
379 assert(!FBB && "Unconditional branch with multiple successors!");
380 BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(TBB);
384 // Conditional branch.
386 unsigned CCValid = Cond[0].getImm();
387 unsigned CCMask = Cond[1].getImm();
388 BuildMI(&MBB, DL, get(SystemZ::BRC))
389 .addImm(CCValid).addImm(CCMask).addMBB(TBB);
393 // Two-way Conditional branch. Insert the second branch.
394 BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(FBB);
400 bool SystemZInstrInfo::analyzeCompare(const MachineInstr *MI,
401 unsigned &SrcReg, unsigned &SrcReg2,
402 int &Mask, int &Value) const {
403 assert(MI->isCompare() && "Caller should have checked for a comparison");
405 if (MI->getNumExplicitOperands() == 2 &&
406 MI->getOperand(0).isReg() &&
407 MI->getOperand(1).isImm()) {
408 SrcReg = MI->getOperand(0).getReg();
410 Value = MI->getOperand(1).getImm();
418 // If Reg is a virtual register, return its definition, otherwise return null.
419 static MachineInstr *getDef(unsigned Reg,
420 const MachineRegisterInfo *MRI) {
421 if (TargetRegisterInfo::isPhysicalRegister(Reg))
423 return MRI->getUniqueVRegDef(Reg);
426 // Return true if MI is a shift of type Opcode by Imm bits.
427 static bool isShift(MachineInstr *MI, unsigned Opcode, int64_t Imm) {
428 return (MI->getOpcode() == Opcode &&
429 !MI->getOperand(2).getReg() &&
430 MI->getOperand(3).getImm() == Imm);
433 // If the destination of MI has no uses, delete it as dead.
434 static void eraseIfDead(MachineInstr *MI, const MachineRegisterInfo *MRI) {
435 if (MRI->use_nodbg_empty(MI->getOperand(0).getReg()))
436 MI->eraseFromParent();
439 // Compare compares SrcReg against zero. Check whether SrcReg contains
440 // the result of an IPM sequence whose input CC survives until Compare,
441 // and whether Compare is therefore redundant. Delete it and return
443 static bool removeIPMBasedCompare(MachineInstr *Compare, unsigned SrcReg,
444 const MachineRegisterInfo *MRI,
445 const TargetRegisterInfo *TRI) {
446 MachineInstr *LGFR = nullptr;
447 MachineInstr *RLL = getDef(SrcReg, MRI);
448 if (RLL && RLL->getOpcode() == SystemZ::LGFR) {
450 RLL = getDef(LGFR->getOperand(1).getReg(), MRI);
452 if (!RLL || !isShift(RLL, SystemZ::RLL, 31))
455 MachineInstr *SRL = getDef(RLL->getOperand(1).getReg(), MRI);
456 if (!SRL || !isShift(SRL, SystemZ::SRL, SystemZ::IPM_CC))
459 MachineInstr *IPM = getDef(SRL->getOperand(1).getReg(), MRI);
460 if (!IPM || IPM->getOpcode() != SystemZ::IPM)
463 // Check that there are no assignments to CC between the IPM and Compare,
464 if (IPM->getParent() != Compare->getParent())
466 MachineBasicBlock::iterator MBBI = IPM, MBBE = Compare;
467 for (++MBBI; MBBI != MBBE; ++MBBI) {
468 MachineInstr *MI = MBBI;
469 if (MI->modifiesRegister(SystemZ::CC, TRI))
473 Compare->eraseFromParent();
475 eraseIfDead(LGFR, MRI);
476 eraseIfDead(RLL, MRI);
477 eraseIfDead(SRL, MRI);
478 eraseIfDead(IPM, MRI);
484 SystemZInstrInfo::optimizeCompareInstr(MachineInstr *Compare,
485 unsigned SrcReg, unsigned SrcReg2,
487 const MachineRegisterInfo *MRI) const {
488 assert(!SrcReg2 && "Only optimizing constant comparisons so far");
489 bool IsLogical = (Compare->getDesc().TSFlags & SystemZII::IsLogical) != 0;
492 removeIPMBasedCompare(Compare, SrcReg, MRI, &RI))
497 // If Opcode is a move that has a conditional variant, return that variant,
498 // otherwise return 0.
499 static unsigned getConditionalMove(unsigned Opcode) {
501 case SystemZ::LR: return SystemZ::LOCR;
502 case SystemZ::LGR: return SystemZ::LOCGR;
507 bool SystemZInstrInfo::isPredicable(MachineInstr *MI) const {
508 unsigned Opcode = MI->getOpcode();
509 if (STI.hasLoadStoreOnCond() &&
510 getConditionalMove(Opcode))
515 bool SystemZInstrInfo::
516 isProfitableToIfCvt(MachineBasicBlock &MBB,
517 unsigned NumCycles, unsigned ExtraPredCycles,
518 BranchProbability Probability) const {
519 // For now only convert single instructions.
520 return NumCycles == 1;
523 bool SystemZInstrInfo::
524 isProfitableToIfCvt(MachineBasicBlock &TMBB,
525 unsigned NumCyclesT, unsigned ExtraPredCyclesT,
526 MachineBasicBlock &FMBB,
527 unsigned NumCyclesF, unsigned ExtraPredCyclesF,
528 BranchProbability Probability) const {
529 // For now avoid converting mutually-exclusive cases.
533 bool SystemZInstrInfo::
534 PredicateInstruction(MachineInstr *MI, ArrayRef<MachineOperand> Pred) const {
535 assert(Pred.size() == 2 && "Invalid condition");
536 unsigned CCValid = Pred[0].getImm();
537 unsigned CCMask = Pred[1].getImm();
538 assert(CCMask > 0 && CCMask < 15 && "Invalid predicate");
539 unsigned Opcode = MI->getOpcode();
540 if (STI.hasLoadStoreOnCond()) {
541 if (unsigned CondOpcode = getConditionalMove(Opcode)) {
542 MI->setDesc(get(CondOpcode));
543 MachineInstrBuilder(*MI->getParent()->getParent(), MI)
544 .addImm(CCValid).addImm(CCMask)
545 .addReg(SystemZ::CC, RegState::Implicit);
552 void SystemZInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
553 MachineBasicBlock::iterator MBBI,
554 DebugLoc DL, unsigned DestReg,
555 unsigned SrcReg, bool KillSrc) const {
556 // Split 128-bit GPR moves into two 64-bit moves. This handles ADDR128 too.
557 if (SystemZ::GR128BitRegClass.contains(DestReg, SrcReg)) {
558 copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_h64),
559 RI.getSubReg(SrcReg, SystemZ::subreg_h64), KillSrc);
560 copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_l64),
561 RI.getSubReg(SrcReg, SystemZ::subreg_l64), KillSrc);
565 if (SystemZ::GRX32BitRegClass.contains(DestReg, SrcReg)) {
566 emitGRX32Move(MBB, MBBI, DL, DestReg, SrcReg, SystemZ::LR, 32, KillSrc);
570 // Everything else needs only one instruction.
572 if (SystemZ::GR64BitRegClass.contains(DestReg, SrcReg))
573 Opcode = SystemZ::LGR;
574 else if (SystemZ::FP32BitRegClass.contains(DestReg, SrcReg))
575 Opcode = SystemZ::LER;
576 else if (SystemZ::FP64BitRegClass.contains(DestReg, SrcReg))
577 Opcode = SystemZ::LDR;
578 else if (SystemZ::FP128BitRegClass.contains(DestReg, SrcReg))
579 Opcode = SystemZ::LXR;
580 else if (SystemZ::VR32BitRegClass.contains(DestReg, SrcReg))
581 Opcode = SystemZ::VLR32;
582 else if (SystemZ::VR64BitRegClass.contains(DestReg, SrcReg))
583 Opcode = SystemZ::VLR64;
584 else if (SystemZ::VR128BitRegClass.contains(DestReg, SrcReg))
585 Opcode = SystemZ::VLR;
587 llvm_unreachable("Impossible reg-to-reg copy");
589 BuildMI(MBB, MBBI, DL, get(Opcode), DestReg)
590 .addReg(SrcReg, getKillRegState(KillSrc));
593 void SystemZInstrInfo::storeRegToStackSlot(
594 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg,
595 bool isKill, int FrameIdx, const TargetRegisterClass *RC,
596 const TargetRegisterInfo *TRI) const {
597 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
599 // Callers may expect a single instruction, so keep 128-bit moves
600 // together for now and lower them after register allocation.
601 unsigned LoadOpcode, StoreOpcode;
602 getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode);
603 addFrameReference(BuildMI(MBB, MBBI, DL, get(StoreOpcode))
604 .addReg(SrcReg, getKillRegState(isKill)),
608 void SystemZInstrInfo::loadRegFromStackSlot(
609 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg,
610 int FrameIdx, const TargetRegisterClass *RC,
611 const TargetRegisterInfo *TRI) const {
612 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
614 // Callers may expect a single instruction, so keep 128-bit moves
615 // together for now and lower them after register allocation.
616 unsigned LoadOpcode, StoreOpcode;
617 getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode);
618 addFrameReference(BuildMI(MBB, MBBI, DL, get(LoadOpcode), DestReg),
622 // Return true if MI is a simple load or store with a 12-bit displacement
623 // and no index. Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores.
624 static bool isSimpleBD12Move(const MachineInstr *MI, unsigned Flag) {
625 const MCInstrDesc &MCID = MI->getDesc();
626 return ((MCID.TSFlags & Flag) &&
627 isUInt<12>(MI->getOperand(2).getImm()) &&
628 MI->getOperand(3).getReg() == 0);
633 LogicOp() : RegSize(0), ImmLSB(0), ImmSize(0) {}
634 LogicOp(unsigned regSize, unsigned immLSB, unsigned immSize)
635 : RegSize(regSize), ImmLSB(immLSB), ImmSize(immSize) {}
637 explicit operator bool() const { return RegSize; }
639 unsigned RegSize, ImmLSB, ImmSize;
641 } // end anonymous namespace
643 static LogicOp interpretAndImmediate(unsigned Opcode) {
645 case SystemZ::NILMux: return LogicOp(32, 0, 16);
646 case SystemZ::NIHMux: return LogicOp(32, 16, 16);
647 case SystemZ::NILL64: return LogicOp(64, 0, 16);
648 case SystemZ::NILH64: return LogicOp(64, 16, 16);
649 case SystemZ::NIHL64: return LogicOp(64, 32, 16);
650 case SystemZ::NIHH64: return LogicOp(64, 48, 16);
651 case SystemZ::NIFMux: return LogicOp(32, 0, 32);
652 case SystemZ::NILF64: return LogicOp(64, 0, 32);
653 case SystemZ::NIHF64: return LogicOp(64, 32, 32);
654 default: return LogicOp();
658 // Used to return from convertToThreeAddress after replacing two-address
659 // instruction OldMI with three-address instruction NewMI.
660 static MachineInstr *finishConvertToThreeAddress(MachineInstr *OldMI,
664 unsigned NumOps = OldMI->getNumOperands();
665 for (unsigned I = 1; I < NumOps; ++I) {
666 MachineOperand &Op = OldMI->getOperand(I);
667 if (Op.isReg() && Op.isKill())
668 LV->replaceKillInstruction(Op.getReg(), OldMI, NewMI);
675 SystemZInstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
676 MachineBasicBlock::iterator &MBBI,
677 LiveVariables *LV) const {
678 MachineInstr *MI = MBBI;
679 MachineBasicBlock *MBB = MI->getParent();
680 MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo();
682 unsigned Opcode = MI->getOpcode();
683 unsigned NumOps = MI->getNumOperands();
685 // Try to convert something like SLL into SLLK, if supported.
686 // We prefer to keep the two-operand form where possible both
687 // because it tends to be shorter and because some instructions
688 // have memory forms that can be used during spilling.
689 if (STI.hasDistinctOps()) {
690 MachineOperand &Dest = MI->getOperand(0);
691 MachineOperand &Src = MI->getOperand(1);
692 unsigned DestReg = Dest.getReg();
693 unsigned SrcReg = Src.getReg();
694 // AHIMux is only really a three-operand instruction when both operands
695 // are low registers. Try to constrain both operands to be low if
697 if (Opcode == SystemZ::AHIMux &&
698 TargetRegisterInfo::isVirtualRegister(DestReg) &&
699 TargetRegisterInfo::isVirtualRegister(SrcReg) &&
700 MRI.getRegClass(DestReg)->contains(SystemZ::R1L) &&
701 MRI.getRegClass(SrcReg)->contains(SystemZ::R1L)) {
702 MRI.constrainRegClass(DestReg, &SystemZ::GR32BitRegClass);
703 MRI.constrainRegClass(SrcReg, &SystemZ::GR32BitRegClass);
705 int ThreeOperandOpcode = SystemZ::getThreeOperandOpcode(Opcode);
706 if (ThreeOperandOpcode >= 0) {
707 MachineInstrBuilder MIB =
708 BuildMI(*MBB, MBBI, MI->getDebugLoc(), get(ThreeOperandOpcode))
710 // Keep the kill state, but drop the tied flag.
711 MIB.addReg(Src.getReg(), getKillRegState(Src.isKill()), Src.getSubReg());
712 // Keep the remaining operands as-is.
713 for (unsigned I = 2; I < NumOps; ++I)
714 MIB.addOperand(MI->getOperand(I));
715 return finishConvertToThreeAddress(MI, MIB, LV);
719 // Try to convert an AND into an RISBG-type instruction.
720 if (LogicOp And = interpretAndImmediate(Opcode)) {
721 uint64_t Imm = MI->getOperand(2).getImm() << And.ImmLSB;
722 // AND IMMEDIATE leaves the other bits of the register unchanged.
723 Imm |= allOnes(And.RegSize) & ~(allOnes(And.ImmSize) << And.ImmLSB);
725 if (isRxSBGMask(Imm, And.RegSize, Start, End)) {
727 if (And.RegSize == 64) {
728 NewOpcode = SystemZ::RISBG;
729 // Prefer RISBGN if available, since it does not clobber CC.
730 if (STI.hasMiscellaneousExtensions())
731 NewOpcode = SystemZ::RISBGN;
733 NewOpcode = SystemZ::RISBMux;
737 MachineOperand &Dest = MI->getOperand(0);
738 MachineOperand &Src = MI->getOperand(1);
739 MachineInstrBuilder MIB =
740 BuildMI(*MBB, MI, MI->getDebugLoc(), get(NewOpcode))
741 .addOperand(Dest).addReg(0)
742 .addReg(Src.getReg(), getKillRegState(Src.isKill()), Src.getSubReg())
743 .addImm(Start).addImm(End + 128).addImm(0);
744 return finishConvertToThreeAddress(MI, MIB, LV);
750 MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl(
751 MachineFunction &MF, MachineInstr *MI, ArrayRef<unsigned> Ops,
752 MachineBasicBlock::iterator InsertPt, int FrameIndex) const {
753 const MachineFrameInfo *MFI = MF.getFrameInfo();
754 unsigned Size = MFI->getObjectSize(FrameIndex);
755 unsigned Opcode = MI->getOpcode();
757 if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) {
758 if ((Opcode == SystemZ::LA || Opcode == SystemZ::LAY) &&
759 isInt<8>(MI->getOperand(2).getImm()) &&
760 !MI->getOperand(3).getReg()) {
761 // LA(Y) %reg, CONST(%reg) -> AGSI %mem, CONST
762 return BuildMI(*InsertPt->getParent(), InsertPt, MI->getDebugLoc(),
764 .addFrameIndex(FrameIndex)
766 .addImm(MI->getOperand(2).getImm());
771 // All other cases require a single operand.
775 unsigned OpNum = Ops[0];
776 assert(Size == MF.getRegInfo()
777 .getRegClass(MI->getOperand(OpNum).getReg())->getSize() &&
778 "Invalid size combination");
780 if ((Opcode == SystemZ::AHI || Opcode == SystemZ::AGHI) &&
782 isInt<8>(MI->getOperand(2).getImm())) {
783 // A(G)HI %reg, CONST -> A(G)SI %mem, CONST
784 Opcode = (Opcode == SystemZ::AHI ? SystemZ::ASI : SystemZ::AGSI);
785 return BuildMI(*InsertPt->getParent(), InsertPt, MI->getDebugLoc(),
787 .addFrameIndex(FrameIndex)
789 .addImm(MI->getOperand(2).getImm());
792 if (Opcode == SystemZ::LGDR || Opcode == SystemZ::LDGR) {
793 bool Op0IsGPR = (Opcode == SystemZ::LGDR);
794 bool Op1IsGPR = (Opcode == SystemZ::LDGR);
795 // If we're spilling the destination of an LDGR or LGDR, store the
796 // source register instead.
798 unsigned StoreOpcode = Op1IsGPR ? SystemZ::STG : SystemZ::STD;
799 return BuildMI(*InsertPt->getParent(), InsertPt, MI->getDebugLoc(),
801 .addOperand(MI->getOperand(1))
802 .addFrameIndex(FrameIndex)
806 // If we're spilling the source of an LDGR or LGDR, load the
807 // destination register instead.
809 unsigned LoadOpcode = Op0IsGPR ? SystemZ::LG : SystemZ::LD;
810 unsigned Dest = MI->getOperand(0).getReg();
811 return BuildMI(*InsertPt->getParent(), InsertPt, MI->getDebugLoc(),
812 get(LoadOpcode), Dest)
813 .addFrameIndex(FrameIndex)
819 // Look for cases where the source of a simple store or the destination
820 // of a simple load is being spilled. Try to use MVC instead.
822 // Although MVC is in practice a fast choice in these cases, it is still
823 // logically a bytewise copy. This means that we cannot use it if the
824 // load or store is volatile. We also wouldn't be able to use MVC if
825 // the two memories partially overlap, but that case cannot occur here,
826 // because we know that one of the memories is a full frame index.
828 // For performance reasons, we also want to avoid using MVC if the addresses
829 // might be equal. We don't worry about that case here, because spill slot
830 // coloring happens later, and because we have special code to remove
831 // MVCs that turn out to be redundant.
832 if (OpNum == 0 && MI->hasOneMemOperand()) {
833 MachineMemOperand *MMO = *MI->memoperands_begin();
834 if (MMO->getSize() == Size && !MMO->isVolatile()) {
835 // Handle conversion of loads.
836 if (isSimpleBD12Move(MI, SystemZII::SimpleBDXLoad)) {
837 return BuildMI(*InsertPt->getParent(), InsertPt, MI->getDebugLoc(),
839 .addFrameIndex(FrameIndex)
842 .addOperand(MI->getOperand(1))
843 .addImm(MI->getOperand(2).getImm())
846 // Handle conversion of stores.
847 if (isSimpleBD12Move(MI, SystemZII::SimpleBDXStore)) {
848 return BuildMI(*InsertPt->getParent(), InsertPt, MI->getDebugLoc(),
850 .addOperand(MI->getOperand(1))
851 .addImm(MI->getOperand(2).getImm())
853 .addFrameIndex(FrameIndex)
860 // If the spilled operand is the final one, try to change <INSN>R
862 int MemOpcode = SystemZ::getMemOpcode(Opcode);
863 if (MemOpcode >= 0) {
864 unsigned NumOps = MI->getNumExplicitOperands();
865 if (OpNum == NumOps - 1) {
866 const MCInstrDesc &MemDesc = get(MemOpcode);
867 uint64_t AccessBytes = SystemZII::getAccessSize(MemDesc.TSFlags);
868 assert(AccessBytes != 0 && "Size of access should be known");
869 assert(AccessBytes <= Size && "Access outside the frame index");
870 uint64_t Offset = Size - AccessBytes;
871 MachineInstrBuilder MIB = BuildMI(*InsertPt->getParent(), InsertPt,
872 MI->getDebugLoc(), get(MemOpcode));
873 for (unsigned I = 0; I < OpNum; ++I)
874 MIB.addOperand(MI->getOperand(I));
875 MIB.addFrameIndex(FrameIndex).addImm(Offset);
876 if (MemDesc.TSFlags & SystemZII::HasIndex)
885 MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl(
886 MachineFunction &MF, MachineInstr *MI, ArrayRef<unsigned> Ops,
887 MachineBasicBlock::iterator InsertPt, MachineInstr *LoadMI) const {
892 SystemZInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const {
893 switch (MI->getOpcode()) {
895 splitMove(MI, SystemZ::LG);
899 splitMove(MI, SystemZ::STG);
903 splitMove(MI, SystemZ::LD);
907 splitMove(MI, SystemZ::STD);
911 expandRXYPseudo(MI, SystemZ::LB, SystemZ::LBH);
915 expandRXYPseudo(MI, SystemZ::LH, SystemZ::LHH);
918 case SystemZ::LLCRMux:
919 expandZExtPseudo(MI, SystemZ::LLCR, 8);
922 case SystemZ::LLHRMux:
923 expandZExtPseudo(MI, SystemZ::LLHR, 16);
926 case SystemZ::LLCMux:
927 expandRXYPseudo(MI, SystemZ::LLC, SystemZ::LLCH);
930 case SystemZ::LLHMux:
931 expandRXYPseudo(MI, SystemZ::LLH, SystemZ::LLHH);
935 expandRXYPseudo(MI, SystemZ::L, SystemZ::LFH);
938 case SystemZ::STCMux:
939 expandRXYPseudo(MI, SystemZ::STC, SystemZ::STCH);
942 case SystemZ::STHMux:
943 expandRXYPseudo(MI, SystemZ::STH, SystemZ::STHH);
947 expandRXYPseudo(MI, SystemZ::ST, SystemZ::STFH);
950 case SystemZ::LHIMux:
951 expandRIPseudo(MI, SystemZ::LHI, SystemZ::IIHF, true);
954 case SystemZ::IIFMux:
955 expandRIPseudo(MI, SystemZ::IILF, SystemZ::IIHF, false);
958 case SystemZ::IILMux:
959 expandRIPseudo(MI, SystemZ::IILL, SystemZ::IIHL, false);
962 case SystemZ::IIHMux:
963 expandRIPseudo(MI, SystemZ::IILH, SystemZ::IIHH, false);
966 case SystemZ::NIFMux:
967 expandRIPseudo(MI, SystemZ::NILF, SystemZ::NIHF, false);
970 case SystemZ::NILMux:
971 expandRIPseudo(MI, SystemZ::NILL, SystemZ::NIHL, false);
974 case SystemZ::NIHMux:
975 expandRIPseudo(MI, SystemZ::NILH, SystemZ::NIHH, false);
978 case SystemZ::OIFMux:
979 expandRIPseudo(MI, SystemZ::OILF, SystemZ::OIHF, false);
982 case SystemZ::OILMux:
983 expandRIPseudo(MI, SystemZ::OILL, SystemZ::OIHL, false);
986 case SystemZ::OIHMux:
987 expandRIPseudo(MI, SystemZ::OILH, SystemZ::OIHH, false);
990 case SystemZ::XIFMux:
991 expandRIPseudo(MI, SystemZ::XILF, SystemZ::XIHF, false);
994 case SystemZ::TMLMux:
995 expandRIPseudo(MI, SystemZ::TMLL, SystemZ::TMHL, false);
998 case SystemZ::TMHMux:
999 expandRIPseudo(MI, SystemZ::TMLH, SystemZ::TMHH, false);
1002 case SystemZ::AHIMux:
1003 expandRIPseudo(MI, SystemZ::AHI, SystemZ::AIH, false);
1006 case SystemZ::AHIMuxK:
1007 expandRIEPseudo(MI, SystemZ::AHI, SystemZ::AHIK, SystemZ::AIH);
1010 case SystemZ::AFIMux:
1011 expandRIPseudo(MI, SystemZ::AFI, SystemZ::AIH, false);
1014 case SystemZ::CFIMux:
1015 expandRIPseudo(MI, SystemZ::CFI, SystemZ::CIH, false);
1018 case SystemZ::CLFIMux:
1019 expandRIPseudo(MI, SystemZ::CLFI, SystemZ::CLIH, false);
1023 expandRXYPseudo(MI, SystemZ::C, SystemZ::CHF);
1026 case SystemZ::CLMux:
1027 expandRXYPseudo(MI, SystemZ::CL, SystemZ::CLHF);
1030 case SystemZ::RISBMux: {
1031 bool DestIsHigh = isHighReg(MI->getOperand(0).getReg());
1032 bool SrcIsHigh = isHighReg(MI->getOperand(2).getReg());
1033 if (SrcIsHigh == DestIsHigh)
1034 MI->setDesc(get(DestIsHigh ? SystemZ::RISBHH : SystemZ::RISBLL));
1036 MI->setDesc(get(DestIsHigh ? SystemZ::RISBHL : SystemZ::RISBLH));
1037 MI->getOperand(5).setImm(MI->getOperand(5).getImm() ^ 32);
1042 case SystemZ::ADJDYNALLOC:
1043 splitAdjDynAlloc(MI);
1051 uint64_t SystemZInstrInfo::getInstSizeInBytes(const MachineInstr *MI) const {
1052 if (MI->getOpcode() == TargetOpcode::INLINEASM) {
1053 const MachineFunction *MF = MI->getParent()->getParent();
1054 const char *AsmStr = MI->getOperand(0).getSymbolName();
1055 return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
1057 return MI->getDesc().getSize();
1061 SystemZInstrInfo::getBranchInfo(const MachineInstr *MI) const {
1062 switch (MI->getOpcode()) {
1066 return SystemZII::Branch(SystemZII::BranchNormal, SystemZ::CCMASK_ANY,
1067 SystemZ::CCMASK_ANY, &MI->getOperand(0));
1071 return SystemZII::Branch(SystemZII::BranchNormal,
1072 MI->getOperand(0).getImm(),
1073 MI->getOperand(1).getImm(), &MI->getOperand(2));
1076 return SystemZII::Branch(SystemZII::BranchCT, SystemZ::CCMASK_ICMP,
1077 SystemZ::CCMASK_CMP_NE, &MI->getOperand(2));
1079 case SystemZ::BRCTG:
1080 return SystemZII::Branch(SystemZII::BranchCTG, SystemZ::CCMASK_ICMP,
1081 SystemZ::CCMASK_CMP_NE, &MI->getOperand(2));
1085 return SystemZII::Branch(SystemZII::BranchC, SystemZ::CCMASK_ICMP,
1086 MI->getOperand(2).getImm(), &MI->getOperand(3));
1090 return SystemZII::Branch(SystemZII::BranchCL, SystemZ::CCMASK_ICMP,
1091 MI->getOperand(2).getImm(), &MI->getOperand(3));
1095 return SystemZII::Branch(SystemZII::BranchCG, SystemZ::CCMASK_ICMP,
1096 MI->getOperand(2).getImm(), &MI->getOperand(3));
1098 case SystemZ::CLGIJ:
1099 case SystemZ::CLGRJ:
1100 return SystemZII::Branch(SystemZII::BranchCLG, SystemZ::CCMASK_ICMP,
1101 MI->getOperand(2).getImm(), &MI->getOperand(3));
1104 llvm_unreachable("Unrecognized branch opcode");
1108 void SystemZInstrInfo::getLoadStoreOpcodes(const TargetRegisterClass *RC,
1109 unsigned &LoadOpcode,
1110 unsigned &StoreOpcode) const {
1111 if (RC == &SystemZ::GR32BitRegClass || RC == &SystemZ::ADDR32BitRegClass) {
1112 LoadOpcode = SystemZ::L;
1113 StoreOpcode = SystemZ::ST;
1114 } else if (RC == &SystemZ::GRH32BitRegClass) {
1115 LoadOpcode = SystemZ::LFH;
1116 StoreOpcode = SystemZ::STFH;
1117 } else if (RC == &SystemZ::GRX32BitRegClass) {
1118 LoadOpcode = SystemZ::LMux;
1119 StoreOpcode = SystemZ::STMux;
1120 } else if (RC == &SystemZ::GR64BitRegClass ||
1121 RC == &SystemZ::ADDR64BitRegClass) {
1122 LoadOpcode = SystemZ::LG;
1123 StoreOpcode = SystemZ::STG;
1124 } else if (RC == &SystemZ::GR128BitRegClass ||
1125 RC == &SystemZ::ADDR128BitRegClass) {
1126 LoadOpcode = SystemZ::L128;
1127 StoreOpcode = SystemZ::ST128;
1128 } else if (RC == &SystemZ::FP32BitRegClass) {
1129 LoadOpcode = SystemZ::LE;
1130 StoreOpcode = SystemZ::STE;
1131 } else if (RC == &SystemZ::FP64BitRegClass) {
1132 LoadOpcode = SystemZ::LD;
1133 StoreOpcode = SystemZ::STD;
1134 } else if (RC == &SystemZ::FP128BitRegClass) {
1135 LoadOpcode = SystemZ::LX;
1136 StoreOpcode = SystemZ::STX;
1137 } else if (RC == &SystemZ::VR32BitRegClass) {
1138 LoadOpcode = SystemZ::VL32;
1139 StoreOpcode = SystemZ::VST32;
1140 } else if (RC == &SystemZ::VR64BitRegClass) {
1141 LoadOpcode = SystemZ::VL64;
1142 StoreOpcode = SystemZ::VST64;
1143 } else if (RC == &SystemZ::VF128BitRegClass ||
1144 RC == &SystemZ::VR128BitRegClass) {
1145 LoadOpcode = SystemZ::VL;
1146 StoreOpcode = SystemZ::VST;
1148 llvm_unreachable("Unsupported regclass to load or store");
1151 unsigned SystemZInstrInfo::getOpcodeForOffset(unsigned Opcode,
1152 int64_t Offset) const {
1153 const MCInstrDesc &MCID = get(Opcode);
1154 int64_t Offset2 = (MCID.TSFlags & SystemZII::Is128Bit ? Offset + 8 : Offset);
1155 if (isUInt<12>(Offset) && isUInt<12>(Offset2)) {
1156 // Get the instruction to use for unsigned 12-bit displacements.
1157 int Disp12Opcode = SystemZ::getDisp12Opcode(Opcode);
1158 if (Disp12Opcode >= 0)
1159 return Disp12Opcode;
1161 // All address-related instructions can use unsigned 12-bit
1165 if (isInt<20>(Offset) && isInt<20>(Offset2)) {
1166 // Get the instruction to use for signed 20-bit displacements.
1167 int Disp20Opcode = SystemZ::getDisp20Opcode(Opcode);
1168 if (Disp20Opcode >= 0)
1169 return Disp20Opcode;
1171 // Check whether Opcode allows signed 20-bit displacements.
1172 if (MCID.TSFlags & SystemZII::Has20BitOffset)
1178 unsigned SystemZInstrInfo::getLoadAndTest(unsigned Opcode) const {
1180 case SystemZ::L: return SystemZ::LT;
1181 case SystemZ::LY: return SystemZ::LT;
1182 case SystemZ::LG: return SystemZ::LTG;
1183 case SystemZ::LGF: return SystemZ::LTGF;
1184 case SystemZ::LR: return SystemZ::LTR;
1185 case SystemZ::LGFR: return SystemZ::LTGFR;
1186 case SystemZ::LGR: return SystemZ::LTGR;
1187 case SystemZ::LER: return SystemZ::LTEBR;
1188 case SystemZ::LDR: return SystemZ::LTDBR;
1189 case SystemZ::LXR: return SystemZ::LTXBR;
1190 case SystemZ::LCDFR: return SystemZ::LCDBR;
1191 case SystemZ::LPDFR: return SystemZ::LPDBR;
1192 case SystemZ::LNDFR: return SystemZ::LNDBR;
1193 case SystemZ::LCDFR_32: return SystemZ::LCEBR;
1194 case SystemZ::LPDFR_32: return SystemZ::LPEBR;
1195 case SystemZ::LNDFR_32: return SystemZ::LNEBR;
1196 // On zEC12 we prefer to use RISBGN. But if there is a chance to
1197 // actually use the condition code, we may turn it back into RISGB.
1198 // Note that RISBG is not really a "load-and-test" instruction,
1199 // but sets the same condition code values, so is OK to use here.
1200 case SystemZ::RISBGN: return SystemZ::RISBG;
1205 // Return true if Mask matches the regexp 0*1+0*, given that zero masks
1206 // have already been filtered out. Store the first set bit in LSB and
1207 // the number of set bits in Length if so.
1208 static bool isStringOfOnes(uint64_t Mask, unsigned &LSB, unsigned &Length) {
1209 unsigned First = findFirstSet(Mask);
1210 uint64_t Top = (Mask >> First) + 1;
1211 if ((Top & -Top) == Top) {
1213 Length = findFirstSet(Top);
1219 bool SystemZInstrInfo::isRxSBGMask(uint64_t Mask, unsigned BitSize,
1220 unsigned &Start, unsigned &End) const {
1221 // Reject trivial all-zero masks.
1222 Mask &= allOnes(BitSize);
1226 // Handle the 1+0+ or 0+1+0* cases. Start then specifies the index of
1227 // the msb and End specifies the index of the lsb.
1228 unsigned LSB, Length;
1229 if (isStringOfOnes(Mask, LSB, Length)) {
1230 Start = 63 - (LSB + Length - 1);
1235 // Handle the wrap-around 1+0+1+ cases. Start then specifies the msb
1236 // of the low 1s and End specifies the lsb of the high 1s.
1237 if (isStringOfOnes(Mask ^ allOnes(BitSize), LSB, Length)) {
1238 assert(LSB > 0 && "Bottom bit must be set");
1239 assert(LSB + Length < BitSize && "Top bit must be set");
1240 Start = 63 - (LSB - 1);
1241 End = 63 - (LSB + Length);
1248 unsigned SystemZInstrInfo::getCompareAndBranch(unsigned Opcode,
1249 const MachineInstr *MI) const {
1252 return SystemZ::CRJ;
1254 return SystemZ::CGRJ;
1256 return MI && isInt<8>(MI->getOperand(1).getImm()) ? SystemZ::CIJ : 0;
1258 return MI && isInt<8>(MI->getOperand(1).getImm()) ? SystemZ::CGIJ : 0;
1260 return SystemZ::CLRJ;
1262 return SystemZ::CLGRJ;
1264 return MI && isUInt<8>(MI->getOperand(1).getImm()) ? SystemZ::CLIJ : 0;
1265 case SystemZ::CLGFI:
1266 return MI && isUInt<8>(MI->getOperand(1).getImm()) ? SystemZ::CLGIJ : 0;
1272 void SystemZInstrInfo::loadImmediate(MachineBasicBlock &MBB,
1273 MachineBasicBlock::iterator MBBI,
1274 unsigned Reg, uint64_t Value) const {
1275 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
1277 if (isInt<16>(Value))
1278 Opcode = SystemZ::LGHI;
1279 else if (SystemZ::isImmLL(Value))
1280 Opcode = SystemZ::LLILL;
1281 else if (SystemZ::isImmLH(Value)) {
1282 Opcode = SystemZ::LLILH;
1285 assert(isInt<32>(Value) && "Huge values not handled yet");
1286 Opcode = SystemZ::LGFI;
1288 BuildMI(MBB, MBBI, DL, get(Opcode), Reg).addImm(Value);