1 //===-- SystemZInstrInfo.cpp - SystemZ instruction information ------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains the SystemZ implementation of the TargetInstrInfo class.
11 //===----------------------------------------------------------------------===//
13 #include "SystemZInstrInfo.h"
14 #include "MCTargetDesc/SystemZMCTargetDesc.h"
16 #include "SystemZInstrBuilder.h"
17 #include "SystemZSubtarget.h"
18 #include "llvm/ADT/Statistic.h"
19 #include "llvm/CodeGen/LiveInterval.h"
20 #include "llvm/CodeGen/LiveIntervals.h"
21 #include "llvm/CodeGen/LiveVariables.h"
22 #include "llvm/CodeGen/MachineBasicBlock.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
24 #include "llvm/CodeGen/MachineFunction.h"
25 #include "llvm/CodeGen/MachineInstr.h"
26 #include "llvm/CodeGen/MachineMemOperand.h"
27 #include "llvm/CodeGen/MachineOperand.h"
28 #include "llvm/CodeGen/MachineRegisterInfo.h"
29 #include "llvm/CodeGen/SlotIndexes.h"
30 #include "llvm/CodeGen/TargetInstrInfo.h"
31 #include "llvm/CodeGen/TargetSubtargetInfo.h"
32 #include "llvm/MC/MCInstrDesc.h"
33 #include "llvm/MC/MCRegisterInfo.h"
34 #include "llvm/Support/BranchProbability.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "llvm/Support/MathExtras.h"
37 #include "llvm/Target/TargetMachine.h"
44 #define GET_INSTRINFO_CTOR_DTOR
45 #define GET_INSTRMAP_INFO
46 #include "SystemZGenInstrInfo.inc"
48 #define DEBUG_TYPE "systemz-II"
50 // Return a mask with Count low bits set.
51 static uint64_t allOnes(unsigned int Count
) {
52 return Count
== 0 ? 0 : (uint64_t(1) << (Count
- 1) << 1) - 1;
55 // Pin the vtable to this file.
56 void SystemZInstrInfo::anchor() {}
58 SystemZInstrInfo::SystemZInstrInfo(SystemZSubtarget
&sti
)
59 : SystemZGenInstrInfo(SystemZ::ADJCALLSTACKDOWN
, SystemZ::ADJCALLSTACKUP
),
63 // MI is a 128-bit load or store. Split it into two 64-bit loads or stores,
64 // each having the opcode given by NewOpcode.
65 void SystemZInstrInfo::splitMove(MachineBasicBlock::iterator MI
,
66 unsigned NewOpcode
) const {
67 MachineBasicBlock
*MBB
= MI
->getParent();
68 MachineFunction
&MF
= *MBB
->getParent();
70 // Get two load or store instructions. Use the original instruction for one
71 // of them (arbitrarily the second here) and create a clone for the other.
72 MachineInstr
*EarlierMI
= MF
.CloneMachineInstr(&*MI
);
73 MBB
->insert(MI
, EarlierMI
);
75 // Set up the two 64-bit registers and remember super reg and its flags.
76 MachineOperand
&HighRegOp
= EarlierMI
->getOperand(0);
77 MachineOperand
&LowRegOp
= MI
->getOperand(0);
78 Register Reg128
= LowRegOp
.getReg();
79 unsigned Reg128Killed
= getKillRegState(LowRegOp
.isKill());
80 unsigned Reg128Undef
= getUndefRegState(LowRegOp
.isUndef());
81 HighRegOp
.setReg(RI
.getSubReg(HighRegOp
.getReg(), SystemZ::subreg_h64
));
82 LowRegOp
.setReg(RI
.getSubReg(LowRegOp
.getReg(), SystemZ::subreg_l64
));
85 // Add implicit uses of the super register in case one of the subregs is
86 // undefined. We could track liveness and skip storing an undefined
87 // subreg, but this is hopefully rare (discovered with llvm-stress).
88 // If Reg128 was killed, set kill flag on MI.
89 unsigned Reg128UndefImpl
= (Reg128Undef
| RegState::Implicit
);
90 MachineInstrBuilder(MF
, EarlierMI
).addReg(Reg128
, Reg128UndefImpl
);
91 MachineInstrBuilder(MF
, MI
).addReg(Reg128
, (Reg128UndefImpl
| Reg128Killed
));
94 // The address in the first (high) instruction is already correct.
95 // Adjust the offset in the second (low) instruction.
96 MachineOperand
&HighOffsetOp
= EarlierMI
->getOperand(2);
97 MachineOperand
&LowOffsetOp
= MI
->getOperand(2);
98 LowOffsetOp
.setImm(LowOffsetOp
.getImm() + 8);
100 // Clear the kill flags on the registers in the first instruction.
101 if (EarlierMI
->getOperand(0).isReg() && EarlierMI
->getOperand(0).isUse())
102 EarlierMI
->getOperand(0).setIsKill(false);
103 EarlierMI
->getOperand(1).setIsKill(false);
104 EarlierMI
->getOperand(3).setIsKill(false);
107 unsigned HighOpcode
= getOpcodeForOffset(NewOpcode
, HighOffsetOp
.getImm());
108 unsigned LowOpcode
= getOpcodeForOffset(NewOpcode
, LowOffsetOp
.getImm());
109 assert(HighOpcode
&& LowOpcode
&& "Both offsets should be in range");
111 EarlierMI
->setDesc(get(HighOpcode
));
112 MI
->setDesc(get(LowOpcode
));
115 // Split ADJDYNALLOC instruction MI.
116 void SystemZInstrInfo::splitAdjDynAlloc(MachineBasicBlock::iterator MI
) const {
117 MachineBasicBlock
*MBB
= MI
->getParent();
118 MachineFunction
&MF
= *MBB
->getParent();
119 MachineFrameInfo
&MFFrame
= MF
.getFrameInfo();
120 MachineOperand
&OffsetMO
= MI
->getOperand(2);
122 uint64_t Offset
= (MFFrame
.getMaxCallFrameSize() +
123 SystemZMC::CallFrameSize
+
125 unsigned NewOpcode
= getOpcodeForOffset(SystemZ::LA
, Offset
);
126 assert(NewOpcode
&& "No support for huge argument lists yet");
127 MI
->setDesc(get(NewOpcode
));
128 OffsetMO
.setImm(Offset
);
131 // MI is an RI-style pseudo instruction. Replace it with LowOpcode
132 // if the first operand is a low GR32 and HighOpcode if the first operand
133 // is a high GR32. ConvertHigh is true if LowOpcode takes a signed operand
134 // and HighOpcode takes an unsigned 32-bit operand. In those cases,
135 // MI has the same kind of operand as LowOpcode, so needs to be converted
136 // if HighOpcode is used.
137 void SystemZInstrInfo::expandRIPseudo(MachineInstr
&MI
, unsigned LowOpcode
,
139 bool ConvertHigh
) const {
140 Register Reg
= MI
.getOperand(0).getReg();
141 bool IsHigh
= SystemZ::isHighReg(Reg
);
142 MI
.setDesc(get(IsHigh
? HighOpcode
: LowOpcode
));
143 if (IsHigh
&& ConvertHigh
)
144 MI
.getOperand(1).setImm(uint32_t(MI
.getOperand(1).getImm()));
147 // MI is a three-operand RIE-style pseudo instruction. Replace it with
148 // LowOpcodeK if the registers are both low GR32s, otherwise use a move
149 // followed by HighOpcode or LowOpcode, depending on whether the target
150 // is a high or low GR32.
151 void SystemZInstrInfo::expandRIEPseudo(MachineInstr
&MI
, unsigned LowOpcode
,
153 unsigned HighOpcode
) const {
154 Register DestReg
= MI
.getOperand(0).getReg();
155 Register SrcReg
= MI
.getOperand(1).getReg();
156 bool DestIsHigh
= SystemZ::isHighReg(DestReg
);
157 bool SrcIsHigh
= SystemZ::isHighReg(SrcReg
);
158 if (!DestIsHigh
&& !SrcIsHigh
)
159 MI
.setDesc(get(LowOpcodeK
));
161 if (DestReg
!= SrcReg
) {
162 emitGRX32Move(*MI
.getParent(), MI
, MI
.getDebugLoc(), DestReg
, SrcReg
,
163 SystemZ::LR
, 32, MI
.getOperand(1).isKill(),
164 MI
.getOperand(1).isUndef());
165 MI
.getOperand(1).setReg(DestReg
);
167 MI
.setDesc(get(DestIsHigh
? HighOpcode
: LowOpcode
));
168 MI
.tieOperands(0, 1);
172 // MI is an RXY-style pseudo instruction. Replace it with LowOpcode
173 // if the first operand is a low GR32 and HighOpcode if the first operand
175 void SystemZInstrInfo::expandRXYPseudo(MachineInstr
&MI
, unsigned LowOpcode
,
176 unsigned HighOpcode
) const {
177 Register Reg
= MI
.getOperand(0).getReg();
178 unsigned Opcode
= getOpcodeForOffset(
179 SystemZ::isHighReg(Reg
) ? HighOpcode
: LowOpcode
,
180 MI
.getOperand(2).getImm());
181 MI
.setDesc(get(Opcode
));
184 // MI is a load-on-condition pseudo instruction with a single register
185 // (source or destination) operand. Replace it with LowOpcode if the
186 // register is a low GR32 and HighOpcode if the register is a high GR32.
187 void SystemZInstrInfo::expandLOCPseudo(MachineInstr
&MI
, unsigned LowOpcode
,
188 unsigned HighOpcode
) const {
189 Register Reg
= MI
.getOperand(0).getReg();
190 unsigned Opcode
= SystemZ::isHighReg(Reg
) ? HighOpcode
: LowOpcode
;
191 MI
.setDesc(get(Opcode
));
194 // MI is an RR-style pseudo instruction that zero-extends the low Size bits
195 // of one GRX32 into another. Replace it with LowOpcode if both operands
196 // are low registers, otherwise use RISB[LH]G.
197 void SystemZInstrInfo::expandZExtPseudo(MachineInstr
&MI
, unsigned LowOpcode
,
198 unsigned Size
) const {
199 MachineInstrBuilder MIB
=
200 emitGRX32Move(*MI
.getParent(), MI
, MI
.getDebugLoc(),
201 MI
.getOperand(0).getReg(), MI
.getOperand(1).getReg(), LowOpcode
,
202 Size
, MI
.getOperand(1).isKill(), MI
.getOperand(1).isUndef());
204 // Keep the remaining operands as-is.
205 for (unsigned I
= 2; I
< MI
.getNumOperands(); ++I
)
206 MIB
.add(MI
.getOperand(I
));
208 MI
.eraseFromParent();
211 void SystemZInstrInfo::expandLoadStackGuard(MachineInstr
*MI
) const {
212 MachineBasicBlock
*MBB
= MI
->getParent();
213 MachineFunction
&MF
= *MBB
->getParent();
214 const Register Reg64
= MI
->getOperand(0).getReg();
215 const Register Reg32
= RI
.getSubReg(Reg64
, SystemZ::subreg_l32
);
217 // EAR can only load the low subregister so us a shift for %a0 to produce
218 // the GR containing %a0 and %a1.
221 BuildMI(*MBB
, MI
, MI
->getDebugLoc(), get(SystemZ::EAR
), Reg32
)
223 .addReg(Reg64
, RegState::ImplicitDefine
);
225 // sllg <reg>, <reg>, 32
226 BuildMI(*MBB
, MI
, MI
->getDebugLoc(), get(SystemZ::SLLG
), Reg64
)
232 BuildMI(*MBB
, MI
, MI
->getDebugLoc(), get(SystemZ::EAR
), Reg32
)
233 .addReg(SystemZ::A1
);
235 // lg <reg>, 40(<reg>)
236 MI
->setDesc(get(SystemZ::LG
));
237 MachineInstrBuilder(MF
, MI
).addReg(Reg64
).addImm(40).addReg(0);
240 // Emit a zero-extending move from 32-bit GPR SrcReg to 32-bit GPR
241 // DestReg before MBBI in MBB. Use LowLowOpcode when both DestReg and SrcReg
242 // are low registers, otherwise use RISB[LH]G. Size is the number of bits
243 // taken from the low end of SrcReg (8 for LLCR, 16 for LLHR and 32 for LR).
244 // KillSrc is true if this move is the last use of SrcReg.
246 SystemZInstrInfo::emitGRX32Move(MachineBasicBlock
&MBB
,
247 MachineBasicBlock::iterator MBBI
,
248 const DebugLoc
&DL
, unsigned DestReg
,
249 unsigned SrcReg
, unsigned LowLowOpcode
,
250 unsigned Size
, bool KillSrc
,
251 bool UndefSrc
) const {
253 bool DestIsHigh
= SystemZ::isHighReg(DestReg
);
254 bool SrcIsHigh
= SystemZ::isHighReg(SrcReg
);
255 if (DestIsHigh
&& SrcIsHigh
)
256 Opcode
= SystemZ::RISBHH
;
257 else if (DestIsHigh
&& !SrcIsHigh
)
258 Opcode
= SystemZ::RISBHL
;
259 else if (!DestIsHigh
&& SrcIsHigh
)
260 Opcode
= SystemZ::RISBLH
;
262 return BuildMI(MBB
, MBBI
, DL
, get(LowLowOpcode
), DestReg
)
263 .addReg(SrcReg
, getKillRegState(KillSrc
) | getUndefRegState(UndefSrc
));
265 unsigned Rotate
= (DestIsHigh
!= SrcIsHigh
? 32 : 0);
266 return BuildMI(MBB
, MBBI
, DL
, get(Opcode
), DestReg
)
267 .addReg(DestReg
, RegState::Undef
)
268 .addReg(SrcReg
, getKillRegState(KillSrc
) | getUndefRegState(UndefSrc
))
269 .addImm(32 - Size
).addImm(128 + 31).addImm(Rotate
);
272 MachineInstr
*SystemZInstrInfo::commuteInstructionImpl(MachineInstr
&MI
,
275 unsigned OpIdx2
) const {
276 auto cloneIfNew
= [NewMI
](MachineInstr
&MI
) -> MachineInstr
& {
278 return *MI
.getParent()->getParent()->CloneMachineInstr(&MI
);
282 switch (MI
.getOpcode()) {
283 case SystemZ::SELRMux
:
284 case SystemZ::SELFHR
:
287 case SystemZ::LOCRMux
:
288 case SystemZ::LOCFHR
:
290 case SystemZ::LOCGR
: {
291 auto &WorkingMI
= cloneIfNew(MI
);
293 unsigned CCValid
= WorkingMI
.getOperand(3).getImm();
294 unsigned CCMask
= WorkingMI
.getOperand(4).getImm();
295 WorkingMI
.getOperand(4).setImm(CCMask
^ CCValid
);
296 return TargetInstrInfo::commuteInstructionImpl(WorkingMI
, /*NewMI=*/false,
300 return TargetInstrInfo::commuteInstructionImpl(MI
, NewMI
, OpIdx1
, OpIdx2
);
304 // If MI is a simple load or store for a frame object, return the register
305 // it loads or stores and set FrameIndex to the index of the frame object.
306 // Return 0 otherwise.
308 // Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores.
309 static int isSimpleMove(const MachineInstr
&MI
, int &FrameIndex
,
311 const MCInstrDesc
&MCID
= MI
.getDesc();
312 if ((MCID
.TSFlags
& Flag
) && MI
.getOperand(1).isFI() &&
313 MI
.getOperand(2).getImm() == 0 && MI
.getOperand(3).getReg() == 0) {
314 FrameIndex
= MI
.getOperand(1).getIndex();
315 return MI
.getOperand(0).getReg();
320 unsigned SystemZInstrInfo::isLoadFromStackSlot(const MachineInstr
&MI
,
321 int &FrameIndex
) const {
322 return isSimpleMove(MI
, FrameIndex
, SystemZII::SimpleBDXLoad
);
325 unsigned SystemZInstrInfo::isStoreToStackSlot(const MachineInstr
&MI
,
326 int &FrameIndex
) const {
327 return isSimpleMove(MI
, FrameIndex
, SystemZII::SimpleBDXStore
);
330 bool SystemZInstrInfo::isStackSlotCopy(const MachineInstr
&MI
,
332 int &SrcFrameIndex
) const {
333 // Check for MVC 0(Length,FI1),0(FI2)
334 const MachineFrameInfo
&MFI
= MI
.getParent()->getParent()->getFrameInfo();
335 if (MI
.getOpcode() != SystemZ::MVC
|| !MI
.getOperand(0).isFI() ||
336 MI
.getOperand(1).getImm() != 0 || !MI
.getOperand(3).isFI() ||
337 MI
.getOperand(4).getImm() != 0)
340 // Check that Length covers the full slots.
341 int64_t Length
= MI
.getOperand(2).getImm();
342 unsigned FI1
= MI
.getOperand(0).getIndex();
343 unsigned FI2
= MI
.getOperand(3).getIndex();
344 if (MFI
.getObjectSize(FI1
) != Length
||
345 MFI
.getObjectSize(FI2
) != Length
)
348 DestFrameIndex
= FI1
;
353 bool SystemZInstrInfo::analyzeBranch(MachineBasicBlock
&MBB
,
354 MachineBasicBlock
*&TBB
,
355 MachineBasicBlock
*&FBB
,
356 SmallVectorImpl
<MachineOperand
> &Cond
,
357 bool AllowModify
) const {
358 // Most of the code and comments here are boilerplate.
360 // Start from the bottom of the block and work up, examining the
361 // terminator instructions.
362 MachineBasicBlock::iterator I
= MBB
.end();
363 while (I
!= MBB
.begin()) {
365 if (I
->isDebugInstr())
368 // Working from the bottom, when we see a non-terminator instruction, we're
370 if (!isUnpredicatedTerminator(*I
))
373 // A terminator that isn't a branch can't easily be handled by this
378 // Can't handle indirect branches.
379 SystemZII::Branch
Branch(getBranchInfo(*I
));
380 if (!Branch
.hasMBBTarget())
383 // Punt on compound branches.
384 if (Branch
.Type
!= SystemZII::BranchNormal
)
387 if (Branch
.CCMask
== SystemZ::CCMASK_ANY
) {
388 // Handle unconditional branches.
390 TBB
= Branch
.getMBBTarget();
394 // If the block has any instructions after a JMP, delete them.
395 while (std::next(I
) != MBB
.end())
396 std::next(I
)->eraseFromParent();
401 // Delete the JMP if it's equivalent to a fall-through.
402 if (MBB
.isLayoutSuccessor(Branch
.getMBBTarget())) {
404 I
->eraseFromParent();
409 // TBB is used to indicate the unconditinal destination.
410 TBB
= Branch
.getMBBTarget();
414 // Working from the bottom, handle the first conditional branch.
416 // FIXME: add X86-style branch swap
418 TBB
= Branch
.getMBBTarget();
419 Cond
.push_back(MachineOperand::CreateImm(Branch
.CCValid
));
420 Cond
.push_back(MachineOperand::CreateImm(Branch
.CCMask
));
424 // Handle subsequent conditional branches.
425 assert(Cond
.size() == 2 && TBB
&& "Should have seen a conditional branch");
427 // Only handle the case where all conditional branches branch to the same
429 if (TBB
!= Branch
.getMBBTarget())
432 // If the conditions are the same, we can leave them alone.
433 unsigned OldCCValid
= Cond
[0].getImm();
434 unsigned OldCCMask
= Cond
[1].getImm();
435 if (OldCCValid
== Branch
.CCValid
&& OldCCMask
== Branch
.CCMask
)
438 // FIXME: Try combining conditions like X86 does. Should be easy on Z!
445 unsigned SystemZInstrInfo::removeBranch(MachineBasicBlock
&MBB
,
446 int *BytesRemoved
) const {
447 assert(!BytesRemoved
&& "code size not handled");
449 // Most of the code and comments here are boilerplate.
450 MachineBasicBlock::iterator I
= MBB
.end();
453 while (I
!= MBB
.begin()) {
455 if (I
->isDebugInstr())
459 if (!getBranchInfo(*I
).hasMBBTarget())
461 // Remove the branch.
462 I
->eraseFromParent();
470 bool SystemZInstrInfo::
471 reverseBranchCondition(SmallVectorImpl
<MachineOperand
> &Cond
) const {
472 assert(Cond
.size() == 2 && "Invalid condition");
473 Cond
[1].setImm(Cond
[1].getImm() ^ Cond
[0].getImm());
477 unsigned SystemZInstrInfo::insertBranch(MachineBasicBlock
&MBB
,
478 MachineBasicBlock
*TBB
,
479 MachineBasicBlock
*FBB
,
480 ArrayRef
<MachineOperand
> Cond
,
482 int *BytesAdded
) const {
483 // In this function we output 32-bit branches, which should always
484 // have enough range. They can be shortened and relaxed by later code
485 // in the pipeline, if desired.
487 // Shouldn't be a fall through.
488 assert(TBB
&& "insertBranch must not be told to insert a fallthrough");
489 assert((Cond
.size() == 2 || Cond
.size() == 0) &&
490 "SystemZ branch conditions have one component!");
491 assert(!BytesAdded
&& "code size not handled");
494 // Unconditional branch?
495 assert(!FBB
&& "Unconditional branch with multiple successors!");
496 BuildMI(&MBB
, DL
, get(SystemZ::J
)).addMBB(TBB
);
500 // Conditional branch.
502 unsigned CCValid
= Cond
[0].getImm();
503 unsigned CCMask
= Cond
[1].getImm();
504 BuildMI(&MBB
, DL
, get(SystemZ::BRC
))
505 .addImm(CCValid
).addImm(CCMask
).addMBB(TBB
);
509 // Two-way Conditional branch. Insert the second branch.
510 BuildMI(&MBB
, DL
, get(SystemZ::J
)).addMBB(FBB
);
516 bool SystemZInstrInfo::analyzeCompare(const MachineInstr
&MI
, unsigned &SrcReg
,
517 unsigned &SrcReg2
, int &Mask
,
519 assert(MI
.isCompare() && "Caller should have checked for a comparison");
521 if (MI
.getNumExplicitOperands() == 2 && MI
.getOperand(0).isReg() &&
522 MI
.getOperand(1).isImm()) {
523 SrcReg
= MI
.getOperand(0).getReg();
525 Value
= MI
.getOperand(1).getImm();
533 bool SystemZInstrInfo::canInsertSelect(const MachineBasicBlock
&MBB
,
534 ArrayRef
<MachineOperand
> Pred
,
535 unsigned DstReg
, unsigned TrueReg
,
536 unsigned FalseReg
, int &CondCycles
,
538 int &FalseCycles
) const {
539 // Not all subtargets have LOCR instructions.
540 if (!STI
.hasLoadStoreOnCond())
542 if (Pred
.size() != 2)
545 // Check register classes.
546 const MachineRegisterInfo
&MRI
= MBB
.getParent()->getRegInfo();
547 const TargetRegisterClass
*RC
=
548 RI
.getCommonSubClass(MRI
.getRegClass(TrueReg
), MRI
.getRegClass(FalseReg
));
552 // We have LOCR instructions for 32 and 64 bit general purpose registers.
553 if ((STI
.hasLoadStoreOnCond2() &&
554 SystemZ::GRX32BitRegClass
.hasSubClassEq(RC
)) ||
555 SystemZ::GR32BitRegClass
.hasSubClassEq(RC
) ||
556 SystemZ::GR64BitRegClass
.hasSubClassEq(RC
)) {
563 // Can't do anything else.
567 void SystemZInstrInfo::insertSelect(MachineBasicBlock
&MBB
,
568 MachineBasicBlock::iterator I
,
569 const DebugLoc
&DL
, unsigned DstReg
,
570 ArrayRef
<MachineOperand
> Pred
,
572 unsigned FalseReg
) const {
573 MachineRegisterInfo
&MRI
= MBB
.getParent()->getRegInfo();
574 const TargetRegisterClass
*RC
= MRI
.getRegClass(DstReg
);
576 assert(Pred
.size() == 2 && "Invalid condition");
577 unsigned CCValid
= Pred
[0].getImm();
578 unsigned CCMask
= Pred
[1].getImm();
581 if (SystemZ::GRX32BitRegClass
.hasSubClassEq(RC
)) {
582 if (STI
.hasMiscellaneousExtensions3())
583 Opc
= SystemZ::SELRMux
;
584 else if (STI
.hasLoadStoreOnCond2())
585 Opc
= SystemZ::LOCRMux
;
588 MRI
.constrainRegClass(DstReg
, &SystemZ::GR32BitRegClass
);
589 Register TReg
= MRI
.createVirtualRegister(&SystemZ::GR32BitRegClass
);
590 Register FReg
= MRI
.createVirtualRegister(&SystemZ::GR32BitRegClass
);
591 BuildMI(MBB
, I
, DL
, get(TargetOpcode::COPY
), TReg
).addReg(TrueReg
);
592 BuildMI(MBB
, I
, DL
, get(TargetOpcode::COPY
), FReg
).addReg(FalseReg
);
596 } else if (SystemZ::GR64BitRegClass
.hasSubClassEq(RC
)) {
597 if (STI
.hasMiscellaneousExtensions3())
598 Opc
= SystemZ::SELGR
;
600 Opc
= SystemZ::LOCGR
;
602 llvm_unreachable("Invalid register class");
604 BuildMI(MBB
, I
, DL
, get(Opc
), DstReg
)
605 .addReg(FalseReg
).addReg(TrueReg
)
606 .addImm(CCValid
).addImm(CCMask
);
609 bool SystemZInstrInfo::FoldImmediate(MachineInstr
&UseMI
, MachineInstr
&DefMI
,
611 MachineRegisterInfo
*MRI
) const {
612 unsigned DefOpc
= DefMI
.getOpcode();
613 if (DefOpc
!= SystemZ::LHIMux
&& DefOpc
!= SystemZ::LHI
&&
614 DefOpc
!= SystemZ::LGHI
)
616 if (DefMI
.getOperand(0).getReg() != Reg
)
618 int32_t ImmVal
= (int32_t)DefMI
.getOperand(1).getImm();
620 unsigned UseOpc
= UseMI
.getOpcode();
626 case SystemZ::SELRMux
:
629 case SystemZ::LOCRMux
:
630 if (!STI
.hasLoadStoreOnCond2())
632 NewUseOpc
= SystemZ::LOCHIMux
;
633 if (UseMI
.getOperand(2).getReg() == Reg
)
635 else if (UseMI
.getOperand(1).getReg() == Reg
)
636 UseIdx
= 2, CommuteIdx
= 1;
644 if (!STI
.hasLoadStoreOnCond2())
646 NewUseOpc
= SystemZ::LOCGHI
;
647 if (UseMI
.getOperand(2).getReg() == Reg
)
649 else if (UseMI
.getOperand(1).getReg() == Reg
)
650 UseIdx
= 2, CommuteIdx
= 1;
658 if (CommuteIdx
!= -1)
659 if (!commuteInstruction(UseMI
, false, CommuteIdx
, UseIdx
))
662 bool DeleteDef
= MRI
->hasOneNonDBGUse(Reg
);
663 UseMI
.setDesc(get(NewUseOpc
));
665 UseMI
.tieOperands(0, 1);
666 UseMI
.getOperand(UseIdx
).ChangeToImmediate(ImmVal
);
668 DefMI
.eraseFromParent();
673 bool SystemZInstrInfo::isPredicable(const MachineInstr
&MI
) const {
674 unsigned Opcode
= MI
.getOpcode();
675 if (Opcode
== SystemZ::Return
||
676 Opcode
== SystemZ::Trap
||
677 Opcode
== SystemZ::CallJG
||
678 Opcode
== SystemZ::CallBR
)
683 bool SystemZInstrInfo::
684 isProfitableToIfCvt(MachineBasicBlock
&MBB
,
685 unsigned NumCycles
, unsigned ExtraPredCycles
,
686 BranchProbability Probability
) const {
687 // Avoid using conditional returns at the end of a loop (since then
688 // we'd need to emit an unconditional branch to the beginning anyway,
689 // making the loop body longer). This doesn't apply for low-probability
690 // loops (eg. compare-and-swap retry), so just decide based on branch
691 // probability instead of looping structure.
692 // However, since Compare and Trap instructions cost the same as a regular
693 // Compare instruction, we should allow the if conversion to convert this
694 // into a Conditional Compare regardless of the branch probability.
695 if (MBB
.getLastNonDebugInstr()->getOpcode() != SystemZ::Trap
&&
696 MBB
.succ_empty() && Probability
< BranchProbability(1, 8))
698 // For now only convert single instructions.
699 return NumCycles
== 1;
702 bool SystemZInstrInfo::
703 isProfitableToIfCvt(MachineBasicBlock
&TMBB
,
704 unsigned NumCyclesT
, unsigned ExtraPredCyclesT
,
705 MachineBasicBlock
&FMBB
,
706 unsigned NumCyclesF
, unsigned ExtraPredCyclesF
,
707 BranchProbability Probability
) const {
708 // For now avoid converting mutually-exclusive cases.
712 bool SystemZInstrInfo::
713 isProfitableToDupForIfCvt(MachineBasicBlock
&MBB
, unsigned NumCycles
,
714 BranchProbability Probability
) const {
715 // For now only duplicate single instructions.
716 return NumCycles
== 1;
719 bool SystemZInstrInfo::PredicateInstruction(
720 MachineInstr
&MI
, ArrayRef
<MachineOperand
> Pred
) const {
721 assert(Pred
.size() == 2 && "Invalid condition");
722 unsigned CCValid
= Pred
[0].getImm();
723 unsigned CCMask
= Pred
[1].getImm();
724 assert(CCMask
> 0 && CCMask
< 15 && "Invalid predicate");
725 unsigned Opcode
= MI
.getOpcode();
726 if (Opcode
== SystemZ::Trap
) {
727 MI
.setDesc(get(SystemZ::CondTrap
));
728 MachineInstrBuilder(*MI
.getParent()->getParent(), MI
)
729 .addImm(CCValid
).addImm(CCMask
)
730 .addReg(SystemZ::CC
, RegState::Implicit
);
733 if (Opcode
== SystemZ::Return
) {
734 MI
.setDesc(get(SystemZ::CondReturn
));
735 MachineInstrBuilder(*MI
.getParent()->getParent(), MI
)
736 .addImm(CCValid
).addImm(CCMask
)
737 .addReg(SystemZ::CC
, RegState::Implicit
);
740 if (Opcode
== SystemZ::CallJG
) {
741 MachineOperand FirstOp
= MI
.getOperand(0);
742 const uint32_t *RegMask
= MI
.getOperand(1).getRegMask();
745 MI
.setDesc(get(SystemZ::CallBRCL
));
746 MachineInstrBuilder(*MI
.getParent()->getParent(), MI
)
751 .addReg(SystemZ::CC
, RegState::Implicit
);
754 if (Opcode
== SystemZ::CallBR
) {
755 const uint32_t *RegMask
= MI
.getOperand(0).getRegMask();
757 MI
.setDesc(get(SystemZ::CallBCR
));
758 MachineInstrBuilder(*MI
.getParent()->getParent(), MI
)
759 .addImm(CCValid
).addImm(CCMask
)
761 .addReg(SystemZ::CC
, RegState::Implicit
);
767 void SystemZInstrInfo::copyPhysReg(MachineBasicBlock
&MBB
,
768 MachineBasicBlock::iterator MBBI
,
769 const DebugLoc
&DL
, MCRegister DestReg
,
770 MCRegister SrcReg
, bool KillSrc
) const {
771 // Split 128-bit GPR moves into two 64-bit moves. Add implicit uses of the
772 // super register in case one of the subregs is undefined.
773 // This handles ADDR128 too.
774 if (SystemZ::GR128BitRegClass
.contains(DestReg
, SrcReg
)) {
775 copyPhysReg(MBB
, MBBI
, DL
, RI
.getSubReg(DestReg
, SystemZ::subreg_h64
),
776 RI
.getSubReg(SrcReg
, SystemZ::subreg_h64
), KillSrc
);
777 MachineInstrBuilder(*MBB
.getParent(), std::prev(MBBI
))
778 .addReg(SrcReg
, RegState::Implicit
);
779 copyPhysReg(MBB
, MBBI
, DL
, RI
.getSubReg(DestReg
, SystemZ::subreg_l64
),
780 RI
.getSubReg(SrcReg
, SystemZ::subreg_l64
), KillSrc
);
781 MachineInstrBuilder(*MBB
.getParent(), std::prev(MBBI
))
782 .addReg(SrcReg
, (getKillRegState(KillSrc
) | RegState::Implicit
));
786 if (SystemZ::GRX32BitRegClass
.contains(DestReg
, SrcReg
)) {
787 emitGRX32Move(MBB
, MBBI
, DL
, DestReg
, SrcReg
, SystemZ::LR
, 32, KillSrc
,
792 // Move 128-bit floating-point values between VR128 and FP128.
793 if (SystemZ::VR128BitRegClass
.contains(DestReg
) &&
794 SystemZ::FP128BitRegClass
.contains(SrcReg
)) {
795 MCRegister SrcRegHi
=
796 RI
.getMatchingSuperReg(RI
.getSubReg(SrcReg
, SystemZ::subreg_h64
),
797 SystemZ::subreg_h64
, &SystemZ::VR128BitRegClass
);
798 MCRegister SrcRegLo
=
799 RI
.getMatchingSuperReg(RI
.getSubReg(SrcReg
, SystemZ::subreg_l64
),
800 SystemZ::subreg_h64
, &SystemZ::VR128BitRegClass
);
802 BuildMI(MBB
, MBBI
, DL
, get(SystemZ::VMRHG
), DestReg
)
803 .addReg(SrcRegHi
, getKillRegState(KillSrc
))
804 .addReg(SrcRegLo
, getKillRegState(KillSrc
));
807 if (SystemZ::FP128BitRegClass
.contains(DestReg
) &&
808 SystemZ::VR128BitRegClass
.contains(SrcReg
)) {
809 MCRegister DestRegHi
=
810 RI
.getMatchingSuperReg(RI
.getSubReg(DestReg
, SystemZ::subreg_h64
),
811 SystemZ::subreg_h64
, &SystemZ::VR128BitRegClass
);
812 MCRegister DestRegLo
=
813 RI
.getMatchingSuperReg(RI
.getSubReg(DestReg
, SystemZ::subreg_l64
),
814 SystemZ::subreg_h64
, &SystemZ::VR128BitRegClass
);
816 if (DestRegHi
!= SrcReg
)
817 copyPhysReg(MBB
, MBBI
, DL
, DestRegHi
, SrcReg
, false);
818 BuildMI(MBB
, MBBI
, DL
, get(SystemZ::VREPG
), DestRegLo
)
819 .addReg(SrcReg
, getKillRegState(KillSrc
)).addImm(1);
823 // Move CC value from/to a GR32.
824 if (SrcReg
== SystemZ::CC
) {
825 auto MIB
= BuildMI(MBB
, MBBI
, DL
, get(SystemZ::IPM
), DestReg
);
827 const MachineFunction
*MF
= MBB
.getParent();
828 const TargetRegisterInfo
*TRI
= MF
->getSubtarget().getRegisterInfo();
829 MIB
->addRegisterKilled(SrcReg
, TRI
);
833 if (DestReg
== SystemZ::CC
) {
834 BuildMI(MBB
, MBBI
, DL
, get(SystemZ::TMLH
))
835 .addReg(SrcReg
, getKillRegState(KillSrc
))
836 .addImm(3 << (SystemZ::IPM_CC
- 16));
840 // Everything else needs only one instruction.
842 if (SystemZ::GR64BitRegClass
.contains(DestReg
, SrcReg
))
843 Opcode
= SystemZ::LGR
;
844 else if (SystemZ::FP32BitRegClass
.contains(DestReg
, SrcReg
))
845 // For z13 we prefer LDR over LER to avoid partial register dependencies.
846 Opcode
= STI
.hasVector() ? SystemZ::LDR32
: SystemZ::LER
;
847 else if (SystemZ::FP64BitRegClass
.contains(DestReg
, SrcReg
))
848 Opcode
= SystemZ::LDR
;
849 else if (SystemZ::FP128BitRegClass
.contains(DestReg
, SrcReg
))
850 Opcode
= SystemZ::LXR
;
851 else if (SystemZ::VR32BitRegClass
.contains(DestReg
, SrcReg
))
852 Opcode
= SystemZ::VLR32
;
853 else if (SystemZ::VR64BitRegClass
.contains(DestReg
, SrcReg
))
854 Opcode
= SystemZ::VLR64
;
855 else if (SystemZ::VR128BitRegClass
.contains(DestReg
, SrcReg
))
856 Opcode
= SystemZ::VLR
;
857 else if (SystemZ::AR32BitRegClass
.contains(DestReg
, SrcReg
))
858 Opcode
= SystemZ::CPYA
;
859 else if (SystemZ::AR32BitRegClass
.contains(DestReg
) &&
860 SystemZ::GR32BitRegClass
.contains(SrcReg
))
861 Opcode
= SystemZ::SAR
;
862 else if (SystemZ::GR32BitRegClass
.contains(DestReg
) &&
863 SystemZ::AR32BitRegClass
.contains(SrcReg
))
864 Opcode
= SystemZ::EAR
;
866 llvm_unreachable("Impossible reg-to-reg copy");
868 BuildMI(MBB
, MBBI
, DL
, get(Opcode
), DestReg
)
869 .addReg(SrcReg
, getKillRegState(KillSrc
));
872 void SystemZInstrInfo::storeRegToStackSlot(
873 MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MBBI
, unsigned SrcReg
,
874 bool isKill
, int FrameIdx
, const TargetRegisterClass
*RC
,
875 const TargetRegisterInfo
*TRI
) const {
876 DebugLoc DL
= MBBI
!= MBB
.end() ? MBBI
->getDebugLoc() : DebugLoc();
878 // Callers may expect a single instruction, so keep 128-bit moves
879 // together for now and lower them after register allocation.
880 unsigned LoadOpcode
, StoreOpcode
;
881 getLoadStoreOpcodes(RC
, LoadOpcode
, StoreOpcode
);
882 addFrameReference(BuildMI(MBB
, MBBI
, DL
, get(StoreOpcode
))
883 .addReg(SrcReg
, getKillRegState(isKill
)),
887 void SystemZInstrInfo::loadRegFromStackSlot(
888 MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MBBI
, unsigned DestReg
,
889 int FrameIdx
, const TargetRegisterClass
*RC
,
890 const TargetRegisterInfo
*TRI
) const {
891 DebugLoc DL
= MBBI
!= MBB
.end() ? MBBI
->getDebugLoc() : DebugLoc();
893 // Callers may expect a single instruction, so keep 128-bit moves
894 // together for now and lower them after register allocation.
895 unsigned LoadOpcode
, StoreOpcode
;
896 getLoadStoreOpcodes(RC
, LoadOpcode
, StoreOpcode
);
897 addFrameReference(BuildMI(MBB
, MBBI
, DL
, get(LoadOpcode
), DestReg
),
901 // Return true if MI is a simple load or store with a 12-bit displacement
902 // and no index. Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores.
903 static bool isSimpleBD12Move(const MachineInstr
*MI
, unsigned Flag
) {
904 const MCInstrDesc
&MCID
= MI
->getDesc();
905 return ((MCID
.TSFlags
& Flag
) &&
906 isUInt
<12>(MI
->getOperand(2).getImm()) &&
907 MI
->getOperand(3).getReg() == 0);
914 LogicOp(unsigned regSize
, unsigned immLSB
, unsigned immSize
)
915 : RegSize(regSize
), ImmLSB(immLSB
), ImmSize(immSize
) {}
917 explicit operator bool() const { return RegSize
; }
919 unsigned RegSize
= 0;
921 unsigned ImmSize
= 0;
924 } // end anonymous namespace
926 static LogicOp
interpretAndImmediate(unsigned Opcode
) {
928 case SystemZ::NILMux
: return LogicOp(32, 0, 16);
929 case SystemZ::NIHMux
: return LogicOp(32, 16, 16);
930 case SystemZ::NILL64
: return LogicOp(64, 0, 16);
931 case SystemZ::NILH64
: return LogicOp(64, 16, 16);
932 case SystemZ::NIHL64
: return LogicOp(64, 32, 16);
933 case SystemZ::NIHH64
: return LogicOp(64, 48, 16);
934 case SystemZ::NIFMux
: return LogicOp(32, 0, 32);
935 case SystemZ::NILF64
: return LogicOp(64, 0, 32);
936 case SystemZ::NIHF64
: return LogicOp(64, 32, 32);
937 default: return LogicOp();
941 static void transferDeadCC(MachineInstr
*OldMI
, MachineInstr
*NewMI
) {
942 if (OldMI
->registerDefIsDead(SystemZ::CC
)) {
943 MachineOperand
*CCDef
= NewMI
->findRegisterDefOperand(SystemZ::CC
);
944 if (CCDef
!= nullptr)
945 CCDef
->setIsDead(true);
949 static void transferMIFlag(MachineInstr
*OldMI
, MachineInstr
*NewMI
,
950 MachineInstr::MIFlag Flag
) {
951 if (OldMI
->getFlag(Flag
))
952 NewMI
->setFlag(Flag
);
955 MachineInstr
*SystemZInstrInfo::convertToThreeAddress(
956 MachineFunction::iterator
&MFI
, MachineInstr
&MI
, LiveVariables
*LV
) const {
957 MachineBasicBlock
*MBB
= MI
.getParent();
959 // Try to convert an AND into an RISBG-type instruction.
960 // TODO: It might be beneficial to select RISBG and shorten to AND instead.
961 if (LogicOp And
= interpretAndImmediate(MI
.getOpcode())) {
962 uint64_t Imm
= MI
.getOperand(2).getImm() << And
.ImmLSB
;
963 // AND IMMEDIATE leaves the other bits of the register unchanged.
964 Imm
|= allOnes(And
.RegSize
) & ~(allOnes(And
.ImmSize
) << And
.ImmLSB
);
966 if (isRxSBGMask(Imm
, And
.RegSize
, Start
, End
)) {
968 if (And
.RegSize
== 64) {
969 NewOpcode
= SystemZ::RISBG
;
970 // Prefer RISBGN if available, since it does not clobber CC.
971 if (STI
.hasMiscellaneousExtensions())
972 NewOpcode
= SystemZ::RISBGN
;
974 NewOpcode
= SystemZ::RISBMux
;
978 MachineOperand
&Dest
= MI
.getOperand(0);
979 MachineOperand
&Src
= MI
.getOperand(1);
980 MachineInstrBuilder MIB
=
981 BuildMI(*MBB
, MI
, MI
.getDebugLoc(), get(NewOpcode
))
984 .addReg(Src
.getReg(), getKillRegState(Src
.isKill()),
990 unsigned NumOps
= MI
.getNumOperands();
991 for (unsigned I
= 1; I
< NumOps
; ++I
) {
992 MachineOperand
&Op
= MI
.getOperand(I
);
993 if (Op
.isReg() && Op
.isKill())
994 LV
->replaceKillInstruction(Op
.getReg(), MI
, *MIB
);
997 transferDeadCC(&MI
, MIB
);
1004 MachineInstr
*SystemZInstrInfo::foldMemoryOperandImpl(
1005 MachineFunction
&MF
, MachineInstr
&MI
, ArrayRef
<unsigned> Ops
,
1006 MachineBasicBlock::iterator InsertPt
, int FrameIndex
,
1007 LiveIntervals
*LIS
, VirtRegMap
*VRM
) const {
1008 const TargetRegisterInfo
*TRI
= MF
.getSubtarget().getRegisterInfo();
1009 const MachineFrameInfo
&MFI
= MF
.getFrameInfo();
1010 unsigned Size
= MFI
.getObjectSize(FrameIndex
);
1011 unsigned Opcode
= MI
.getOpcode();
1013 if (Ops
.size() == 2 && Ops
[0] == 0 && Ops
[1] == 1) {
1014 if (LIS
!= nullptr && (Opcode
== SystemZ::LA
|| Opcode
== SystemZ::LAY
) &&
1015 isInt
<8>(MI
.getOperand(2).getImm()) && !MI
.getOperand(3).getReg()) {
1017 // Check CC liveness, since new instruction introduces a dead
1019 MCRegUnitIterator
CCUnit(SystemZ::CC
, TRI
);
1020 LiveRange
&CCLiveRange
= LIS
->getRegUnit(*CCUnit
);
1022 assert(!CCUnit
.isValid() && "CC only has one reg unit.");
1024 LIS
->getSlotIndexes()->getInstructionIndex(MI
).getRegSlot();
1025 if (!CCLiveRange
.liveAt(MISlot
)) {
1026 // LA(Y) %reg, CONST(%reg) -> AGSI %mem, CONST
1027 MachineInstr
*BuiltMI
= BuildMI(*InsertPt
->getParent(), InsertPt
,
1028 MI
.getDebugLoc(), get(SystemZ::AGSI
))
1029 .addFrameIndex(FrameIndex
)
1031 .addImm(MI
.getOperand(2).getImm());
1032 BuiltMI
->findRegisterDefOperand(SystemZ::CC
)->setIsDead(true);
1033 CCLiveRange
.createDeadDef(MISlot
, LIS
->getVNInfoAllocator());
1040 // All other cases require a single operand.
1041 if (Ops
.size() != 1)
1044 unsigned OpNum
= Ops
[0];
1046 TRI
->getRegSizeInBits(*MF
.getRegInfo()
1047 .getRegClass(MI
.getOperand(OpNum
).getReg())) &&
1048 "Invalid size combination");
1050 if ((Opcode
== SystemZ::AHI
|| Opcode
== SystemZ::AGHI
) && OpNum
== 0 &&
1051 isInt
<8>(MI
.getOperand(2).getImm())) {
1052 // A(G)HI %reg, CONST -> A(G)SI %mem, CONST
1053 Opcode
= (Opcode
== SystemZ::AHI
? SystemZ::ASI
: SystemZ::AGSI
);
1054 MachineInstr
*BuiltMI
=
1055 BuildMI(*InsertPt
->getParent(), InsertPt
, MI
.getDebugLoc(), get(Opcode
))
1056 .addFrameIndex(FrameIndex
)
1058 .addImm(MI
.getOperand(2).getImm());
1059 transferDeadCC(&MI
, BuiltMI
);
1060 transferMIFlag(&MI
, BuiltMI
, MachineInstr::NoSWrap
);
1064 if ((Opcode
== SystemZ::ALFI
&& OpNum
== 0 &&
1065 isInt
<8>((int32_t)MI
.getOperand(2).getImm())) ||
1066 (Opcode
== SystemZ::ALGFI
&& OpNum
== 0 &&
1067 isInt
<8>((int64_t)MI
.getOperand(2).getImm()))) {
1068 // AL(G)FI %reg, CONST -> AL(G)SI %mem, CONST
1069 Opcode
= (Opcode
== SystemZ::ALFI
? SystemZ::ALSI
: SystemZ::ALGSI
);
1070 MachineInstr
*BuiltMI
=
1071 BuildMI(*InsertPt
->getParent(), InsertPt
, MI
.getDebugLoc(), get(Opcode
))
1072 .addFrameIndex(FrameIndex
)
1074 .addImm((int8_t)MI
.getOperand(2).getImm());
1075 transferDeadCC(&MI
, BuiltMI
);
1079 if ((Opcode
== SystemZ::SLFI
&& OpNum
== 0 &&
1080 isInt
<8>((int32_t)-MI
.getOperand(2).getImm())) ||
1081 (Opcode
== SystemZ::SLGFI
&& OpNum
== 0 &&
1082 isInt
<8>((int64_t)-MI
.getOperand(2).getImm()))) {
1083 // SL(G)FI %reg, CONST -> AL(G)SI %mem, -CONST
1084 Opcode
= (Opcode
== SystemZ::SLFI
? SystemZ::ALSI
: SystemZ::ALGSI
);
1085 MachineInstr
*BuiltMI
=
1086 BuildMI(*InsertPt
->getParent(), InsertPt
, MI
.getDebugLoc(), get(Opcode
))
1087 .addFrameIndex(FrameIndex
)
1089 .addImm((int8_t)-MI
.getOperand(2).getImm());
1090 transferDeadCC(&MI
, BuiltMI
);
1094 if (Opcode
== SystemZ::LGDR
|| Opcode
== SystemZ::LDGR
) {
1095 bool Op0IsGPR
= (Opcode
== SystemZ::LGDR
);
1096 bool Op1IsGPR
= (Opcode
== SystemZ::LDGR
);
1097 // If we're spilling the destination of an LDGR or LGDR, store the
1098 // source register instead.
1100 unsigned StoreOpcode
= Op1IsGPR
? SystemZ::STG
: SystemZ::STD
;
1101 return BuildMI(*InsertPt
->getParent(), InsertPt
, MI
.getDebugLoc(),
1103 .add(MI
.getOperand(1))
1104 .addFrameIndex(FrameIndex
)
1108 // If we're spilling the source of an LDGR or LGDR, load the
1109 // destination register instead.
1111 unsigned LoadOpcode
= Op0IsGPR
? SystemZ::LG
: SystemZ::LD
;
1112 return BuildMI(*InsertPt
->getParent(), InsertPt
, MI
.getDebugLoc(),
1114 .add(MI
.getOperand(0))
1115 .addFrameIndex(FrameIndex
)
1121 // Look for cases where the source of a simple store or the destination
1122 // of a simple load is being spilled. Try to use MVC instead.
1124 // Although MVC is in practice a fast choice in these cases, it is still
1125 // logically a bytewise copy. This means that we cannot use it if the
1126 // load or store is volatile. We also wouldn't be able to use MVC if
1127 // the two memories partially overlap, but that case cannot occur here,
1128 // because we know that one of the memories is a full frame index.
1130 // For performance reasons, we also want to avoid using MVC if the addresses
1131 // might be equal. We don't worry about that case here, because spill slot
1132 // coloring happens later, and because we have special code to remove
1133 // MVCs that turn out to be redundant.
1134 if (OpNum
== 0 && MI
.hasOneMemOperand()) {
1135 MachineMemOperand
*MMO
= *MI
.memoperands_begin();
1136 if (MMO
->getSize() == Size
&& !MMO
->isVolatile() && !MMO
->isAtomic()) {
1137 // Handle conversion of loads.
1138 if (isSimpleBD12Move(&MI
, SystemZII::SimpleBDXLoad
)) {
1139 return BuildMI(*InsertPt
->getParent(), InsertPt
, MI
.getDebugLoc(),
1141 .addFrameIndex(FrameIndex
)
1144 .add(MI
.getOperand(1))
1145 .addImm(MI
.getOperand(2).getImm())
1146 .addMemOperand(MMO
);
1148 // Handle conversion of stores.
1149 if (isSimpleBD12Move(&MI
, SystemZII::SimpleBDXStore
)) {
1150 return BuildMI(*InsertPt
->getParent(), InsertPt
, MI
.getDebugLoc(),
1152 .add(MI
.getOperand(1))
1153 .addImm(MI
.getOperand(2).getImm())
1155 .addFrameIndex(FrameIndex
)
1157 .addMemOperand(MMO
);
1162 // If the spilled operand is the final one or the instruction is
1163 // commutable, try to change <INSN>R into <INSN>.
1164 unsigned NumOps
= MI
.getNumExplicitOperands();
1165 int MemOpcode
= SystemZ::getMemOpcode(Opcode
);
1167 // See if this is a 3-address instruction that is convertible to 2-address
1168 // and suitable for folding below. Only try this with virtual registers
1169 // and a provided VRM (during regalloc).
1170 bool NeedsCommute
= false;
1171 if (SystemZ::getTwoOperandOpcode(Opcode
) != -1 && MemOpcode
!= -1) {
1175 assert(NumOps
== 3 && "Expected two source registers.");
1176 Register DstReg
= MI
.getOperand(0).getReg();
1178 (Register::isVirtualRegister(DstReg
) ? VRM
->getPhys(DstReg
) : DstReg
);
1179 Register SrcReg
= (OpNum
== 2 ? MI
.getOperand(1).getReg()
1180 : ((OpNum
== 1 && MI
.isCommutable())
1181 ? MI
.getOperand(2).getReg()
1183 if (DstPhys
&& !SystemZ::GRH32BitRegClass
.contains(DstPhys
) && SrcReg
&&
1184 Register::isVirtualRegister(SrcReg
) &&
1185 DstPhys
== VRM
->getPhys(SrcReg
))
1186 NeedsCommute
= (OpNum
== 1);
1192 if (MemOpcode
>= 0) {
1193 if ((OpNum
== NumOps
- 1) || NeedsCommute
) {
1194 const MCInstrDesc
&MemDesc
= get(MemOpcode
);
1195 uint64_t AccessBytes
= SystemZII::getAccessSize(MemDesc
.TSFlags
);
1196 assert(AccessBytes
!= 0 && "Size of access should be known");
1197 assert(AccessBytes
<= Size
&& "Access outside the frame index");
1198 uint64_t Offset
= Size
- AccessBytes
;
1199 MachineInstrBuilder MIB
= BuildMI(*InsertPt
->getParent(), InsertPt
,
1200 MI
.getDebugLoc(), get(MemOpcode
));
1201 MIB
.add(MI
.getOperand(0));
1203 MIB
.add(MI
.getOperand(2));
1205 for (unsigned I
= 1; I
< OpNum
; ++I
)
1206 MIB
.add(MI
.getOperand(I
));
1207 MIB
.addFrameIndex(FrameIndex
).addImm(Offset
);
1208 if (MemDesc
.TSFlags
& SystemZII::HasIndex
)
1210 transferDeadCC(&MI
, MIB
);
1211 transferMIFlag(&MI
, MIB
, MachineInstr::NoSWrap
);
1219 MachineInstr
*SystemZInstrInfo::foldMemoryOperandImpl(
1220 MachineFunction
&MF
, MachineInstr
&MI
, ArrayRef
<unsigned> Ops
,
1221 MachineBasicBlock::iterator InsertPt
, MachineInstr
&LoadMI
,
1222 LiveIntervals
*LIS
) const {
1226 bool SystemZInstrInfo::expandPostRAPseudo(MachineInstr
&MI
) const {
1227 switch (MI
.getOpcode()) {
1229 splitMove(MI
, SystemZ::LG
);
1232 case SystemZ::ST128
:
1233 splitMove(MI
, SystemZ::STG
);
1237 splitMove(MI
, SystemZ::LD
);
1241 splitMove(MI
, SystemZ::STD
);
1244 case SystemZ::LBMux
:
1245 expandRXYPseudo(MI
, SystemZ::LB
, SystemZ::LBH
);
1248 case SystemZ::LHMux
:
1249 expandRXYPseudo(MI
, SystemZ::LH
, SystemZ::LHH
);
1252 case SystemZ::LLCRMux
:
1253 expandZExtPseudo(MI
, SystemZ::LLCR
, 8);
1256 case SystemZ::LLHRMux
:
1257 expandZExtPseudo(MI
, SystemZ::LLHR
, 16);
1260 case SystemZ::LLCMux
:
1261 expandRXYPseudo(MI
, SystemZ::LLC
, SystemZ::LLCH
);
1264 case SystemZ::LLHMux
:
1265 expandRXYPseudo(MI
, SystemZ::LLH
, SystemZ::LLHH
);
1269 expandRXYPseudo(MI
, SystemZ::L
, SystemZ::LFH
);
1272 case SystemZ::LOCMux
:
1273 expandLOCPseudo(MI
, SystemZ::LOC
, SystemZ::LOCFH
);
1276 case SystemZ::LOCHIMux
:
1277 expandLOCPseudo(MI
, SystemZ::LOCHI
, SystemZ::LOCHHI
);
1280 case SystemZ::STCMux
:
1281 expandRXYPseudo(MI
, SystemZ::STC
, SystemZ::STCH
);
1284 case SystemZ::STHMux
:
1285 expandRXYPseudo(MI
, SystemZ::STH
, SystemZ::STHH
);
1288 case SystemZ::STMux
:
1289 expandRXYPseudo(MI
, SystemZ::ST
, SystemZ::STFH
);
1292 case SystemZ::STOCMux
:
1293 expandLOCPseudo(MI
, SystemZ::STOC
, SystemZ::STOCFH
);
1296 case SystemZ::LHIMux
:
1297 expandRIPseudo(MI
, SystemZ::LHI
, SystemZ::IIHF
, true);
1300 case SystemZ::IIFMux
:
1301 expandRIPseudo(MI
, SystemZ::IILF
, SystemZ::IIHF
, false);
1304 case SystemZ::IILMux
:
1305 expandRIPseudo(MI
, SystemZ::IILL
, SystemZ::IIHL
, false);
1308 case SystemZ::IIHMux
:
1309 expandRIPseudo(MI
, SystemZ::IILH
, SystemZ::IIHH
, false);
1312 case SystemZ::NIFMux
:
1313 expandRIPseudo(MI
, SystemZ::NILF
, SystemZ::NIHF
, false);
1316 case SystemZ::NILMux
:
1317 expandRIPseudo(MI
, SystemZ::NILL
, SystemZ::NIHL
, false);
1320 case SystemZ::NIHMux
:
1321 expandRIPseudo(MI
, SystemZ::NILH
, SystemZ::NIHH
, false);
1324 case SystemZ::OIFMux
:
1325 expandRIPseudo(MI
, SystemZ::OILF
, SystemZ::OIHF
, false);
1328 case SystemZ::OILMux
:
1329 expandRIPseudo(MI
, SystemZ::OILL
, SystemZ::OIHL
, false);
1332 case SystemZ::OIHMux
:
1333 expandRIPseudo(MI
, SystemZ::OILH
, SystemZ::OIHH
, false);
1336 case SystemZ::XIFMux
:
1337 expandRIPseudo(MI
, SystemZ::XILF
, SystemZ::XIHF
, false);
1340 case SystemZ::TMLMux
:
1341 expandRIPseudo(MI
, SystemZ::TMLL
, SystemZ::TMHL
, false);
1344 case SystemZ::TMHMux
:
1345 expandRIPseudo(MI
, SystemZ::TMLH
, SystemZ::TMHH
, false);
1348 case SystemZ::AHIMux
:
1349 expandRIPseudo(MI
, SystemZ::AHI
, SystemZ::AIH
, false);
1352 case SystemZ::AHIMuxK
:
1353 expandRIEPseudo(MI
, SystemZ::AHI
, SystemZ::AHIK
, SystemZ::AIH
);
1356 case SystemZ::AFIMux
:
1357 expandRIPseudo(MI
, SystemZ::AFI
, SystemZ::AIH
, false);
1360 case SystemZ::CHIMux
:
1361 expandRIPseudo(MI
, SystemZ::CHI
, SystemZ::CIH
, false);
1364 case SystemZ::CFIMux
:
1365 expandRIPseudo(MI
, SystemZ::CFI
, SystemZ::CIH
, false);
1368 case SystemZ::CLFIMux
:
1369 expandRIPseudo(MI
, SystemZ::CLFI
, SystemZ::CLIH
, false);
1373 expandRXYPseudo(MI
, SystemZ::C
, SystemZ::CHF
);
1376 case SystemZ::CLMux
:
1377 expandRXYPseudo(MI
, SystemZ::CL
, SystemZ::CLHF
);
1380 case SystemZ::RISBMux
: {
1381 bool DestIsHigh
= SystemZ::isHighReg(MI
.getOperand(0).getReg());
1382 bool SrcIsHigh
= SystemZ::isHighReg(MI
.getOperand(2).getReg());
1383 if (SrcIsHigh
== DestIsHigh
)
1384 MI
.setDesc(get(DestIsHigh
? SystemZ::RISBHH
: SystemZ::RISBLL
));
1386 MI
.setDesc(get(DestIsHigh
? SystemZ::RISBHL
: SystemZ::RISBLH
));
1387 MI
.getOperand(5).setImm(MI
.getOperand(5).getImm() ^ 32);
1392 case SystemZ::ADJDYNALLOC
:
1393 splitAdjDynAlloc(MI
);
1396 case TargetOpcode::LOAD_STACK_GUARD
:
1397 expandLoadStackGuard(&MI
);
1405 unsigned SystemZInstrInfo::getInstSizeInBytes(const MachineInstr
&MI
) const {
1406 if (MI
.isInlineAsm()) {
1407 const MachineFunction
*MF
= MI
.getParent()->getParent();
1408 const char *AsmStr
= MI
.getOperand(0).getSymbolName();
1409 return getInlineAsmLength(AsmStr
, *MF
->getTarget().getMCAsmInfo());
1411 return MI
.getDesc().getSize();
1415 SystemZInstrInfo::getBranchInfo(const MachineInstr
&MI
) const {
1416 switch (MI
.getOpcode()) {
1421 return SystemZII::Branch(SystemZII::BranchNormal
, SystemZ::CCMASK_ANY
,
1422 SystemZ::CCMASK_ANY
, &MI
.getOperand(0));
1426 return SystemZII::Branch(SystemZII::BranchNormal
, MI
.getOperand(0).getImm(),
1427 MI
.getOperand(1).getImm(), &MI
.getOperand(2));
1430 case SystemZ::BRCTH
:
1431 return SystemZII::Branch(SystemZII::BranchCT
, SystemZ::CCMASK_ICMP
,
1432 SystemZ::CCMASK_CMP_NE
, &MI
.getOperand(2));
1434 case SystemZ::BRCTG
:
1435 return SystemZII::Branch(SystemZII::BranchCTG
, SystemZ::CCMASK_ICMP
,
1436 SystemZ::CCMASK_CMP_NE
, &MI
.getOperand(2));
1440 return SystemZII::Branch(SystemZII::BranchC
, SystemZ::CCMASK_ICMP
,
1441 MI
.getOperand(2).getImm(), &MI
.getOperand(3));
1445 return SystemZII::Branch(SystemZII::BranchCL
, SystemZ::CCMASK_ICMP
,
1446 MI
.getOperand(2).getImm(), &MI
.getOperand(3));
1450 return SystemZII::Branch(SystemZII::BranchCG
, SystemZ::CCMASK_ICMP
,
1451 MI
.getOperand(2).getImm(), &MI
.getOperand(3));
1453 case SystemZ::CLGIJ
:
1454 case SystemZ::CLGRJ
:
1455 return SystemZII::Branch(SystemZII::BranchCLG
, SystemZ::CCMASK_ICMP
,
1456 MI
.getOperand(2).getImm(), &MI
.getOperand(3));
1458 case SystemZ::INLINEASM_BR
:
1459 // Don't try to analyze asm goto, so pass nullptr as branch target argument.
1460 return SystemZII::Branch(SystemZII::AsmGoto
, 0, 0, nullptr);
1463 llvm_unreachable("Unrecognized branch opcode");
1467 void SystemZInstrInfo::getLoadStoreOpcodes(const TargetRegisterClass
*RC
,
1468 unsigned &LoadOpcode
,
1469 unsigned &StoreOpcode
) const {
1470 if (RC
== &SystemZ::GR32BitRegClass
|| RC
== &SystemZ::ADDR32BitRegClass
) {
1471 LoadOpcode
= SystemZ::L
;
1472 StoreOpcode
= SystemZ::ST
;
1473 } else if (RC
== &SystemZ::GRH32BitRegClass
) {
1474 LoadOpcode
= SystemZ::LFH
;
1475 StoreOpcode
= SystemZ::STFH
;
1476 } else if (RC
== &SystemZ::GRX32BitRegClass
) {
1477 LoadOpcode
= SystemZ::LMux
;
1478 StoreOpcode
= SystemZ::STMux
;
1479 } else if (RC
== &SystemZ::GR64BitRegClass
||
1480 RC
== &SystemZ::ADDR64BitRegClass
) {
1481 LoadOpcode
= SystemZ::LG
;
1482 StoreOpcode
= SystemZ::STG
;
1483 } else if (RC
== &SystemZ::GR128BitRegClass
||
1484 RC
== &SystemZ::ADDR128BitRegClass
) {
1485 LoadOpcode
= SystemZ::L128
;
1486 StoreOpcode
= SystemZ::ST128
;
1487 } else if (RC
== &SystemZ::FP32BitRegClass
) {
1488 LoadOpcode
= SystemZ::LE
;
1489 StoreOpcode
= SystemZ::STE
;
1490 } else if (RC
== &SystemZ::FP64BitRegClass
) {
1491 LoadOpcode
= SystemZ::LD
;
1492 StoreOpcode
= SystemZ::STD
;
1493 } else if (RC
== &SystemZ::FP128BitRegClass
) {
1494 LoadOpcode
= SystemZ::LX
;
1495 StoreOpcode
= SystemZ::STX
;
1496 } else if (RC
== &SystemZ::VR32BitRegClass
) {
1497 LoadOpcode
= SystemZ::VL32
;
1498 StoreOpcode
= SystemZ::VST32
;
1499 } else if (RC
== &SystemZ::VR64BitRegClass
) {
1500 LoadOpcode
= SystemZ::VL64
;
1501 StoreOpcode
= SystemZ::VST64
;
1502 } else if (RC
== &SystemZ::VF128BitRegClass
||
1503 RC
== &SystemZ::VR128BitRegClass
) {
1504 LoadOpcode
= SystemZ::VL
;
1505 StoreOpcode
= SystemZ::VST
;
1507 llvm_unreachable("Unsupported regclass to load or store");
1510 unsigned SystemZInstrInfo::getOpcodeForOffset(unsigned Opcode
,
1511 int64_t Offset
) const {
1512 const MCInstrDesc
&MCID
= get(Opcode
);
1513 int64_t Offset2
= (MCID
.TSFlags
& SystemZII::Is128Bit
? Offset
+ 8 : Offset
);
1514 if (isUInt
<12>(Offset
) && isUInt
<12>(Offset2
)) {
1515 // Get the instruction to use for unsigned 12-bit displacements.
1516 int Disp12Opcode
= SystemZ::getDisp12Opcode(Opcode
);
1517 if (Disp12Opcode
>= 0)
1518 return Disp12Opcode
;
1520 // All address-related instructions can use unsigned 12-bit
1524 if (isInt
<20>(Offset
) && isInt
<20>(Offset2
)) {
1525 // Get the instruction to use for signed 20-bit displacements.
1526 int Disp20Opcode
= SystemZ::getDisp20Opcode(Opcode
);
1527 if (Disp20Opcode
>= 0)
1528 return Disp20Opcode
;
1530 // Check whether Opcode allows signed 20-bit displacements.
1531 if (MCID
.TSFlags
& SystemZII::Has20BitOffset
)
1537 unsigned SystemZInstrInfo::getLoadAndTest(unsigned Opcode
) const {
1539 case SystemZ::L
: return SystemZ::LT
;
1540 case SystemZ::LY
: return SystemZ::LT
;
1541 case SystemZ::LG
: return SystemZ::LTG
;
1542 case SystemZ::LGF
: return SystemZ::LTGF
;
1543 case SystemZ::LR
: return SystemZ::LTR
;
1544 case SystemZ::LGFR
: return SystemZ::LTGFR
;
1545 case SystemZ::LGR
: return SystemZ::LTGR
;
1546 case SystemZ::LER
: return SystemZ::LTEBR
;
1547 case SystemZ::LDR
: return SystemZ::LTDBR
;
1548 case SystemZ::LXR
: return SystemZ::LTXBR
;
1549 case SystemZ::LCDFR
: return SystemZ::LCDBR
;
1550 case SystemZ::LPDFR
: return SystemZ::LPDBR
;
1551 case SystemZ::LNDFR
: return SystemZ::LNDBR
;
1552 case SystemZ::LCDFR_32
: return SystemZ::LCEBR
;
1553 case SystemZ::LPDFR_32
: return SystemZ::LPEBR
;
1554 case SystemZ::LNDFR_32
: return SystemZ::LNEBR
;
1555 // On zEC12 we prefer to use RISBGN. But if there is a chance to
1556 // actually use the condition code, we may turn it back into RISGB.
1557 // Note that RISBG is not really a "load-and-test" instruction,
1558 // but sets the same condition code values, so is OK to use here.
1559 case SystemZ::RISBGN
: return SystemZ::RISBG
;
1564 // Return true if Mask matches the regexp 0*1+0*, given that zero masks
1565 // have already been filtered out. Store the first set bit in LSB and
1566 // the number of set bits in Length if so.
1567 static bool isStringOfOnes(uint64_t Mask
, unsigned &LSB
, unsigned &Length
) {
1568 unsigned First
= findFirstSet(Mask
);
1569 uint64_t Top
= (Mask
>> First
) + 1;
1570 if ((Top
& -Top
) == Top
) {
1572 Length
= findFirstSet(Top
);
1578 bool SystemZInstrInfo::isRxSBGMask(uint64_t Mask
, unsigned BitSize
,
1579 unsigned &Start
, unsigned &End
) const {
1580 // Reject trivial all-zero masks.
1581 Mask
&= allOnes(BitSize
);
1585 // Handle the 1+0+ or 0+1+0* cases. Start then specifies the index of
1586 // the msb and End specifies the index of the lsb.
1587 unsigned LSB
, Length
;
1588 if (isStringOfOnes(Mask
, LSB
, Length
)) {
1589 Start
= 63 - (LSB
+ Length
- 1);
1594 // Handle the wrap-around 1+0+1+ cases. Start then specifies the msb
1595 // of the low 1s and End specifies the lsb of the high 1s.
1596 if (isStringOfOnes(Mask
^ allOnes(BitSize
), LSB
, Length
)) {
1597 assert(LSB
> 0 && "Bottom bit must be set");
1598 assert(LSB
+ Length
< BitSize
&& "Top bit must be set");
1599 Start
= 63 - (LSB
- 1);
1600 End
= 63 - (LSB
+ Length
);
1607 unsigned SystemZInstrInfo::getFusedCompare(unsigned Opcode
,
1608 SystemZII::FusedCompareType Type
,
1609 const MachineInstr
*MI
) const {
1613 if (!(MI
&& isInt
<8>(MI
->getOperand(1).getImm())))
1617 case SystemZ::CLGFI
:
1618 if (!(MI
&& isUInt
<8>(MI
->getOperand(1).getImm())))
1623 if (!STI
.hasMiscellaneousExtensions())
1625 if (!(MI
&& MI
->getOperand(3).getReg() == 0))
1630 case SystemZII::CompareAndBranch
:
1633 return SystemZ::CRJ
;
1635 return SystemZ::CGRJ
;
1637 return SystemZ::CIJ
;
1639 return SystemZ::CGIJ
;
1641 return SystemZ::CLRJ
;
1643 return SystemZ::CLGRJ
;
1645 return SystemZ::CLIJ
;
1646 case SystemZ::CLGFI
:
1647 return SystemZ::CLGIJ
;
1651 case SystemZII::CompareAndReturn
:
1654 return SystemZ::CRBReturn
;
1656 return SystemZ::CGRBReturn
;
1658 return SystemZ::CIBReturn
;
1660 return SystemZ::CGIBReturn
;
1662 return SystemZ::CLRBReturn
;
1664 return SystemZ::CLGRBReturn
;
1666 return SystemZ::CLIBReturn
;
1667 case SystemZ::CLGFI
:
1668 return SystemZ::CLGIBReturn
;
1672 case SystemZII::CompareAndSibcall
:
1675 return SystemZ::CRBCall
;
1677 return SystemZ::CGRBCall
;
1679 return SystemZ::CIBCall
;
1681 return SystemZ::CGIBCall
;
1683 return SystemZ::CLRBCall
;
1685 return SystemZ::CLGRBCall
;
1687 return SystemZ::CLIBCall
;
1688 case SystemZ::CLGFI
:
1689 return SystemZ::CLGIBCall
;
1693 case SystemZII::CompareAndTrap
:
1696 return SystemZ::CRT
;
1698 return SystemZ::CGRT
;
1700 return SystemZ::CIT
;
1702 return SystemZ::CGIT
;
1704 return SystemZ::CLRT
;
1706 return SystemZ::CLGRT
;
1708 return SystemZ::CLFIT
;
1709 case SystemZ::CLGFI
:
1710 return SystemZ::CLGIT
;
1712 return SystemZ::CLT
;
1714 return SystemZ::CLGT
;
1722 unsigned SystemZInstrInfo::getLoadAndTrap(unsigned Opcode
) const {
1723 if (!STI
.hasLoadAndTrap())
1728 return SystemZ::LAT
;
1730 return SystemZ::LGAT
;
1732 return SystemZ::LFHAT
;
1734 return SystemZ::LLGFAT
;
1736 return SystemZ::LLGTAT
;
1741 void SystemZInstrInfo::loadImmediate(MachineBasicBlock
&MBB
,
1742 MachineBasicBlock::iterator MBBI
,
1743 unsigned Reg
, uint64_t Value
) const {
1744 DebugLoc DL
= MBBI
!= MBB
.end() ? MBBI
->getDebugLoc() : DebugLoc();
1746 if (isInt
<16>(Value
))
1747 Opcode
= SystemZ::LGHI
;
1748 else if (SystemZ::isImmLL(Value
))
1749 Opcode
= SystemZ::LLILL
;
1750 else if (SystemZ::isImmLH(Value
)) {
1751 Opcode
= SystemZ::LLILH
;
1754 assert(isInt
<32>(Value
) && "Huge values not handled yet");
1755 Opcode
= SystemZ::LGFI
;
1757 BuildMI(MBB
, MBBI
, DL
, get(Opcode
), Reg
).addImm(Value
);
1760 bool SystemZInstrInfo::verifyInstruction(const MachineInstr
&MI
,
1761 StringRef
&ErrInfo
) const {
1762 const MCInstrDesc
&MCID
= MI
.getDesc();
1763 for (unsigned I
= 0, E
= MI
.getNumOperands(); I
!= E
; ++I
) {
1764 if (I
>= MCID
.getNumOperands())
1766 const MachineOperand
&Op
= MI
.getOperand(I
);
1767 const MCOperandInfo
&MCOI
= MCID
.OpInfo
[I
];
1768 // Addressing modes have register and immediate operands. Op should be a
1769 // register (or frame index) operand if MCOI.RegClass contains a valid
1770 // register class, or an immediate otherwise.
1771 if (MCOI
.OperandType
== MCOI::OPERAND_MEMORY
&&
1772 ((MCOI
.RegClass
!= -1 && !Op
.isReg() && !Op
.isFI()) ||
1773 (MCOI
.RegClass
== -1 && !Op
.isImm()))) {
1774 ErrInfo
= "Addressing mode operands corrupt!";
1782 bool SystemZInstrInfo::
1783 areMemAccessesTriviallyDisjoint(const MachineInstr
&MIa
,
1784 const MachineInstr
&MIb
) const {
1786 if (!MIa
.hasOneMemOperand() || !MIb
.hasOneMemOperand())
1789 // If mem-operands show that the same address Value is used by both
1790 // instructions, check for non-overlapping offsets and widths. Not
1791 // sure if a register based analysis would be an improvement...
1793 MachineMemOperand
*MMOa
= *MIa
.memoperands_begin();
1794 MachineMemOperand
*MMOb
= *MIb
.memoperands_begin();
1795 const Value
*VALa
= MMOa
->getValue();
1796 const Value
*VALb
= MMOb
->getValue();
1797 bool SameVal
= (VALa
&& VALb
&& (VALa
== VALb
));
1799 const PseudoSourceValue
*PSVa
= MMOa
->getPseudoValue();
1800 const PseudoSourceValue
*PSVb
= MMOb
->getPseudoValue();
1801 if (PSVa
&& PSVb
&& (PSVa
== PSVb
))
1805 int OffsetA
= MMOa
->getOffset(), OffsetB
= MMOb
->getOffset();
1806 int WidthA
= MMOa
->getSize(), WidthB
= MMOb
->getSize();
1807 int LowOffset
= OffsetA
< OffsetB
? OffsetA
: OffsetB
;
1808 int HighOffset
= OffsetA
< OffsetB
? OffsetB
: OffsetA
;
1809 int LowWidth
= (LowOffset
== OffsetA
) ? WidthA
: WidthB
;
1810 if (LowOffset
+ LowWidth
<= HighOffset
)