blob: 8dbd9df32b7e79037d62c136ad6603509141623f [file] [log] [blame]
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001//===-- SystemZInstrInfo.cpp - SystemZ instruction information ------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the SystemZ implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SystemZInstrInfo.h"
15#include "SystemZInstrBuilder.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000016#include "SystemZTargetMachine.h"
Richard Sandifordff6c5a52013-07-19 16:12:08 +000017#include "llvm/CodeGen/LiveVariables.h"
Richard Sandifordf6bae1e2013-07-02 15:28:56 +000018#include "llvm/CodeGen/MachineRegisterInfo.h"
Ulrich Weigand5f613df2013-05-06 16:15:19 +000019
Chandler Carruthd174b722014-04-22 02:03:14 +000020using namespace llvm;
21
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000022#define GET_INSTRINFO_CTOR_DTOR
Ulrich Weigand5f613df2013-05-06 16:15:19 +000023#define GET_INSTRMAP_INFO
24#include "SystemZGenInstrInfo.inc"
25
Richard Sandiford6a06ba32013-07-31 11:36:35 +000026// Return a mask with Count low bits set.
27static uint64_t allOnes(unsigned int Count) {
28 return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1;
29}
30
Richard Sandiford0755c932013-10-01 11:26:28 +000031// Reg should be a 32-bit GPR. Return true if it is a high register rather
32// than a low register.
33static bool isHighReg(unsigned int Reg) {
34 if (SystemZ::GRH32BitRegClass.contains(Reg))
35 return true;
36 assert(SystemZ::GR32BitRegClass.contains(Reg) && "Invalid GRX32");
37 return false;
38}
39
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000040// Pin the vtable to this file.
41void SystemZInstrInfo::anchor() {}
42
Eric Christopher673b3af2014-06-27 07:01:17 +000043SystemZInstrInfo::SystemZInstrInfo(SystemZSubtarget &sti)
Ulrich Weigand5f613df2013-05-06 16:15:19 +000044 : SystemZGenInstrInfo(SystemZ::ADJCALLSTACKDOWN, SystemZ::ADJCALLSTACKUP),
Eric Christopher673b3af2014-06-27 07:01:17 +000045 RI(), STI(sti) {
Ulrich Weigand5f613df2013-05-06 16:15:19 +000046}
47
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.
50void SystemZInstrInfo::splitMove(MachineBasicBlock::iterator MI,
51 unsigned NewOpcode) const {
52 MachineBasicBlock *MBB = MI->getParent();
53 MachineFunction &MF = *MBB->getParent();
54
55 // Get two load or store instructions. Use the original instruction for one
Alp Tokercb402912014-01-24 17:20:08 +000056 // of them (arbitrarily the second here) and create a clone for the other.
Ulrich Weigand5f613df2013-05-06 16:15:19 +000057 MachineInstr *EarlierMI = MF.CloneMachineInstr(MI);
58 MBB->insert(MI, EarlierMI);
59
60 // Set up the two 64-bit registers.
61 MachineOperand &HighRegOp = EarlierMI->getOperand(0);
62 MachineOperand &LowRegOp = MI->getOperand(0);
Richard Sandiford87a44362013-09-30 10:28:35 +000063 HighRegOp.setReg(RI.getSubReg(HighRegOp.getReg(), SystemZ::subreg_h64));
64 LowRegOp.setReg(RI.getSubReg(LowRegOp.getReg(), SystemZ::subreg_l64));
Ulrich Weigand5f613df2013-05-06 16:15:19 +000065
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);
71
72 // Set the opcodes.
73 unsigned HighOpcode = getOpcodeForOffset(NewOpcode, HighOffsetOp.getImm());
74 unsigned LowOpcode = getOpcodeForOffset(NewOpcode, LowOffsetOp.getImm());
75 assert(HighOpcode && LowOpcode && "Both offsets should be in range");
76
77 EarlierMI->setDesc(get(HighOpcode));
78 MI->setDesc(get(LowOpcode));
79}
80
81// Split ADJDYNALLOC instruction MI.
82void 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);
87
88 uint64_t Offset = (MFFrame->getMaxCallFrameSize() +
89 SystemZMC::CallFrameSize +
90 OffsetMO.getImm());
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);
95}
96
Richard Sandiford01240232013-10-01 13:02:28 +000097// 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.
103void SystemZInstrInfo::expandRIPseudo(MachineInstr *MI, unsigned LowOpcode,
104 unsigned HighOpcode,
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()));
111}
112
Richard Sandiford42a694f2013-10-01 14:53:46 +0000113// MI is a three-operand RIE-style pseudo instruction. Replace it with
114// LowOpcode3 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.
117void SystemZInstrInfo::expandRIEPseudo(MachineInstr *MI, unsigned LowOpcode,
118 unsigned LowOpcodeK,
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));
126 else {
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 }
133}
134
Richard Sandiford0755c932013-10-01 11:26:28 +0000135// MI is an RXY-style pseudo instruction. Replace it with LowOpcode
136// if the first operand is a low GR32 and HighOpcode if the first operand
137// is a high GR32.
138void SystemZInstrInfo::expandRXYPseudo(MachineInstr *MI, unsigned LowOpcode,
139 unsigned HighOpcode) const {
140 unsigned Reg = MI->getOperand(0).getReg();
141 unsigned Opcode = getOpcodeForOffset(isHighReg(Reg) ? HighOpcode : LowOpcode,
142 MI->getOperand(2).getImm());
143 MI->setDesc(get(Opcode));
144}
145
Richard Sandiford21235a22013-10-01 12:49:07 +0000146// MI is an RR-style pseudo instruction that zero-extends the low Size bits
147// of one GRX32 into another. Replace it with LowOpcode if both operands
148// are low registers, otherwise use RISB[LH]G.
149void SystemZInstrInfo::expandZExtPseudo(MachineInstr *MI, unsigned LowOpcode,
150 unsigned Size) const {
151 emitGRX32Move(*MI->getParent(), MI, MI->getDebugLoc(),
152 MI->getOperand(0).getReg(), MI->getOperand(1).getReg(),
153 LowOpcode, Size, MI->getOperand(1).isKill());
154 MI->eraseFromParent();
155}
156
Richard Sandiford0755c932013-10-01 11:26:28 +0000157// Emit a zero-extending move from 32-bit GPR SrcReg to 32-bit GPR
158// DestReg before MBBI in MBB. Use LowLowOpcode when both DestReg and SrcReg
159// are low registers, otherwise use RISB[LH]G. Size is the number of bits
160// taken from the low end of SrcReg (8 for LLCR, 16 for LLHR and 32 for LR).
161// KillSrc is true if this move is the last use of SrcReg.
162void SystemZInstrInfo::emitGRX32Move(MachineBasicBlock &MBB,
163 MachineBasicBlock::iterator MBBI,
164 DebugLoc DL, unsigned DestReg,
165 unsigned SrcReg, unsigned LowLowOpcode,
166 unsigned Size, bool KillSrc) const {
167 unsigned Opcode;
168 bool DestIsHigh = isHighReg(DestReg);
169 bool SrcIsHigh = isHighReg(SrcReg);
170 if (DestIsHigh && SrcIsHigh)
171 Opcode = SystemZ::RISBHH;
172 else if (DestIsHigh && !SrcIsHigh)
173 Opcode = SystemZ::RISBHL;
174 else if (!DestIsHigh && SrcIsHigh)
175 Opcode = SystemZ::RISBLH;
176 else {
177 BuildMI(MBB, MBBI, DL, get(LowLowOpcode), DestReg)
178 .addReg(SrcReg, getKillRegState(KillSrc));
179 return;
180 }
181 unsigned Rotate = (DestIsHigh != SrcIsHigh ? 32 : 0);
182 BuildMI(MBB, MBBI, DL, get(Opcode), DestReg)
183 .addReg(DestReg, RegState::Undef)
184 .addReg(SrcReg, getKillRegState(KillSrc))
185 .addImm(32 - Size).addImm(128 + 31).addImm(Rotate);
186}
187
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000188// If MI is a simple load or store for a frame object, return the register
189// it loads or stores and set FrameIndex to the index of the frame object.
190// Return 0 otherwise.
191//
192// Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores.
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000193static int isSimpleMove(const MachineInstr *MI, int &FrameIndex,
194 unsigned Flag) {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000195 const MCInstrDesc &MCID = MI->getDesc();
196 if ((MCID.TSFlags & Flag) &&
197 MI->getOperand(1).isFI() &&
198 MI->getOperand(2).getImm() == 0 &&
199 MI->getOperand(3).getReg() == 0) {
200 FrameIndex = MI->getOperand(1).getIndex();
201 return MI->getOperand(0).getReg();
202 }
203 return 0;
204}
205
206unsigned SystemZInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
207 int &FrameIndex) const {
208 return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXLoad);
209}
210
211unsigned SystemZInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
212 int &FrameIndex) const {
213 return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXStore);
214}
215
Richard Sandifordc40f27b2013-07-05 14:38:48 +0000216bool SystemZInstrInfo::isStackSlotCopy(const MachineInstr *MI,
217 int &DestFrameIndex,
218 int &SrcFrameIndex) const {
219 // Check for MVC 0(Length,FI1),0(FI2)
220 const MachineFrameInfo *MFI = MI->getParent()->getParent()->getFrameInfo();
221 if (MI->getOpcode() != SystemZ::MVC ||
222 !MI->getOperand(0).isFI() ||
223 MI->getOperand(1).getImm() != 0 ||
224 !MI->getOperand(3).isFI() ||
225 MI->getOperand(4).getImm() != 0)
226 return false;
227
228 // Check that Length covers the full slots.
229 int64_t Length = MI->getOperand(2).getImm();
230 unsigned FI1 = MI->getOperand(0).getIndex();
231 unsigned FI2 = MI->getOperand(3).getIndex();
232 if (MFI->getObjectSize(FI1) != Length ||
233 MFI->getObjectSize(FI2) != Length)
234 return false;
235
236 DestFrameIndex = FI1;
237 SrcFrameIndex = FI2;
238 return true;
239}
240
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000241bool SystemZInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
242 MachineBasicBlock *&TBB,
243 MachineBasicBlock *&FBB,
244 SmallVectorImpl<MachineOperand> &Cond,
245 bool AllowModify) const {
246 // Most of the code and comments here are boilerplate.
247
248 // Start from the bottom of the block and work up, examining the
249 // terminator instructions.
250 MachineBasicBlock::iterator I = MBB.end();
251 while (I != MBB.begin()) {
252 --I;
253 if (I->isDebugValue())
254 continue;
255
256 // Working from the bottom, when we see a non-terminator instruction, we're
257 // done.
258 if (!isUnpredicatedTerminator(I))
259 break;
260
261 // A terminator that isn't a branch can't easily be handled by this
262 // analysis.
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000263 if (!I->isBranch())
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000264 return true;
265
266 // Can't handle indirect branches.
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000267 SystemZII::Branch Branch(getBranchInfo(I));
268 if (!Branch.Target->isMBB())
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000269 return true;
270
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000271 // Punt on compound branches.
272 if (Branch.Type != SystemZII::BranchNormal)
273 return true;
274
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000275 if (Branch.CCMask == SystemZ::CCMASK_ANY) {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000276 // Handle unconditional branches.
277 if (!AllowModify) {
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000278 TBB = Branch.Target->getMBB();
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000279 continue;
280 }
281
282 // If the block has any instructions after a JMP, delete them.
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000283 while (std::next(I) != MBB.end())
284 std::next(I)->eraseFromParent();
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000285
286 Cond.clear();
Craig Topper062a2ba2014-04-25 05:30:21 +0000287 FBB = nullptr;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000288
289 // Delete the JMP if it's equivalent to a fall-through.
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000290 if (MBB.isLayoutSuccessor(Branch.Target->getMBB())) {
Craig Topper062a2ba2014-04-25 05:30:21 +0000291 TBB = nullptr;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000292 I->eraseFromParent();
293 I = MBB.end();
294 continue;
295 }
296
297 // TBB is used to indicate the unconditinal destination.
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000298 TBB = Branch.Target->getMBB();
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000299 continue;
300 }
301
302 // Working from the bottom, handle the first conditional branch.
303 if (Cond.empty()) {
304 // FIXME: add X86-style branch swap
305 FBB = TBB;
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000306 TBB = Branch.Target->getMBB();
Richard Sandiford3d768e32013-07-31 12:30:20 +0000307 Cond.push_back(MachineOperand::CreateImm(Branch.CCValid));
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000308 Cond.push_back(MachineOperand::CreateImm(Branch.CCMask));
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000309 continue;
310 }
311
312 // Handle subsequent conditional branches.
Richard Sandiford3d768e32013-07-31 12:30:20 +0000313 assert(Cond.size() == 2 && TBB && "Should have seen a conditional branch");
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000314
315 // Only handle the case where all conditional branches branch to the same
316 // destination.
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000317 if (TBB != Branch.Target->getMBB())
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000318 return true;
319
320 // If the conditions are the same, we can leave them alone.
Richard Sandiford3d768e32013-07-31 12:30:20 +0000321 unsigned OldCCValid = Cond[0].getImm();
322 unsigned OldCCMask = Cond[1].getImm();
323 if (OldCCValid == Branch.CCValid && OldCCMask == Branch.CCMask)
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000324 continue;
325
326 // FIXME: Try combining conditions like X86 does. Should be easy on Z!
Richard Sandiford3d768e32013-07-31 12:30:20 +0000327 return false;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000328 }
329
330 return false;
331}
332
333unsigned SystemZInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
334 // Most of the code and comments here are boilerplate.
335 MachineBasicBlock::iterator I = MBB.end();
336 unsigned Count = 0;
337
338 while (I != MBB.begin()) {
339 --I;
340 if (I->isDebugValue())
341 continue;
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000342 if (!I->isBranch())
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000343 break;
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000344 if (!getBranchInfo(I).Target->isMBB())
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000345 break;
346 // Remove the branch.
347 I->eraseFromParent();
348 I = MBB.end();
349 ++Count;
350 }
351
352 return Count;
353}
354
Richard Sandiford3d768e32013-07-31 12:30:20 +0000355bool SystemZInstrInfo::
356ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
357 assert(Cond.size() == 2 && "Invalid condition");
358 Cond[1].setImm(Cond[1].getImm() ^ Cond[0].getImm());
359 return false;
360}
361
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000362unsigned
363SystemZInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
364 MachineBasicBlock *FBB,
365 const SmallVectorImpl<MachineOperand> &Cond,
366 DebugLoc DL) const {
367 // In this function we output 32-bit branches, which should always
368 // have enough range. They can be shortened and relaxed by later code
369 // in the pipeline, if desired.
370
371 // Shouldn't be a fall through.
372 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
Richard Sandiford3d768e32013-07-31 12:30:20 +0000373 assert((Cond.size() == 2 || Cond.size() == 0) &&
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000374 "SystemZ branch conditions have one component!");
375
376 if (Cond.empty()) {
377 // Unconditional branch?
378 assert(!FBB && "Unconditional branch with multiple successors!");
Richard Sandiford312425f2013-05-20 14:23:08 +0000379 BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(TBB);
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000380 return 1;
381 }
382
383 // Conditional branch.
384 unsigned Count = 0;
Richard Sandiford3d768e32013-07-31 12:30:20 +0000385 unsigned CCValid = Cond[0].getImm();
386 unsigned CCMask = Cond[1].getImm();
387 BuildMI(&MBB, DL, get(SystemZ::BRC))
388 .addImm(CCValid).addImm(CCMask).addMBB(TBB);
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000389 ++Count;
390
391 if (FBB) {
392 // Two-way Conditional branch. Insert the second branch.
Richard Sandiford312425f2013-05-20 14:23:08 +0000393 BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(FBB);
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000394 ++Count;
395 }
396 return Count;
397}
398
Richard Sandiford564681c2013-08-12 10:28:10 +0000399bool SystemZInstrInfo::analyzeCompare(const MachineInstr *MI,
400 unsigned &SrcReg, unsigned &SrcReg2,
401 int &Mask, int &Value) const {
402 assert(MI->isCompare() && "Caller should have checked for a comparison");
403
404 if (MI->getNumExplicitOperands() == 2 &&
405 MI->getOperand(0).isReg() &&
406 MI->getOperand(1).isImm()) {
407 SrcReg = MI->getOperand(0).getReg();
408 SrcReg2 = 0;
409 Value = MI->getOperand(1).getImm();
410 Mask = ~0;
411 return true;
412 }
413
414 return false;
415}
416
Richard Sandiforda5901252013-08-16 10:22:54 +0000417// If Reg is a virtual register, return its definition, otherwise return null.
418static MachineInstr *getDef(unsigned Reg,
419 const MachineRegisterInfo *MRI) {
Richard Sandiford564681c2013-08-12 10:28:10 +0000420 if (TargetRegisterInfo::isPhysicalRegister(Reg))
Craig Topper062a2ba2014-04-25 05:30:21 +0000421 return nullptr;
Richard Sandiford564681c2013-08-12 10:28:10 +0000422 return MRI->getUniqueVRegDef(Reg);
423}
424
425// Return true if MI is a shift of type Opcode by Imm bits.
426static bool isShift(MachineInstr *MI, int Opcode, int64_t Imm) {
427 return (MI->getOpcode() == Opcode &&
428 !MI->getOperand(2).getReg() &&
429 MI->getOperand(3).getImm() == Imm);
430}
431
Richard Sandiforda5901252013-08-16 10:22:54 +0000432// If the destination of MI has no uses, delete it as dead.
433static void eraseIfDead(MachineInstr *MI, const MachineRegisterInfo *MRI) {
434 if (MRI->use_nodbg_empty(MI->getOperand(0).getReg()))
435 MI->eraseFromParent();
436}
437
Richard Sandiford564681c2013-08-12 10:28:10 +0000438// Compare compares SrcReg against zero. Check whether SrcReg contains
Richard Sandiforda5901252013-08-16 10:22:54 +0000439// the result of an IPM sequence whose input CC survives until Compare,
440// and whether Compare is therefore redundant. Delete it and return
441// true if so.
442static bool removeIPMBasedCompare(MachineInstr *Compare, unsigned SrcReg,
443 const MachineRegisterInfo *MRI,
444 const TargetRegisterInfo *TRI) {
Craig Topper062a2ba2014-04-25 05:30:21 +0000445 MachineInstr *LGFR = nullptr;
Richard Sandiforda5901252013-08-16 10:22:54 +0000446 MachineInstr *RLL = getDef(SrcReg, MRI);
Richard Sandiforde3827752013-08-16 10:55:47 +0000447 if (RLL && RLL->getOpcode() == SystemZ::LGFR) {
448 LGFR = RLL;
449 RLL = getDef(LGFR->getOperand(1).getReg(), MRI);
450 }
Richard Sandiforda5901252013-08-16 10:22:54 +0000451 if (!RLL || !isShift(RLL, SystemZ::RLL, 31))
Richard Sandiford564681c2013-08-12 10:28:10 +0000452 return false;
453
Richard Sandiforda5901252013-08-16 10:22:54 +0000454 MachineInstr *SRL = getDef(RLL->getOperand(1).getReg(), MRI);
Richard Sandifordf722a8e302013-10-16 11:10:55 +0000455 if (!SRL || !isShift(SRL, SystemZ::SRL, SystemZ::IPM_CC))
Richard Sandiford564681c2013-08-12 10:28:10 +0000456 return false;
457
Richard Sandiforda5901252013-08-16 10:22:54 +0000458 MachineInstr *IPM = getDef(SRL->getOperand(1).getReg(), MRI);
Richard Sandiford564681c2013-08-12 10:28:10 +0000459 if (!IPM || IPM->getOpcode() != SystemZ::IPM)
460 return false;
461
462 // Check that there are no assignments to CC between the IPM and Compare,
Richard Sandiford564681c2013-08-12 10:28:10 +0000463 if (IPM->getParent() != Compare->getParent())
464 return false;
465 MachineBasicBlock::iterator MBBI = IPM, MBBE = Compare;
466 for (++MBBI; MBBI != MBBE; ++MBBI) {
467 MachineInstr *MI = MBBI;
Richard Sandiforda5901252013-08-16 10:22:54 +0000468 if (MI->modifiesRegister(SystemZ::CC, TRI))
Richard Sandiford564681c2013-08-12 10:28:10 +0000469 return false;
470 }
471
Richard Sandiford564681c2013-08-12 10:28:10 +0000472 Compare->eraseFromParent();
Richard Sandiforde3827752013-08-16 10:55:47 +0000473 if (LGFR)
474 eraseIfDead(LGFR, MRI);
Richard Sandiforda5901252013-08-16 10:22:54 +0000475 eraseIfDead(RLL, MRI);
476 eraseIfDead(SRL, MRI);
477 eraseIfDead(IPM, MRI);
478
Richard Sandiford564681c2013-08-12 10:28:10 +0000479 return true;
480}
481
482bool
483SystemZInstrInfo::optimizeCompareInstr(MachineInstr *Compare,
484 unsigned SrcReg, unsigned SrcReg2,
485 int Mask, int Value,
486 const MachineRegisterInfo *MRI) const {
487 assert(!SrcReg2 && "Only optimizing constant comparisons so far");
488 bool IsLogical = (Compare->getDesc().TSFlags & SystemZII::IsLogical) != 0;
489 if (Value == 0 &&
490 !IsLogical &&
Eric Christopher673b3af2014-06-27 07:01:17 +0000491 removeIPMBasedCompare(Compare, SrcReg, MRI, &RI))
Richard Sandiford564681c2013-08-12 10:28:10 +0000492 return true;
493 return false;
494}
495
Richard Sandifordf2404162013-07-25 09:11:15 +0000496// If Opcode is a move that has a conditional variant, return that variant,
497// otherwise return 0.
498static unsigned getConditionalMove(unsigned Opcode) {
499 switch (Opcode) {
500 case SystemZ::LR: return SystemZ::LOCR;
501 case SystemZ::LGR: return SystemZ::LOCGR;
502 default: return 0;
503 }
504}
505
506bool SystemZInstrInfo::isPredicable(MachineInstr *MI) const {
507 unsigned Opcode = MI->getOpcode();
Eric Christopher673b3af2014-06-27 07:01:17 +0000508 if (STI.hasLoadStoreOnCond() &&
Richard Sandifordf2404162013-07-25 09:11:15 +0000509 getConditionalMove(Opcode))
510 return true;
511 return false;
512}
513
514bool SystemZInstrInfo::
515isProfitableToIfCvt(MachineBasicBlock &MBB,
516 unsigned NumCycles, unsigned ExtraPredCycles,
517 const BranchProbability &Probability) const {
518 // For now only convert single instructions.
519 return NumCycles == 1;
520}
521
522bool SystemZInstrInfo::
523isProfitableToIfCvt(MachineBasicBlock &TMBB,
524 unsigned NumCyclesT, unsigned ExtraPredCyclesT,
525 MachineBasicBlock &FMBB,
526 unsigned NumCyclesF, unsigned ExtraPredCyclesF,
527 const BranchProbability &Probability) const {
528 // For now avoid converting mutually-exclusive cases.
529 return false;
530}
531
532bool SystemZInstrInfo::
533PredicateInstruction(MachineInstr *MI,
534 const SmallVectorImpl<MachineOperand> &Pred) const {
Richard Sandiford3d768e32013-07-31 12:30:20 +0000535 assert(Pred.size() == 2 && "Invalid condition");
536 unsigned CCValid = Pred[0].getImm();
537 unsigned CCMask = Pred[1].getImm();
Richard Sandifordf2404162013-07-25 09:11:15 +0000538 assert(CCMask > 0 && CCMask < 15 && "Invalid predicate");
539 unsigned Opcode = MI->getOpcode();
Eric Christopher673b3af2014-06-27 07:01:17 +0000540 if (STI.hasLoadStoreOnCond()) {
Richard Sandifordf2404162013-07-25 09:11:15 +0000541 if (unsigned CondOpcode = getConditionalMove(Opcode)) {
542 MI->setDesc(get(CondOpcode));
Richard Sandiford3d768e32013-07-31 12:30:20 +0000543 MachineInstrBuilder(*MI->getParent()->getParent(), MI)
Richard Sandifordfd7f4ae2013-08-01 10:39:40 +0000544 .addImm(CCValid).addImm(CCMask)
Alp Toker98444342014-04-19 23:56:35 +0000545 .addReg(SystemZ::CC, RegState::Implicit);
Richard Sandifordf2404162013-07-25 09:11:15 +0000546 return true;
547 }
548 }
549 return false;
550}
551
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000552void
553SystemZInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
554 MachineBasicBlock::iterator MBBI, DebugLoc DL,
555 unsigned DestReg, unsigned SrcReg,
556 bool KillSrc) const {
557 // Split 128-bit GPR moves into two 64-bit moves. This handles ADDR128 too.
558 if (SystemZ::GR128BitRegClass.contains(DestReg, SrcReg)) {
Richard Sandiford87a44362013-09-30 10:28:35 +0000559 copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_h64),
560 RI.getSubReg(SrcReg, SystemZ::subreg_h64), KillSrc);
561 copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_l64),
562 RI.getSubReg(SrcReg, SystemZ::subreg_l64), KillSrc);
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000563 return;
564 }
565
Richard Sandiford0755c932013-10-01 11:26:28 +0000566 if (SystemZ::GRX32BitRegClass.contains(DestReg, SrcReg)) {
567 emitGRX32Move(MBB, MBBI, DL, DestReg, SrcReg, SystemZ::LR, 32, KillSrc);
568 return;
569 }
570
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000571 // Everything else needs only one instruction.
572 unsigned Opcode;
Richard Sandiford0755c932013-10-01 11:26:28 +0000573 if (SystemZ::GR64BitRegClass.contains(DestReg, SrcReg))
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000574 Opcode = SystemZ::LGR;
575 else if (SystemZ::FP32BitRegClass.contains(DestReg, SrcReg))
576 Opcode = SystemZ::LER;
577 else if (SystemZ::FP64BitRegClass.contains(DestReg, SrcReg))
578 Opcode = SystemZ::LDR;
579 else if (SystemZ::FP128BitRegClass.contains(DestReg, SrcReg))
580 Opcode = SystemZ::LXR;
Ulrich Weigand49506d72015-05-05 19:28:34 +0000581 else if (SystemZ::VR32BitRegClass.contains(DestReg, SrcReg))
582 Opcode = SystemZ::VLR32;
583 else if (SystemZ::VR64BitRegClass.contains(DestReg, SrcReg))
584 Opcode = SystemZ::VLR64;
Ulrich Weigandce4c1092015-05-05 19:25:42 +0000585 else if (SystemZ::VR128BitRegClass.contains(DestReg, SrcReg))
586 Opcode = SystemZ::VLR;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000587 else
588 llvm_unreachable("Impossible reg-to-reg copy");
589
590 BuildMI(MBB, MBBI, DL, get(Opcode), DestReg)
591 .addReg(SrcReg, getKillRegState(KillSrc));
592}
593
594void
595SystemZInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
596 MachineBasicBlock::iterator MBBI,
597 unsigned SrcReg, bool isKill,
598 int FrameIdx,
599 const TargetRegisterClass *RC,
600 const TargetRegisterInfo *TRI) const {
601 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
602
603 // Callers may expect a single instruction, so keep 128-bit moves
604 // together for now and lower them after register allocation.
605 unsigned LoadOpcode, StoreOpcode;
606 getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode);
607 addFrameReference(BuildMI(MBB, MBBI, DL, get(StoreOpcode))
608 .addReg(SrcReg, getKillRegState(isKill)), FrameIdx);
609}
610
611void
612SystemZInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
613 MachineBasicBlock::iterator MBBI,
614 unsigned DestReg, int FrameIdx,
615 const TargetRegisterClass *RC,
616 const TargetRegisterInfo *TRI) const {
617 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
618
619 // Callers may expect a single instruction, so keep 128-bit moves
620 // together for now and lower them after register allocation.
621 unsigned LoadOpcode, StoreOpcode;
622 getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode);
623 addFrameReference(BuildMI(MBB, MBBI, DL, get(LoadOpcode), DestReg),
624 FrameIdx);
625}
626
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000627// Return true if MI is a simple load or store with a 12-bit displacement
628// and no index. Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores.
629static bool isSimpleBD12Move(const MachineInstr *MI, unsigned Flag) {
630 const MCInstrDesc &MCID = MI->getDesc();
631 return ((MCID.TSFlags & Flag) &&
632 isUInt<12>(MI->getOperand(2).getImm()) &&
633 MI->getOperand(3).getReg() == 0);
634}
635
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000636namespace {
Richard Sandifordc2312692014-03-06 10:38:30 +0000637struct LogicOp {
638 LogicOp() : RegSize(0), ImmLSB(0), ImmSize(0) {}
639 LogicOp(unsigned regSize, unsigned immLSB, unsigned immSize)
640 : RegSize(regSize), ImmLSB(immLSB), ImmSize(immSize) {}
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000641
Aaron Ballmanb46962f2015-02-15 22:00:20 +0000642 explicit operator bool() const { return RegSize; }
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000643
Richard Sandifordc2312692014-03-06 10:38:30 +0000644 unsigned RegSize, ImmLSB, ImmSize;
645};
646} // end anonymous namespace
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000647
648static LogicOp interpretAndImmediate(unsigned Opcode) {
649 switch (Opcode) {
Richard Sandiford70284282013-10-01 14:20:41 +0000650 case SystemZ::NILMux: return LogicOp(32, 0, 16);
651 case SystemZ::NIHMux: return LogicOp(32, 16, 16);
Richard Sandiford652784e2013-09-25 11:11:53 +0000652 case SystemZ::NILL64: return LogicOp(64, 0, 16);
653 case SystemZ::NILH64: return LogicOp(64, 16, 16);
Richard Sandiford70284282013-10-01 14:20:41 +0000654 case SystemZ::NIHL64: return LogicOp(64, 32, 16);
655 case SystemZ::NIHH64: return LogicOp(64, 48, 16);
656 case SystemZ::NIFMux: return LogicOp(32, 0, 32);
Richard Sandiford652784e2013-09-25 11:11:53 +0000657 case SystemZ::NILF64: return LogicOp(64, 0, 32);
Richard Sandiford70284282013-10-01 14:20:41 +0000658 case SystemZ::NIHF64: return LogicOp(64, 32, 32);
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000659 default: return LogicOp();
660 }
661}
662
663// Used to return from convertToThreeAddress after replacing two-address
664// instruction OldMI with three-address instruction NewMI.
665static MachineInstr *finishConvertToThreeAddress(MachineInstr *OldMI,
666 MachineInstr *NewMI,
667 LiveVariables *LV) {
668 if (LV) {
669 unsigned NumOps = OldMI->getNumOperands();
670 for (unsigned I = 1; I < NumOps; ++I) {
671 MachineOperand &Op = OldMI->getOperand(I);
672 if (Op.isReg() && Op.isKill())
673 LV->replaceKillInstruction(Op.getReg(), OldMI, NewMI);
674 }
675 }
676 return NewMI;
677}
678
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000679MachineInstr *
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000680SystemZInstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
681 MachineBasicBlock::iterator &MBBI,
682 LiveVariables *LV) const {
683 MachineInstr *MI = MBBI;
684 MachineBasicBlock *MBB = MI->getParent();
Richard Sandiford42a694f2013-10-01 14:53:46 +0000685 MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo();
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000686
687 unsigned Opcode = MI->getOpcode();
688 unsigned NumOps = MI->getNumOperands();
689
690 // Try to convert something like SLL into SLLK, if supported.
691 // We prefer to keep the two-operand form where possible both
692 // because it tends to be shorter and because some instructions
693 // have memory forms that can be used during spilling.
Eric Christopher673b3af2014-06-27 07:01:17 +0000694 if (STI.hasDistinctOps()) {
Richard Sandiford42a694f2013-10-01 14:53:46 +0000695 MachineOperand &Dest = MI->getOperand(0);
696 MachineOperand &Src = MI->getOperand(1);
697 unsigned DestReg = Dest.getReg();
698 unsigned SrcReg = Src.getReg();
699 // AHIMux is only really a three-operand instruction when both operands
700 // are low registers. Try to constrain both operands to be low if
701 // possible.
702 if (Opcode == SystemZ::AHIMux &&
703 TargetRegisterInfo::isVirtualRegister(DestReg) &&
704 TargetRegisterInfo::isVirtualRegister(SrcReg) &&
705 MRI.getRegClass(DestReg)->contains(SystemZ::R1L) &&
706 MRI.getRegClass(SrcReg)->contains(SystemZ::R1L)) {
707 MRI.constrainRegClass(DestReg, &SystemZ::GR32BitRegClass);
708 MRI.constrainRegClass(SrcReg, &SystemZ::GR32BitRegClass);
709 }
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000710 int ThreeOperandOpcode = SystemZ::getThreeOperandOpcode(Opcode);
711 if (ThreeOperandOpcode >= 0) {
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000712 MachineInstrBuilder MIB =
713 BuildMI(*MBB, MBBI, MI->getDebugLoc(), get(ThreeOperandOpcode))
714 .addOperand(Dest);
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000715 // Keep the kill state, but drop the tied flag.
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000716 MIB.addReg(Src.getReg(), getKillRegState(Src.isKill()), Src.getSubReg());
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000717 // Keep the remaining operands as-is.
718 for (unsigned I = 2; I < NumOps; ++I)
719 MIB.addOperand(MI->getOperand(I));
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000720 return finishConvertToThreeAddress(MI, MIB, LV);
721 }
722 }
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000723
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000724 // Try to convert an AND into an RISBG-type instruction.
725 if (LogicOp And = interpretAndImmediate(Opcode)) {
Richard Sandiford70284282013-10-01 14:20:41 +0000726 uint64_t Imm = MI->getOperand(2).getImm() << And.ImmLSB;
727 // AND IMMEDIATE leaves the other bits of the register unchanged.
728 Imm |= allOnes(And.RegSize) & ~(allOnes(And.ImmSize) << And.ImmLSB);
729 unsigned Start, End;
730 if (isRxSBGMask(Imm, And.RegSize, Start, End)) {
731 unsigned NewOpcode;
Ulrich Weigand371d10a2015-03-31 12:58:17 +0000732 if (And.RegSize == 64) {
Richard Sandiford70284282013-10-01 14:20:41 +0000733 NewOpcode = SystemZ::RISBG;
Ulrich Weigand371d10a2015-03-31 12:58:17 +0000734 // Prefer RISBGN if available, since it does not clobber CC.
735 if (STI.hasMiscellaneousExtensions())
736 NewOpcode = SystemZ::RISBGN;
737 } else {
Richard Sandiford70284282013-10-01 14:20:41 +0000738 NewOpcode = SystemZ::RISBMux;
739 Start &= 31;
740 End &= 31;
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000741 }
Richard Sandiford70284282013-10-01 14:20:41 +0000742 MachineOperand &Dest = MI->getOperand(0);
743 MachineOperand &Src = MI->getOperand(1);
744 MachineInstrBuilder MIB =
745 BuildMI(*MBB, MI, MI->getDebugLoc(), get(NewOpcode))
746 .addOperand(Dest).addReg(0)
747 .addReg(Src.getReg(), getKillRegState(Src.isKill()), Src.getSubReg())
748 .addImm(Start).addImm(End + 128).addImm(0);
749 return finishConvertToThreeAddress(MI, MIB, LV);
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000750 }
751 }
Craig Topper062a2ba2014-04-25 05:30:21 +0000752 return nullptr;
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000753}
754
Benjamin Kramerf1362f62015-02-28 12:04:00 +0000755MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
756 MachineInstr *MI,
757 ArrayRef<unsigned> Ops,
758 int FrameIndex) const {
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000759 const MachineFrameInfo *MFI = MF.getFrameInfo();
760 unsigned Size = MFI->getObjectSize(FrameIndex);
Richard Sandiford6af6ff12013-10-15 08:42:59 +0000761 unsigned Opcode = MI->getOpcode();
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000762
Richard Sandiford6af6ff12013-10-15 08:42:59 +0000763 if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) {
764 if ((Opcode == SystemZ::LA || Opcode == SystemZ::LAY) &&
765 isInt<8>(MI->getOperand(2).getImm()) &&
766 !MI->getOperand(3).getReg()) {
767 // LA(Y) %reg, CONST(%reg) -> AGSI %mem, CONST
768 return BuildMI(MF, MI->getDebugLoc(), get(SystemZ::AGSI))
769 .addFrameIndex(FrameIndex).addImm(0)
770 .addImm(MI->getOperand(2).getImm());
771 }
Craig Topper062a2ba2014-04-25 05:30:21 +0000772 return nullptr;
Richard Sandiford6af6ff12013-10-15 08:42:59 +0000773 }
774
775 // All other cases require a single operand.
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000776 if (Ops.size() != 1)
Craig Topper062a2ba2014-04-25 05:30:21 +0000777 return nullptr;
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000778
779 unsigned OpNum = Ops[0];
NAKAMURA Takumiddcba562013-07-03 02:20:49 +0000780 assert(Size == MF.getRegInfo()
781 .getRegClass(MI->getOperand(OpNum).getReg())->getSize() &&
Benjamin Kramer421c8fb2013-07-02 21:17:31 +0000782 "Invalid size combination");
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000783
Richard Sandiford6af6ff12013-10-15 08:42:59 +0000784 if ((Opcode == SystemZ::AHI || Opcode == SystemZ::AGHI) &&
785 OpNum == 0 &&
786 isInt<8>(MI->getOperand(2).getImm())) {
787 // A(G)HI %reg, CONST -> A(G)SI %mem, CONST
788 Opcode = (Opcode == SystemZ::AHI ? SystemZ::ASI : SystemZ::AGSI);
789 return BuildMI(MF, MI->getDebugLoc(), get(Opcode))
790 .addFrameIndex(FrameIndex).addImm(0)
791 .addImm(MI->getOperand(2).getImm());
792 }
793
Richard Sandiford3f0edc22013-07-12 08:37:17 +0000794 if (Opcode == SystemZ::LGDR || Opcode == SystemZ::LDGR) {
795 bool Op0IsGPR = (Opcode == SystemZ::LGDR);
796 bool Op1IsGPR = (Opcode == SystemZ::LDGR);
797 // If we're spilling the destination of an LDGR or LGDR, store the
798 // source register instead.
799 if (OpNum == 0) {
800 unsigned StoreOpcode = Op1IsGPR ? SystemZ::STG : SystemZ::STD;
801 return BuildMI(MF, MI->getDebugLoc(), get(StoreOpcode))
802 .addOperand(MI->getOperand(1)).addFrameIndex(FrameIndex)
803 .addImm(0).addReg(0);
804 }
805 // If we're spilling the source of an LDGR or LGDR, load the
806 // destination register instead.
807 if (OpNum == 1) {
808 unsigned LoadOpcode = Op0IsGPR ? SystemZ::LG : SystemZ::LD;
809 unsigned Dest = MI->getOperand(0).getReg();
810 return BuildMI(MF, MI->getDebugLoc(), get(LoadOpcode), Dest)
811 .addFrameIndex(FrameIndex).addImm(0).addReg(0);
812 }
813 }
814
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000815 // Look for cases where the source of a simple store or the destination
816 // of a simple load is being spilled. Try to use MVC instead.
817 //
818 // Although MVC is in practice a fast choice in these cases, it is still
819 // logically a bytewise copy. This means that we cannot use it if the
Richard Sandiford067817e2013-09-27 15:29:20 +0000820 // load or store is volatile. We also wouldn't be able to use MVC if
821 // the two memories partially overlap, but that case cannot occur here,
822 // because we know that one of the memories is a full frame index.
823 //
824 // For performance reasons, we also want to avoid using MVC if the addresses
825 // might be equal. We don't worry about that case here, because spill slot
826 // coloring happens later, and because we have special code to remove
827 // MVCs that turn out to be redundant.
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000828 if (OpNum == 0 && MI->hasOneMemOperand()) {
829 MachineMemOperand *MMO = *MI->memoperands_begin();
830 if (MMO->getSize() == Size && !MMO->isVolatile()) {
831 // Handle conversion of loads.
Richard Sandiford8976ea72013-07-05 14:02:01 +0000832 if (isSimpleBD12Move(MI, SystemZII::SimpleBDXLoad)) {
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000833 return BuildMI(MF, MI->getDebugLoc(), get(SystemZ::MVC))
Richard Sandiford1ca6dea2013-07-05 14:31:24 +0000834 .addFrameIndex(FrameIndex).addImm(0).addImm(Size)
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000835 .addOperand(MI->getOperand(1)).addImm(MI->getOperand(2).getImm())
Richard Sandiford1ca6dea2013-07-05 14:31:24 +0000836 .addMemOperand(MMO);
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000837 }
838 // Handle conversion of stores.
Richard Sandiford8976ea72013-07-05 14:02:01 +0000839 if (isSimpleBD12Move(MI, SystemZII::SimpleBDXStore)) {
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000840 return BuildMI(MF, MI->getDebugLoc(), get(SystemZ::MVC))
841 .addOperand(MI->getOperand(1)).addImm(MI->getOperand(2).getImm())
Richard Sandiford1ca6dea2013-07-05 14:31:24 +0000842 .addImm(Size).addFrameIndex(FrameIndex).addImm(0)
843 .addMemOperand(MMO);
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000844 }
845 }
846 }
847
Richard Sandiforded1fab62013-07-03 10:10:02 +0000848 // If the spilled operand is the final one, try to change <INSN>R
849 // into <INSN>.
Richard Sandiford3f0edc22013-07-12 08:37:17 +0000850 int MemOpcode = SystemZ::getMemOpcode(Opcode);
Richard Sandiforded1fab62013-07-03 10:10:02 +0000851 if (MemOpcode >= 0) {
852 unsigned NumOps = MI->getNumExplicitOperands();
853 if (OpNum == NumOps - 1) {
854 const MCInstrDesc &MemDesc = get(MemOpcode);
855 uint64_t AccessBytes = SystemZII::getAccessSize(MemDesc.TSFlags);
856 assert(AccessBytes != 0 && "Size of access should be known");
857 assert(AccessBytes <= Size && "Access outside the frame index");
858 uint64_t Offset = Size - AccessBytes;
Richard Sandiforded1fab62013-07-03 10:10:02 +0000859 MachineInstrBuilder MIB = BuildMI(MF, MI->getDebugLoc(), get(MemOpcode));
860 for (unsigned I = 0; I < OpNum; ++I)
861 MIB.addOperand(MI->getOperand(I));
862 MIB.addFrameIndex(FrameIndex).addImm(Offset);
863 if (MemDesc.TSFlags & SystemZII::HasIndex)
864 MIB.addReg(0);
Richard Sandiforded1fab62013-07-03 10:10:02 +0000865 return MIB;
866 }
867 }
868
Craig Topper062a2ba2014-04-25 05:30:21 +0000869 return nullptr;
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000870}
871
872MachineInstr *
Benjamin Kramerf1362f62015-02-28 12:04:00 +0000873SystemZInstrInfo::foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
874 ArrayRef<unsigned> Ops,
875 MachineInstr *LoadMI) const {
Craig Topper062a2ba2014-04-25 05:30:21 +0000876 return nullptr;
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000877}
878
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000879bool
880SystemZInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const {
881 switch (MI->getOpcode()) {
882 case SystemZ::L128:
883 splitMove(MI, SystemZ::LG);
884 return true;
885
886 case SystemZ::ST128:
887 splitMove(MI, SystemZ::STG);
888 return true;
889
890 case SystemZ::LX:
891 splitMove(MI, SystemZ::LD);
892 return true;
893
894 case SystemZ::STX:
895 splitMove(MI, SystemZ::STD);
896 return true;
897
Richard Sandiford89e160d2013-10-01 12:11:47 +0000898 case SystemZ::LBMux:
899 expandRXYPseudo(MI, SystemZ::LB, SystemZ::LBH);
900 return true;
901
902 case SystemZ::LHMux:
903 expandRXYPseudo(MI, SystemZ::LH, SystemZ::LHH);
904 return true;
905
Richard Sandiford21235a22013-10-01 12:49:07 +0000906 case SystemZ::LLCRMux:
907 expandZExtPseudo(MI, SystemZ::LLCR, 8);
908 return true;
909
910 case SystemZ::LLHRMux:
911 expandZExtPseudo(MI, SystemZ::LLHR, 16);
912 return true;
913
Richard Sandiford0d46b1a2013-10-01 12:19:08 +0000914 case SystemZ::LLCMux:
915 expandRXYPseudo(MI, SystemZ::LLC, SystemZ::LLCH);
916 return true;
917
918 case SystemZ::LLHMux:
919 expandRXYPseudo(MI, SystemZ::LLH, SystemZ::LLHH);
920 return true;
921
Richard Sandiford0755c932013-10-01 11:26:28 +0000922 case SystemZ::LMux:
923 expandRXYPseudo(MI, SystemZ::L, SystemZ::LFH);
924 return true;
925
Richard Sandiford5469c392013-10-01 12:22:49 +0000926 case SystemZ::STCMux:
927 expandRXYPseudo(MI, SystemZ::STC, SystemZ::STCH);
928 return true;
929
930 case SystemZ::STHMux:
931 expandRXYPseudo(MI, SystemZ::STH, SystemZ::STHH);
932 return true;
933
Richard Sandiford0755c932013-10-01 11:26:28 +0000934 case SystemZ::STMux:
935 expandRXYPseudo(MI, SystemZ::ST, SystemZ::STFH);
936 return true;
937
Richard Sandiford01240232013-10-01 13:02:28 +0000938 case SystemZ::LHIMux:
939 expandRIPseudo(MI, SystemZ::LHI, SystemZ::IIHF, true);
940 return true;
941
942 case SystemZ::IIFMux:
943 expandRIPseudo(MI, SystemZ::IILF, SystemZ::IIHF, false);
944 return true;
945
Richard Sandiford1a569312013-10-01 13:18:56 +0000946 case SystemZ::IILMux:
947 expandRIPseudo(MI, SystemZ::IILL, SystemZ::IIHL, false);
948 return true;
949
950 case SystemZ::IIHMux:
951 expandRIPseudo(MI, SystemZ::IILH, SystemZ::IIHH, false);
952 return true;
953
Richard Sandiford70284282013-10-01 14:20:41 +0000954 case SystemZ::NIFMux:
955 expandRIPseudo(MI, SystemZ::NILF, SystemZ::NIHF, false);
956 return true;
957
958 case SystemZ::NILMux:
959 expandRIPseudo(MI, SystemZ::NILL, SystemZ::NIHL, false);
960 return true;
961
962 case SystemZ::NIHMux:
963 expandRIPseudo(MI, SystemZ::NILH, SystemZ::NIHH, false);
964 return true;
965
Richard Sandiford6e96ac62013-10-01 13:22:41 +0000966 case SystemZ::OIFMux:
967 expandRIPseudo(MI, SystemZ::OILF, SystemZ::OIHF, false);
968 return true;
969
970 case SystemZ::OILMux:
971 expandRIPseudo(MI, SystemZ::OILL, SystemZ::OIHL, false);
972 return true;
973
974 case SystemZ::OIHMux:
975 expandRIPseudo(MI, SystemZ::OILH, SystemZ::OIHH, false);
976 return true;
977
Richard Sandiford5718dac2013-10-01 14:08:44 +0000978 case SystemZ::XIFMux:
979 expandRIPseudo(MI, SystemZ::XILF, SystemZ::XIHF, false);
980 return true;
981
Richard Sandiford2cac7632013-10-01 14:41:52 +0000982 case SystemZ::TMLMux:
983 expandRIPseudo(MI, SystemZ::TMLL, SystemZ::TMHL, false);
984 return true;
985
986 case SystemZ::TMHMux:
987 expandRIPseudo(MI, SystemZ::TMLH, SystemZ::TMHH, false);
988 return true;
989
Richard Sandiford42a694f2013-10-01 14:53:46 +0000990 case SystemZ::AHIMux:
991 expandRIPseudo(MI, SystemZ::AHI, SystemZ::AIH, false);
992 return true;
993
994 case SystemZ::AHIMuxK:
995 expandRIEPseudo(MI, SystemZ::AHI, SystemZ::AHIK, SystemZ::AIH);
996 return true;
997
998 case SystemZ::AFIMux:
999 expandRIPseudo(MI, SystemZ::AFI, SystemZ::AIH, false);
1000 return true;
1001
Richard Sandiforda9ac0e02013-10-01 14:56:23 +00001002 case SystemZ::CFIMux:
1003 expandRIPseudo(MI, SystemZ::CFI, SystemZ::CIH, false);
1004 return true;
1005
1006 case SystemZ::CLFIMux:
1007 expandRIPseudo(MI, SystemZ::CLFI, SystemZ::CLIH, false);
1008 return true;
1009
Richard Sandifordb63e3002013-10-01 15:00:44 +00001010 case SystemZ::CMux:
1011 expandRXYPseudo(MI, SystemZ::C, SystemZ::CHF);
1012 return true;
1013
1014 case SystemZ::CLMux:
1015 expandRXYPseudo(MI, SystemZ::CL, SystemZ::CLHF);
1016 return true;
1017
Richard Sandiford70284282013-10-01 14:20:41 +00001018 case SystemZ::RISBMux: {
1019 bool DestIsHigh = isHighReg(MI->getOperand(0).getReg());
1020 bool SrcIsHigh = isHighReg(MI->getOperand(2).getReg());
1021 if (SrcIsHigh == DestIsHigh)
1022 MI->setDesc(get(DestIsHigh ? SystemZ::RISBHH : SystemZ::RISBLL));
1023 else {
1024 MI->setDesc(get(DestIsHigh ? SystemZ::RISBHL : SystemZ::RISBLH));
1025 MI->getOperand(5).setImm(MI->getOperand(5).getImm() ^ 32);
1026 }
1027 return true;
1028 }
1029
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001030 case SystemZ::ADJDYNALLOC:
1031 splitAdjDynAlloc(MI);
1032 return true;
1033
1034 default:
1035 return false;
1036 }
1037}
1038
Richard Sandiford312425f2013-05-20 14:23:08 +00001039uint64_t SystemZInstrInfo::getInstSizeInBytes(const MachineInstr *MI) const {
1040 if (MI->getOpcode() == TargetOpcode::INLINEASM) {
1041 const MachineFunction *MF = MI->getParent()->getParent();
1042 const char *AsmStr = MI->getOperand(0).getSymbolName();
1043 return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
1044 }
1045 return MI->getDesc().getSize();
1046}
1047
Richard Sandiford53c9efd2013-05-28 10:13:54 +00001048SystemZII::Branch
1049SystemZInstrInfo::getBranchInfo(const MachineInstr *MI) const {
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001050 switch (MI->getOpcode()) {
1051 case SystemZ::BR:
1052 case SystemZ::J:
1053 case SystemZ::JG:
Richard Sandiford0fb90ab2013-05-28 10:41:11 +00001054 return SystemZII::Branch(SystemZII::BranchNormal, SystemZ::CCMASK_ANY,
Richard Sandiford3d768e32013-07-31 12:30:20 +00001055 SystemZ::CCMASK_ANY, &MI->getOperand(0));
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001056
1057 case SystemZ::BRC:
1058 case SystemZ::BRCL:
Richard Sandiford0fb90ab2013-05-28 10:41:11 +00001059 return SystemZII::Branch(SystemZII::BranchNormal,
Richard Sandiford3d768e32013-07-31 12:30:20 +00001060 MI->getOperand(0).getImm(),
1061 MI->getOperand(1).getImm(), &MI->getOperand(2));
Richard Sandiford0fb90ab2013-05-28 10:41:11 +00001062
Richard Sandifordc2121252013-08-05 11:23:46 +00001063 case SystemZ::BRCT:
1064 return SystemZII::Branch(SystemZII::BranchCT, SystemZ::CCMASK_ICMP,
1065 SystemZ::CCMASK_CMP_NE, &MI->getOperand(2));
1066
1067 case SystemZ::BRCTG:
1068 return SystemZII::Branch(SystemZII::BranchCTG, SystemZ::CCMASK_ICMP,
1069 SystemZ::CCMASK_CMP_NE, &MI->getOperand(2));
1070
Richard Sandiforde1d9f002013-05-29 11:58:52 +00001071 case SystemZ::CIJ:
Richard Sandiford0fb90ab2013-05-28 10:41:11 +00001072 case SystemZ::CRJ:
Richard Sandiford3d768e32013-07-31 12:30:20 +00001073 return SystemZII::Branch(SystemZII::BranchC, SystemZ::CCMASK_ICMP,
1074 MI->getOperand(2).getImm(), &MI->getOperand(3));
Richard Sandiford0fb90ab2013-05-28 10:41:11 +00001075
Richard Sandiford93183ee2013-09-18 09:56:40 +00001076 case SystemZ::CLIJ:
1077 case SystemZ::CLRJ:
1078 return SystemZII::Branch(SystemZII::BranchCL, SystemZ::CCMASK_ICMP,
1079 MI->getOperand(2).getImm(), &MI->getOperand(3));
1080
Richard Sandiforde1d9f002013-05-29 11:58:52 +00001081 case SystemZ::CGIJ:
Richard Sandiford0fb90ab2013-05-28 10:41:11 +00001082 case SystemZ::CGRJ:
Richard Sandiford3d768e32013-07-31 12:30:20 +00001083 return SystemZII::Branch(SystemZII::BranchCG, SystemZ::CCMASK_ICMP,
1084 MI->getOperand(2).getImm(), &MI->getOperand(3));
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001085
Richard Sandiford93183ee2013-09-18 09:56:40 +00001086 case SystemZ::CLGIJ:
1087 case SystemZ::CLGRJ:
1088 return SystemZII::Branch(SystemZII::BranchCLG, SystemZ::CCMASK_ICMP,
1089 MI->getOperand(2).getImm(), &MI->getOperand(3));
1090
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001091 default:
Richard Sandiford53c9efd2013-05-28 10:13:54 +00001092 llvm_unreachable("Unrecognized branch opcode");
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001093 }
1094}
1095
1096void SystemZInstrInfo::getLoadStoreOpcodes(const TargetRegisterClass *RC,
1097 unsigned &LoadOpcode,
1098 unsigned &StoreOpcode) const {
1099 if (RC == &SystemZ::GR32BitRegClass || RC == &SystemZ::ADDR32BitRegClass) {
1100 LoadOpcode = SystemZ::L;
Richard Sandiford6cbd7f02013-09-25 10:29:47 +00001101 StoreOpcode = SystemZ::ST;
Richard Sandiford0755c932013-10-01 11:26:28 +00001102 } else if (RC == &SystemZ::GRH32BitRegClass) {
1103 LoadOpcode = SystemZ::LFH;
1104 StoreOpcode = SystemZ::STFH;
1105 } else if (RC == &SystemZ::GRX32BitRegClass) {
1106 LoadOpcode = SystemZ::LMux;
1107 StoreOpcode = SystemZ::STMux;
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001108 } else if (RC == &SystemZ::GR64BitRegClass ||
1109 RC == &SystemZ::ADDR64BitRegClass) {
1110 LoadOpcode = SystemZ::LG;
1111 StoreOpcode = SystemZ::STG;
1112 } else if (RC == &SystemZ::GR128BitRegClass ||
1113 RC == &SystemZ::ADDR128BitRegClass) {
1114 LoadOpcode = SystemZ::L128;
1115 StoreOpcode = SystemZ::ST128;
1116 } else if (RC == &SystemZ::FP32BitRegClass) {
1117 LoadOpcode = SystemZ::LE;
1118 StoreOpcode = SystemZ::STE;
1119 } else if (RC == &SystemZ::FP64BitRegClass) {
1120 LoadOpcode = SystemZ::LD;
1121 StoreOpcode = SystemZ::STD;
1122 } else if (RC == &SystemZ::FP128BitRegClass) {
1123 LoadOpcode = SystemZ::LX;
1124 StoreOpcode = SystemZ::STX;
Ulrich Weigand49506d72015-05-05 19:28:34 +00001125 } else if (RC == &SystemZ::VR32BitRegClass) {
1126 LoadOpcode = SystemZ::VL32;
1127 StoreOpcode = SystemZ::VST32;
1128 } else if (RC == &SystemZ::VR64BitRegClass) {
1129 LoadOpcode = SystemZ::VL64;
1130 StoreOpcode = SystemZ::VST64;
Ulrich Weigandce4c1092015-05-05 19:25:42 +00001131 } else if (RC == &SystemZ::VF128BitRegClass ||
1132 RC == &SystemZ::VR128BitRegClass) {
1133 LoadOpcode = SystemZ::VL;
1134 StoreOpcode = SystemZ::VST;
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001135 } else
1136 llvm_unreachable("Unsupported regclass to load or store");
1137}
1138
1139unsigned SystemZInstrInfo::getOpcodeForOffset(unsigned Opcode,
1140 int64_t Offset) const {
1141 const MCInstrDesc &MCID = get(Opcode);
1142 int64_t Offset2 = (MCID.TSFlags & SystemZII::Is128Bit ? Offset + 8 : Offset);
1143 if (isUInt<12>(Offset) && isUInt<12>(Offset2)) {
1144 // Get the instruction to use for unsigned 12-bit displacements.
1145 int Disp12Opcode = SystemZ::getDisp12Opcode(Opcode);
1146 if (Disp12Opcode >= 0)
1147 return Disp12Opcode;
1148
1149 // All address-related instructions can use unsigned 12-bit
1150 // displacements.
1151 return Opcode;
1152 }
1153 if (isInt<20>(Offset) && isInt<20>(Offset2)) {
1154 // Get the instruction to use for signed 20-bit displacements.
1155 int Disp20Opcode = SystemZ::getDisp20Opcode(Opcode);
1156 if (Disp20Opcode >= 0)
1157 return Disp20Opcode;
1158
1159 // Check whether Opcode allows signed 20-bit displacements.
1160 if (MCID.TSFlags & SystemZII::Has20BitOffset)
1161 return Opcode;
1162 }
1163 return 0;
1164}
1165
Richard Sandifordb49a3ab2013-08-05 11:03:20 +00001166unsigned SystemZInstrInfo::getLoadAndTest(unsigned Opcode) const {
1167 switch (Opcode) {
Ulrich Weigand371d10a2015-03-31 12:58:17 +00001168 case SystemZ::L: return SystemZ::LT;
1169 case SystemZ::LY: return SystemZ::LT;
1170 case SystemZ::LG: return SystemZ::LTG;
1171 case SystemZ::LGF: return SystemZ::LTGF;
1172 case SystemZ::LR: return SystemZ::LTR;
1173 case SystemZ::LGFR: return SystemZ::LTGFR;
1174 case SystemZ::LGR: return SystemZ::LTGR;
1175 case SystemZ::LER: return SystemZ::LTEBR;
1176 case SystemZ::LDR: return SystemZ::LTDBR;
1177 case SystemZ::LXR: return SystemZ::LTXBR;
1178 // On zEC12 we prefer to use RISBGN. But if there is a chance to
1179 // actually use the condition code, we may turn it back into RISGB.
1180 // Note that RISBG is not really a "load-and-test" instruction,
1181 // but sets the same condition code values, so is OK to use here.
1182 case SystemZ::RISBGN: return SystemZ::RISBG;
1183 default: return 0;
Richard Sandifordb49a3ab2013-08-05 11:03:20 +00001184 }
1185}
1186
Richard Sandiford6a06ba32013-07-31 11:36:35 +00001187// Return true if Mask matches the regexp 0*1+0*, given that zero masks
1188// have already been filtered out. Store the first set bit in LSB and
1189// the number of set bits in Length if so.
1190static bool isStringOfOnes(uint64_t Mask, unsigned &LSB, unsigned &Length) {
1191 unsigned First = findFirstSet(Mask);
1192 uint64_t Top = (Mask >> First) + 1;
1193 if ((Top & -Top) == Top) {
1194 LSB = First;
1195 Length = findFirstSet(Top);
1196 return true;
1197 }
1198 return false;
1199}
1200
1201bool SystemZInstrInfo::isRxSBGMask(uint64_t Mask, unsigned BitSize,
1202 unsigned &Start, unsigned &End) const {
1203 // Reject trivial all-zero masks.
Ulrich Weigandce4c1092015-05-05 19:25:42 +00001204 Mask &= allOnes(BitSize);
Richard Sandiford6a06ba32013-07-31 11:36:35 +00001205 if (Mask == 0)
1206 return false;
1207
1208 // Handle the 1+0+ or 0+1+0* cases. Start then specifies the index of
1209 // the msb and End specifies the index of the lsb.
1210 unsigned LSB, Length;
1211 if (isStringOfOnes(Mask, LSB, Length)) {
1212 Start = 63 - (LSB + Length - 1);
1213 End = 63 - LSB;
1214 return true;
1215 }
1216
1217 // Handle the wrap-around 1+0+1+ cases. Start then specifies the msb
1218 // of the low 1s and End specifies the lsb of the high 1s.
1219 if (isStringOfOnes(Mask ^ allOnes(BitSize), LSB, Length)) {
1220 assert(LSB > 0 && "Bottom bit must be set");
1221 assert(LSB + Length < BitSize && "Top bit must be set");
1222 Start = 63 - (LSB - 1);
1223 End = 63 - (LSB + Length);
1224 return true;
1225 }
1226
1227 return false;
1228}
1229
Richard Sandiforde1d9f002013-05-29 11:58:52 +00001230unsigned SystemZInstrInfo::getCompareAndBranch(unsigned Opcode,
1231 const MachineInstr *MI) const {
Richard Sandiford0fb90ab2013-05-28 10:41:11 +00001232 switch (Opcode) {
1233 case SystemZ::CR:
1234 return SystemZ::CRJ;
1235 case SystemZ::CGR:
1236 return SystemZ::CGRJ;
Richard Sandiforde1d9f002013-05-29 11:58:52 +00001237 case SystemZ::CHI:
1238 return MI && isInt<8>(MI->getOperand(1).getImm()) ? SystemZ::CIJ : 0;
1239 case SystemZ::CGHI:
1240 return MI && isInt<8>(MI->getOperand(1).getImm()) ? SystemZ::CGIJ : 0;
Richard Sandiford93183ee2013-09-18 09:56:40 +00001241 case SystemZ::CLR:
1242 return SystemZ::CLRJ;
1243 case SystemZ::CLGR:
1244 return SystemZ::CLGRJ;
1245 case SystemZ::CLFI:
1246 return MI && isUInt<8>(MI->getOperand(1).getImm()) ? SystemZ::CLIJ : 0;
1247 case SystemZ::CLGFI:
1248 return MI && isUInt<8>(MI->getOperand(1).getImm()) ? SystemZ::CLGIJ : 0;
Richard Sandiford0fb90ab2013-05-28 10:41:11 +00001249 default:
1250 return 0;
1251 }
1252}
1253
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001254void SystemZInstrInfo::loadImmediate(MachineBasicBlock &MBB,
1255 MachineBasicBlock::iterator MBBI,
1256 unsigned Reg, uint64_t Value) const {
1257 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
1258 unsigned Opcode;
1259 if (isInt<16>(Value))
1260 Opcode = SystemZ::LGHI;
1261 else if (SystemZ::isImmLL(Value))
1262 Opcode = SystemZ::LLILL;
1263 else if (SystemZ::isImmLH(Value)) {
1264 Opcode = SystemZ::LLILH;
1265 Value >>= 16;
1266 } else {
1267 assert(isInt<32>(Value) && "Huge values not handled yet");
1268 Opcode = SystemZ::LGFI;
1269 }
1270 BuildMI(MBB, MBBI, DL, get(Opcode), Reg).addImm(Value);
1271}