Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1 | //===-- 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 Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 16 | #include "SystemZTargetMachine.h" |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/LiveVariables.h" |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 20 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 23 | #define GET_INSTRINFO_CTOR_DTOR |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 24 | #define GET_INSTRMAP_INFO |
| 25 | #include "SystemZGenInstrInfo.inc" |
| 26 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 27 | // Return a mask with Count low bits set. |
| 28 | static uint64_t allOnes(unsigned int Count) { |
| 29 | return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1; |
| 30 | } |
| 31 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 32 | // Reg should be a 32-bit GPR. Return true if it is a high register rather |
| 33 | // than a low register. |
| 34 | static bool isHighReg(unsigned int Reg) { |
| 35 | if (SystemZ::GRH32BitRegClass.contains(Reg)) |
| 36 | return true; |
| 37 | assert(SystemZ::GR32BitRegClass.contains(Reg) && "Invalid GRX32"); |
| 38 | return false; |
| 39 | } |
| 40 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 41 | // Pin the vtable to this file. |
| 42 | void SystemZInstrInfo::anchor() {} |
| 43 | |
Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 44 | SystemZInstrInfo::SystemZInstrInfo(SystemZSubtarget &sti) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 45 | : SystemZGenInstrInfo(SystemZ::ADJCALLSTACKDOWN, SystemZ::ADJCALLSTACKUP), |
Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 46 | RI(), STI(sti) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // MI is a 128-bit load or store. Split it into two 64-bit loads or stores, |
| 50 | // each having the opcode given by NewOpcode. |
| 51 | void SystemZInstrInfo::splitMove(MachineBasicBlock::iterator MI, |
| 52 | unsigned NewOpcode) const { |
| 53 | MachineBasicBlock *MBB = MI->getParent(); |
| 54 | MachineFunction &MF = *MBB->getParent(); |
| 55 | |
| 56 | // Get two load or store instructions. Use the original instruction for one |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 57 | // of them (arbitrarily the second here) and create a clone for the other. |
Duncan P. N. Exon Smith | 4565ec0 | 2016-07-12 01:39:01 +0000 | [diff] [blame] | 58 | MachineInstr *EarlierMI = MF.CloneMachineInstr(&*MI); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 59 | MBB->insert(MI, EarlierMI); |
| 60 | |
| 61 | // Set up the two 64-bit registers. |
| 62 | MachineOperand &HighRegOp = EarlierMI->getOperand(0); |
| 63 | MachineOperand &LowRegOp = MI->getOperand(0); |
Richard Sandiford | 87a4436 | 2013-09-30 10:28:35 +0000 | [diff] [blame] | 64 | HighRegOp.setReg(RI.getSubReg(HighRegOp.getReg(), SystemZ::subreg_h64)); |
| 65 | LowRegOp.setReg(RI.getSubReg(LowRegOp.getReg(), SystemZ::subreg_l64)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 66 | |
| 67 | // The address in the first (high) instruction is already correct. |
| 68 | // Adjust the offset in the second (low) instruction. |
| 69 | MachineOperand &HighOffsetOp = EarlierMI->getOperand(2); |
| 70 | MachineOperand &LowOffsetOp = MI->getOperand(2); |
| 71 | LowOffsetOp.setImm(LowOffsetOp.getImm() + 8); |
| 72 | |
Jonas Paulsson | 2ba3152 | 2016-03-31 08:00:14 +0000 | [diff] [blame] | 73 | // Clear the kill flags for the base and index registers in the first |
| 74 | // instruction. |
Jonas Paulsson | 63a2b68 | 2015-10-10 07:14:24 +0000 | [diff] [blame] | 75 | EarlierMI->getOperand(1).setIsKill(false); |
Jonas Paulsson | 7da3820 | 2015-10-26 15:03:41 +0000 | [diff] [blame] | 76 | EarlierMI->getOperand(3).setIsKill(false); |
Jonas Paulsson | 63a2b68 | 2015-10-10 07:14:24 +0000 | [diff] [blame] | 77 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 78 | // Set the opcodes. |
| 79 | unsigned HighOpcode = getOpcodeForOffset(NewOpcode, HighOffsetOp.getImm()); |
| 80 | unsigned LowOpcode = getOpcodeForOffset(NewOpcode, LowOffsetOp.getImm()); |
| 81 | assert(HighOpcode && LowOpcode && "Both offsets should be in range"); |
| 82 | |
| 83 | EarlierMI->setDesc(get(HighOpcode)); |
| 84 | MI->setDesc(get(LowOpcode)); |
| 85 | } |
| 86 | |
| 87 | // Split ADJDYNALLOC instruction MI. |
| 88 | void SystemZInstrInfo::splitAdjDynAlloc(MachineBasicBlock::iterator MI) const { |
| 89 | MachineBasicBlock *MBB = MI->getParent(); |
| 90 | MachineFunction &MF = *MBB->getParent(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame^] | 91 | MachineFrameInfo &MFFrame = MF.getFrameInfo(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 92 | MachineOperand &OffsetMO = MI->getOperand(2); |
| 93 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame^] | 94 | uint64_t Offset = (MFFrame.getMaxCallFrameSize() + |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 95 | SystemZMC::CallFrameSize + |
| 96 | OffsetMO.getImm()); |
| 97 | unsigned NewOpcode = getOpcodeForOffset(SystemZ::LA, Offset); |
| 98 | assert(NewOpcode && "No support for huge argument lists yet"); |
| 99 | MI->setDesc(get(NewOpcode)); |
| 100 | OffsetMO.setImm(Offset); |
| 101 | } |
| 102 | |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 103 | // MI is an RI-style pseudo instruction. Replace it with LowOpcode |
| 104 | // if the first operand is a low GR32 and HighOpcode if the first operand |
| 105 | // is a high GR32. ConvertHigh is true if LowOpcode takes a signed operand |
| 106 | // and HighOpcode takes an unsigned 32-bit operand. In those cases, |
| 107 | // MI has the same kind of operand as LowOpcode, so needs to be converted |
| 108 | // if HighOpcode is used. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 109 | void SystemZInstrInfo::expandRIPseudo(MachineInstr &MI, unsigned LowOpcode, |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 110 | unsigned HighOpcode, |
| 111 | bool ConvertHigh) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 112 | unsigned Reg = MI.getOperand(0).getReg(); |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 113 | bool IsHigh = isHighReg(Reg); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 114 | MI.setDesc(get(IsHigh ? HighOpcode : LowOpcode)); |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 115 | if (IsHigh && ConvertHigh) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 116 | MI.getOperand(1).setImm(uint32_t(MI.getOperand(1).getImm())); |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 119 | // MI is a three-operand RIE-style pseudo instruction. Replace it with |
Jonas Paulsson | 18d877f | 2015-10-09 07:19:16 +0000 | [diff] [blame] | 120 | // LowOpcodeK if the registers are both low GR32s, otherwise use a move |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 121 | // followed by HighOpcode or LowOpcode, depending on whether the target |
| 122 | // is a high or low GR32. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 123 | void SystemZInstrInfo::expandRIEPseudo(MachineInstr &MI, unsigned LowOpcode, |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 124 | unsigned LowOpcodeK, |
| 125 | unsigned HighOpcode) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 126 | unsigned DestReg = MI.getOperand(0).getReg(); |
| 127 | unsigned SrcReg = MI.getOperand(1).getReg(); |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 128 | bool DestIsHigh = isHighReg(DestReg); |
| 129 | bool SrcIsHigh = isHighReg(SrcReg); |
| 130 | if (!DestIsHigh && !SrcIsHigh) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 131 | MI.setDesc(get(LowOpcodeK)); |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 132 | else { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 133 | emitGRX32Move(*MI.getParent(), MI, MI.getDebugLoc(), DestReg, SrcReg, |
| 134 | SystemZ::LR, 32, MI.getOperand(1).isKill()); |
| 135 | MI.setDesc(get(DestIsHigh ? HighOpcode : LowOpcode)); |
| 136 | MI.getOperand(1).setReg(DestReg); |
| 137 | MI.tieOperands(0, 1); |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 141 | // MI is an RXY-style pseudo instruction. Replace it with LowOpcode |
| 142 | // if the first operand is a low GR32 and HighOpcode if the first operand |
| 143 | // is a high GR32. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 144 | void SystemZInstrInfo::expandRXYPseudo(MachineInstr &MI, unsigned LowOpcode, |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 145 | unsigned HighOpcode) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 146 | unsigned Reg = MI.getOperand(0).getReg(); |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 147 | unsigned Opcode = getOpcodeForOffset(isHighReg(Reg) ? HighOpcode : LowOpcode, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 148 | MI.getOperand(2).getImm()); |
| 149 | MI.setDesc(get(Opcode)); |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 152 | // MI is an RR-style pseudo instruction that zero-extends the low Size bits |
| 153 | // of one GRX32 into another. Replace it with LowOpcode if both operands |
| 154 | // are low registers, otherwise use RISB[LH]G. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 155 | void SystemZInstrInfo::expandZExtPseudo(MachineInstr &MI, unsigned LowOpcode, |
Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 156 | unsigned Size) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 157 | emitGRX32Move(*MI.getParent(), MI, MI.getDebugLoc(), |
| 158 | MI.getOperand(0).getReg(), MI.getOperand(1).getReg(), LowOpcode, |
| 159 | Size, MI.getOperand(1).isKill()); |
| 160 | MI.eraseFromParent(); |
Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 163 | void SystemZInstrInfo::expandLoadStackGuard(MachineInstr *MI) const { |
| 164 | MachineBasicBlock *MBB = MI->getParent(); |
| 165 | MachineFunction &MF = *MBB->getParent(); |
| 166 | const unsigned Reg = MI->getOperand(0).getReg(); |
| 167 | |
| 168 | // Conveniently, all 4 instructions are cloned from LOAD_STACK_GUARD, |
| 169 | // so they already have operand 0 set to reg. |
| 170 | |
| 171 | // ear <reg>, %a0 |
| 172 | MachineInstr *Ear1MI = MF.CloneMachineInstr(MI); |
| 173 | MBB->insert(MI, Ear1MI); |
| 174 | Ear1MI->setDesc(get(SystemZ::EAR)); |
| 175 | MachineInstrBuilder(MF, Ear1MI).addImm(0); |
| 176 | |
| 177 | // sllg <reg>, <reg>, 32 |
| 178 | MachineInstr *SllgMI = MF.CloneMachineInstr(MI); |
| 179 | MBB->insert(MI, SllgMI); |
| 180 | SllgMI->setDesc(get(SystemZ::SLLG)); |
| 181 | MachineInstrBuilder(MF, SllgMI).addReg(Reg).addReg(0).addImm(32); |
| 182 | |
| 183 | // ear <reg>, %a1 |
| 184 | MachineInstr *Ear2MI = MF.CloneMachineInstr(MI); |
| 185 | MBB->insert(MI, Ear2MI); |
| 186 | Ear2MI->setDesc(get(SystemZ::EAR)); |
| 187 | MachineInstrBuilder(MF, Ear2MI).addImm(1); |
| 188 | |
| 189 | // lg <reg>, 40(<reg>) |
| 190 | MI->setDesc(get(SystemZ::LG)); |
| 191 | MachineInstrBuilder(MF, MI).addReg(Reg).addImm(40).addReg(0); |
| 192 | } |
| 193 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 194 | // Emit a zero-extending move from 32-bit GPR SrcReg to 32-bit GPR |
| 195 | // DestReg before MBBI in MBB. Use LowLowOpcode when both DestReg and SrcReg |
| 196 | // are low registers, otherwise use RISB[LH]G. Size is the number of bits |
| 197 | // taken from the low end of SrcReg (8 for LLCR, 16 for LLHR and 32 for LR). |
| 198 | // KillSrc is true if this move is the last use of SrcReg. |
| 199 | void SystemZInstrInfo::emitGRX32Move(MachineBasicBlock &MBB, |
| 200 | MachineBasicBlock::iterator MBBI, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 201 | const DebugLoc &DL, unsigned DestReg, |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 202 | unsigned SrcReg, unsigned LowLowOpcode, |
| 203 | unsigned Size, bool KillSrc) const { |
| 204 | unsigned Opcode; |
| 205 | bool DestIsHigh = isHighReg(DestReg); |
| 206 | bool SrcIsHigh = isHighReg(SrcReg); |
| 207 | if (DestIsHigh && SrcIsHigh) |
| 208 | Opcode = SystemZ::RISBHH; |
| 209 | else if (DestIsHigh && !SrcIsHigh) |
| 210 | Opcode = SystemZ::RISBHL; |
| 211 | else if (!DestIsHigh && SrcIsHigh) |
| 212 | Opcode = SystemZ::RISBLH; |
| 213 | else { |
| 214 | BuildMI(MBB, MBBI, DL, get(LowLowOpcode), DestReg) |
| 215 | .addReg(SrcReg, getKillRegState(KillSrc)); |
| 216 | return; |
| 217 | } |
| 218 | unsigned Rotate = (DestIsHigh != SrcIsHigh ? 32 : 0); |
| 219 | BuildMI(MBB, MBBI, DL, get(Opcode), DestReg) |
| 220 | .addReg(DestReg, RegState::Undef) |
| 221 | .addReg(SrcReg, getKillRegState(KillSrc)) |
| 222 | .addImm(32 - Size).addImm(128 + 31).addImm(Rotate); |
| 223 | } |
| 224 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 225 | // If MI is a simple load or store for a frame object, return the register |
| 226 | // it loads or stores and set FrameIndex to the index of the frame object. |
| 227 | // Return 0 otherwise. |
| 228 | // |
| 229 | // Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 230 | static int isSimpleMove(const MachineInstr &MI, int &FrameIndex, |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 231 | unsigned Flag) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 232 | const MCInstrDesc &MCID = MI.getDesc(); |
| 233 | if ((MCID.TSFlags & Flag) && MI.getOperand(1).isFI() && |
| 234 | MI.getOperand(2).getImm() == 0 && MI.getOperand(3).getReg() == 0) { |
| 235 | FrameIndex = MI.getOperand(1).getIndex(); |
| 236 | return MI.getOperand(0).getReg(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 237 | } |
| 238 | return 0; |
| 239 | } |
| 240 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 241 | unsigned SystemZInstrInfo::isLoadFromStackSlot(const MachineInstr &MI, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 242 | int &FrameIndex) const { |
| 243 | return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXLoad); |
| 244 | } |
| 245 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 246 | unsigned SystemZInstrInfo::isStoreToStackSlot(const MachineInstr &MI, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 247 | int &FrameIndex) const { |
| 248 | return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXStore); |
| 249 | } |
| 250 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 251 | bool SystemZInstrInfo::isStackSlotCopy(const MachineInstr &MI, |
Richard Sandiford | c40f27b | 2013-07-05 14:38:48 +0000 | [diff] [blame] | 252 | int &DestFrameIndex, |
| 253 | int &SrcFrameIndex) const { |
| 254 | // Check for MVC 0(Length,FI1),0(FI2) |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame^] | 255 | const MachineFrameInfo &MFI = MI.getParent()->getParent()->getFrameInfo(); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 256 | if (MI.getOpcode() != SystemZ::MVC || !MI.getOperand(0).isFI() || |
| 257 | MI.getOperand(1).getImm() != 0 || !MI.getOperand(3).isFI() || |
| 258 | MI.getOperand(4).getImm() != 0) |
Richard Sandiford | c40f27b | 2013-07-05 14:38:48 +0000 | [diff] [blame] | 259 | return false; |
| 260 | |
| 261 | // Check that Length covers the full slots. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 262 | int64_t Length = MI.getOperand(2).getImm(); |
| 263 | unsigned FI1 = MI.getOperand(0).getIndex(); |
| 264 | unsigned FI2 = MI.getOperand(3).getIndex(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame^] | 265 | if (MFI.getObjectSize(FI1) != Length || |
| 266 | MFI.getObjectSize(FI2) != Length) |
Richard Sandiford | c40f27b | 2013-07-05 14:38:48 +0000 | [diff] [blame] | 267 | return false; |
| 268 | |
| 269 | DestFrameIndex = FI1; |
| 270 | SrcFrameIndex = FI2; |
| 271 | return true; |
| 272 | } |
| 273 | |
Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 274 | bool SystemZInstrInfo::analyzeBranch(MachineBasicBlock &MBB, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 275 | MachineBasicBlock *&TBB, |
| 276 | MachineBasicBlock *&FBB, |
| 277 | SmallVectorImpl<MachineOperand> &Cond, |
| 278 | bool AllowModify) const { |
| 279 | // Most of the code and comments here are boilerplate. |
| 280 | |
| 281 | // Start from the bottom of the block and work up, examining the |
| 282 | // terminator instructions. |
| 283 | MachineBasicBlock::iterator I = MBB.end(); |
| 284 | while (I != MBB.begin()) { |
| 285 | --I; |
| 286 | if (I->isDebugValue()) |
| 287 | continue; |
| 288 | |
| 289 | // Working from the bottom, when we see a non-terminator instruction, we're |
| 290 | // done. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 291 | if (!isUnpredicatedTerminator(*I)) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 292 | break; |
| 293 | |
| 294 | // A terminator that isn't a branch can't easily be handled by this |
| 295 | // analysis. |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 296 | if (!I->isBranch()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 297 | return true; |
| 298 | |
| 299 | // Can't handle indirect branches. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 300 | SystemZII::Branch Branch(getBranchInfo(*I)); |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 301 | if (!Branch.Target->isMBB()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 302 | return true; |
| 303 | |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 304 | // Punt on compound branches. |
| 305 | if (Branch.Type != SystemZII::BranchNormal) |
| 306 | return true; |
| 307 | |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 308 | if (Branch.CCMask == SystemZ::CCMASK_ANY) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 309 | // Handle unconditional branches. |
| 310 | if (!AllowModify) { |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 311 | TBB = Branch.Target->getMBB(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 312 | continue; |
| 313 | } |
| 314 | |
| 315 | // If the block has any instructions after a JMP, delete them. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 316 | while (std::next(I) != MBB.end()) |
| 317 | std::next(I)->eraseFromParent(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 318 | |
| 319 | Cond.clear(); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 320 | FBB = nullptr; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 321 | |
| 322 | // Delete the JMP if it's equivalent to a fall-through. |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 323 | if (MBB.isLayoutSuccessor(Branch.Target->getMBB())) { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 324 | TBB = nullptr; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 325 | I->eraseFromParent(); |
| 326 | I = MBB.end(); |
| 327 | continue; |
| 328 | } |
| 329 | |
| 330 | // TBB is used to indicate the unconditinal destination. |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 331 | TBB = Branch.Target->getMBB(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 332 | continue; |
| 333 | } |
| 334 | |
| 335 | // Working from the bottom, handle the first conditional branch. |
| 336 | if (Cond.empty()) { |
| 337 | // FIXME: add X86-style branch swap |
| 338 | FBB = TBB; |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 339 | TBB = Branch.Target->getMBB(); |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 340 | Cond.push_back(MachineOperand::CreateImm(Branch.CCValid)); |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 341 | Cond.push_back(MachineOperand::CreateImm(Branch.CCMask)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 342 | continue; |
| 343 | } |
| 344 | |
| 345 | // Handle subsequent conditional branches. |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 346 | assert(Cond.size() == 2 && TBB && "Should have seen a conditional branch"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 347 | |
| 348 | // Only handle the case where all conditional branches branch to the same |
| 349 | // destination. |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 350 | if (TBB != Branch.Target->getMBB()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 351 | return true; |
| 352 | |
| 353 | // If the conditions are the same, we can leave them alone. |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 354 | unsigned OldCCValid = Cond[0].getImm(); |
| 355 | unsigned OldCCMask = Cond[1].getImm(); |
| 356 | if (OldCCValid == Branch.CCValid && OldCCMask == Branch.CCMask) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 357 | continue; |
| 358 | |
| 359 | // FIXME: Try combining conditions like X86 does. Should be easy on Z! |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 360 | return false; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | unsigned SystemZInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
| 367 | // Most of the code and comments here are boilerplate. |
| 368 | MachineBasicBlock::iterator I = MBB.end(); |
| 369 | unsigned Count = 0; |
| 370 | |
| 371 | while (I != MBB.begin()) { |
| 372 | --I; |
| 373 | if (I->isDebugValue()) |
| 374 | continue; |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 375 | if (!I->isBranch()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 376 | break; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 377 | if (!getBranchInfo(*I).Target->isMBB()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 378 | break; |
| 379 | // Remove the branch. |
| 380 | I->eraseFromParent(); |
| 381 | I = MBB.end(); |
| 382 | ++Count; |
| 383 | } |
| 384 | |
| 385 | return Count; |
| 386 | } |
| 387 | |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 388 | bool SystemZInstrInfo:: |
| 389 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
| 390 | assert(Cond.size() == 2 && "Invalid condition"); |
| 391 | Cond[1].setImm(Cond[1].getImm() ^ Cond[0].getImm()); |
| 392 | return false; |
| 393 | } |
| 394 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 395 | unsigned SystemZInstrInfo::InsertBranch(MachineBasicBlock &MBB, |
| 396 | MachineBasicBlock *TBB, |
| 397 | MachineBasicBlock *FBB, |
| 398 | ArrayRef<MachineOperand> Cond, |
| 399 | const DebugLoc &DL) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 400 | // In this function we output 32-bit branches, which should always |
| 401 | // have enough range. They can be shortened and relaxed by later code |
| 402 | // in the pipeline, if desired. |
| 403 | |
| 404 | // Shouldn't be a fall through. |
| 405 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 406 | assert((Cond.size() == 2 || Cond.size() == 0) && |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 407 | "SystemZ branch conditions have one component!"); |
| 408 | |
| 409 | if (Cond.empty()) { |
| 410 | // Unconditional branch? |
| 411 | assert(!FBB && "Unconditional branch with multiple successors!"); |
Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 412 | BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(TBB); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 413 | return 1; |
| 414 | } |
| 415 | |
| 416 | // Conditional branch. |
| 417 | unsigned Count = 0; |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 418 | unsigned CCValid = Cond[0].getImm(); |
| 419 | unsigned CCMask = Cond[1].getImm(); |
| 420 | BuildMI(&MBB, DL, get(SystemZ::BRC)) |
| 421 | .addImm(CCValid).addImm(CCMask).addMBB(TBB); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 422 | ++Count; |
| 423 | |
| 424 | if (FBB) { |
| 425 | // Two-way Conditional branch. Insert the second branch. |
Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 426 | BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(FBB); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 427 | ++Count; |
| 428 | } |
| 429 | return Count; |
| 430 | } |
| 431 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 432 | bool SystemZInstrInfo::analyzeCompare(const MachineInstr &MI, unsigned &SrcReg, |
| 433 | unsigned &SrcReg2, int &Mask, |
| 434 | int &Value) const { |
| 435 | assert(MI.isCompare() && "Caller should have checked for a comparison"); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 436 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 437 | if (MI.getNumExplicitOperands() == 2 && MI.getOperand(0).isReg() && |
| 438 | MI.getOperand(1).isImm()) { |
| 439 | SrcReg = MI.getOperand(0).getReg(); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 440 | SrcReg2 = 0; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 441 | Value = MI.getOperand(1).getImm(); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 442 | Mask = ~0; |
| 443 | return true; |
| 444 | } |
| 445 | |
| 446 | return false; |
| 447 | } |
| 448 | |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 449 | // If Reg is a virtual register, return its definition, otherwise return null. |
| 450 | static MachineInstr *getDef(unsigned Reg, |
| 451 | const MachineRegisterInfo *MRI) { |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 452 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 453 | return nullptr; |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 454 | return MRI->getUniqueVRegDef(Reg); |
| 455 | } |
| 456 | |
| 457 | // Return true if MI is a shift of type Opcode by Imm bits. |
Matthias Braun | fa3872e | 2015-05-18 20:27:55 +0000 | [diff] [blame] | 458 | static bool isShift(MachineInstr *MI, unsigned Opcode, int64_t Imm) { |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 459 | return (MI->getOpcode() == Opcode && |
| 460 | !MI->getOperand(2).getReg() && |
| 461 | MI->getOperand(3).getImm() == Imm); |
| 462 | } |
| 463 | |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 464 | // If the destination of MI has no uses, delete it as dead. |
| 465 | static void eraseIfDead(MachineInstr *MI, const MachineRegisterInfo *MRI) { |
| 466 | if (MRI->use_nodbg_empty(MI->getOperand(0).getReg())) |
| 467 | MI->eraseFromParent(); |
| 468 | } |
| 469 | |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 470 | // Compare compares SrcReg against zero. Check whether SrcReg contains |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 471 | // the result of an IPM sequence whose input CC survives until Compare, |
| 472 | // and whether Compare is therefore redundant. Delete it and return |
| 473 | // true if so. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 474 | static bool removeIPMBasedCompare(MachineInstr &Compare, unsigned SrcReg, |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 475 | const MachineRegisterInfo *MRI, |
| 476 | const TargetRegisterInfo *TRI) { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 477 | MachineInstr *LGFR = nullptr; |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 478 | MachineInstr *RLL = getDef(SrcReg, MRI); |
Richard Sandiford | e382775 | 2013-08-16 10:55:47 +0000 | [diff] [blame] | 479 | if (RLL && RLL->getOpcode() == SystemZ::LGFR) { |
| 480 | LGFR = RLL; |
| 481 | RLL = getDef(LGFR->getOperand(1).getReg(), MRI); |
| 482 | } |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 483 | if (!RLL || !isShift(RLL, SystemZ::RLL, 31)) |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 484 | return false; |
| 485 | |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 486 | MachineInstr *SRL = getDef(RLL->getOperand(1).getReg(), MRI); |
Richard Sandiford | f722a8e30 | 2013-10-16 11:10:55 +0000 | [diff] [blame] | 487 | if (!SRL || !isShift(SRL, SystemZ::SRL, SystemZ::IPM_CC)) |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 488 | return false; |
| 489 | |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 490 | MachineInstr *IPM = getDef(SRL->getOperand(1).getReg(), MRI); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 491 | if (!IPM || IPM->getOpcode() != SystemZ::IPM) |
| 492 | return false; |
| 493 | |
| 494 | // Check that there are no assignments to CC between the IPM and Compare, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 495 | if (IPM->getParent() != Compare.getParent()) |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 496 | return false; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 497 | MachineBasicBlock::iterator MBBI = IPM, MBBE = Compare.getIterator(); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 498 | for (++MBBI; MBBI != MBBE; ++MBBI) { |
Duncan P. N. Exon Smith | 4565ec0 | 2016-07-12 01:39:01 +0000 | [diff] [blame] | 499 | MachineInstr &MI = *MBBI; |
| 500 | if (MI.modifiesRegister(SystemZ::CC, TRI)) |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 501 | return false; |
| 502 | } |
| 503 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 504 | Compare.eraseFromParent(); |
Richard Sandiford | e382775 | 2013-08-16 10:55:47 +0000 | [diff] [blame] | 505 | if (LGFR) |
| 506 | eraseIfDead(LGFR, MRI); |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 507 | eraseIfDead(RLL, MRI); |
| 508 | eraseIfDead(SRL, MRI); |
| 509 | eraseIfDead(IPM, MRI); |
| 510 | |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 511 | return true; |
| 512 | } |
| 513 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 514 | bool SystemZInstrInfo::optimizeCompareInstr( |
| 515 | MachineInstr &Compare, unsigned SrcReg, unsigned SrcReg2, int Mask, |
| 516 | int Value, const MachineRegisterInfo *MRI) const { |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 517 | assert(!SrcReg2 && "Only optimizing constant comparisons so far"); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 518 | bool IsLogical = (Compare.getDesc().TSFlags & SystemZII::IsLogical) != 0; |
Ulrich Weigand | 19d24d2 | 2015-11-13 13:00:27 +0000 | [diff] [blame] | 519 | return Value == 0 && !IsLogical && |
| 520 | removeIPMBasedCompare(Compare, SrcReg, MRI, &RI); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 523 | // If Opcode is a move that has a conditional variant, return that variant, |
| 524 | // otherwise return 0. |
| 525 | static unsigned getConditionalMove(unsigned Opcode) { |
| 526 | switch (Opcode) { |
| 527 | case SystemZ::LR: return SystemZ::LOCR; |
| 528 | case SystemZ::LGR: return SystemZ::LOCGR; |
| 529 | default: return 0; |
| 530 | } |
| 531 | } |
| 532 | |
Zhan Jun Liau | def708a | 2016-07-11 18:45:03 +0000 | [diff] [blame] | 533 | static unsigned getConditionalLoadImmediate(unsigned Opcode) { |
| 534 | switch (Opcode) { |
| 535 | case SystemZ::LHI: return SystemZ::LOCHI; |
| 536 | case SystemZ::LGHI: return SystemZ::LOCGHI; |
| 537 | default: return 0; |
| 538 | } |
| 539 | } |
| 540 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 541 | bool SystemZInstrInfo::isPredicable(MachineInstr &MI) const { |
| 542 | unsigned Opcode = MI.getOpcode(); |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 543 | if (STI.hasLoadStoreOnCond() && getConditionalMove(Opcode)) |
| 544 | return true; |
Zhan Jun Liau | def708a | 2016-07-11 18:45:03 +0000 | [diff] [blame] | 545 | if (STI.hasLoadStoreOnCond2() && getConditionalLoadImmediate(Opcode)) |
| 546 | return true; |
Ulrich Weigand | fa2dffb | 2016-04-08 17:22:19 +0000 | [diff] [blame] | 547 | if (Opcode == SystemZ::Return || |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 548 | Opcode == SystemZ::Trap || |
Ulrich Weigand | 848a513 | 2016-04-11 12:12:32 +0000 | [diff] [blame] | 549 | Opcode == SystemZ::CallJG || |
| 550 | Opcode == SystemZ::CallBR) |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 551 | return true; |
| 552 | return false; |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | bool SystemZInstrInfo:: |
| 556 | isProfitableToIfCvt(MachineBasicBlock &MBB, |
| 557 | unsigned NumCycles, unsigned ExtraPredCycles, |
Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 558 | BranchProbability Probability) const { |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 559 | // Avoid using conditional returns at the end of a loop (since then |
| 560 | // we'd need to emit an unconditional branch to the beginning anyway, |
| 561 | // making the loop body longer). This doesn't apply for low-probability |
| 562 | // loops (eg. compare-and-swap retry), so just decide based on branch |
| 563 | // probability instead of looping structure. |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 564 | // However, since Compare and Trap instructions cost the same as a regular |
| 565 | // Compare instruction, we should allow the if conversion to convert this |
| 566 | // into a Conditional Compare regardless of the branch probability. |
| 567 | if (MBB.getLastNonDebugInstr()->getOpcode() != SystemZ::Trap && |
| 568 | MBB.succ_empty() && Probability < BranchProbability(1, 8)) |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 569 | return false; |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 570 | // For now only convert single instructions. |
| 571 | return NumCycles == 1; |
| 572 | } |
| 573 | |
| 574 | bool SystemZInstrInfo:: |
| 575 | isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 576 | unsigned NumCyclesT, unsigned ExtraPredCyclesT, |
| 577 | MachineBasicBlock &FMBB, |
| 578 | unsigned NumCyclesF, unsigned ExtraPredCyclesF, |
Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 579 | BranchProbability Probability) const { |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 580 | // For now avoid converting mutually-exclusive cases. |
| 581 | return false; |
| 582 | } |
| 583 | |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 584 | bool SystemZInstrInfo:: |
| 585 | isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, |
| 586 | BranchProbability Probability) const { |
| 587 | // For now only duplicate single instructions. |
| 588 | return NumCycles == 1; |
| 589 | } |
| 590 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 591 | bool SystemZInstrInfo::PredicateInstruction( |
| 592 | MachineInstr &MI, ArrayRef<MachineOperand> Pred) const { |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 593 | assert(Pred.size() == 2 && "Invalid condition"); |
| 594 | unsigned CCValid = Pred[0].getImm(); |
| 595 | unsigned CCMask = Pred[1].getImm(); |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 596 | assert(CCMask > 0 && CCMask < 15 && "Invalid predicate"); |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 597 | unsigned Opcode = MI.getOpcode(); |
Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 598 | if (STI.hasLoadStoreOnCond()) { |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 599 | if (unsigned CondOpcode = getConditionalMove(Opcode)) { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 600 | MI.setDesc(get(CondOpcode)); |
| 601 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 602 | .addImm(CCValid) |
| 603 | .addImm(CCMask) |
| 604 | .addReg(SystemZ::CC, RegState::Implicit); |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 605 | return true; |
| 606 | } |
| 607 | } |
Zhan Jun Liau | def708a | 2016-07-11 18:45:03 +0000 | [diff] [blame] | 608 | if (STI.hasLoadStoreOnCond2()) { |
| 609 | if (unsigned CondOpcode = getConditionalLoadImmediate(Opcode)) { |
| 610 | MI.setDesc(get(CondOpcode)); |
| 611 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 612 | .addImm(CCValid) |
| 613 | .addImm(CCMask) |
| 614 | .addReg(SystemZ::CC, RegState::Implicit); |
| 615 | return true; |
| 616 | } |
| 617 | } |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 618 | if (Opcode == SystemZ::Trap) { |
| 619 | MI.setDesc(get(SystemZ::CondTrap)); |
| 620 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 621 | .addImm(CCValid).addImm(CCMask) |
| 622 | .addReg(SystemZ::CC, RegState::Implicit); |
| 623 | return true; |
| 624 | } |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 625 | if (Opcode == SystemZ::Return) { |
| 626 | MI.setDesc(get(SystemZ::CondReturn)); |
| 627 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 628 | .addImm(CCValid).addImm(CCMask) |
| 629 | .addReg(SystemZ::CC, RegState::Implicit); |
| 630 | return true; |
| 631 | } |
Ulrich Weigand | fa2dffb | 2016-04-08 17:22:19 +0000 | [diff] [blame] | 632 | if (Opcode == SystemZ::CallJG) { |
Zhan Jun Liau | a5d60af | 2016-07-07 15:34:46 +0000 | [diff] [blame] | 633 | MachineOperand FirstOp = MI.getOperand(0); |
Ulrich Weigand | fa2dffb | 2016-04-08 17:22:19 +0000 | [diff] [blame] | 634 | const uint32_t *RegMask = MI.getOperand(1).getRegMask(); |
| 635 | MI.RemoveOperand(1); |
| 636 | MI.RemoveOperand(0); |
| 637 | MI.setDesc(get(SystemZ::CallBRCL)); |
| 638 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 639 | .addImm(CCValid).addImm(CCMask) |
Zhan Jun Liau | a5d60af | 2016-07-07 15:34:46 +0000 | [diff] [blame] | 640 | .addOperand(FirstOp) |
Ulrich Weigand | fa2dffb | 2016-04-08 17:22:19 +0000 | [diff] [blame] | 641 | .addRegMask(RegMask) |
| 642 | .addReg(SystemZ::CC, RegState::Implicit); |
| 643 | return true; |
| 644 | } |
Ulrich Weigand | 848a513 | 2016-04-11 12:12:32 +0000 | [diff] [blame] | 645 | if (Opcode == SystemZ::CallBR) { |
| 646 | const uint32_t *RegMask = MI.getOperand(0).getRegMask(); |
| 647 | MI.RemoveOperand(0); |
| 648 | MI.setDesc(get(SystemZ::CallBCR)); |
| 649 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 650 | .addImm(CCValid).addImm(CCMask) |
| 651 | .addRegMask(RegMask) |
| 652 | .addReg(SystemZ::CC, RegState::Implicit); |
| 653 | return true; |
| 654 | } |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 655 | return false; |
| 656 | } |
| 657 | |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 658 | void SystemZInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 659 | MachineBasicBlock::iterator MBBI, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 660 | const DebugLoc &DL, unsigned DestReg, |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 661 | unsigned SrcReg, bool KillSrc) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 662 | // Split 128-bit GPR moves into two 64-bit moves. This handles ADDR128 too. |
| 663 | if (SystemZ::GR128BitRegClass.contains(DestReg, SrcReg)) { |
Richard Sandiford | 87a4436 | 2013-09-30 10:28:35 +0000 | [diff] [blame] | 664 | copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_h64), |
| 665 | RI.getSubReg(SrcReg, SystemZ::subreg_h64), KillSrc); |
| 666 | copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_l64), |
| 667 | RI.getSubReg(SrcReg, SystemZ::subreg_l64), KillSrc); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 668 | return; |
| 669 | } |
| 670 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 671 | if (SystemZ::GRX32BitRegClass.contains(DestReg, SrcReg)) { |
| 672 | emitGRX32Move(MBB, MBBI, DL, DestReg, SrcReg, SystemZ::LR, 32, KillSrc); |
| 673 | return; |
| 674 | } |
| 675 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 676 | // Everything else needs only one instruction. |
| 677 | unsigned Opcode; |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 678 | if (SystemZ::GR64BitRegClass.contains(DestReg, SrcReg)) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 679 | Opcode = SystemZ::LGR; |
| 680 | else if (SystemZ::FP32BitRegClass.contains(DestReg, SrcReg)) |
Ulrich Weigand | cdce026 | 2016-03-14 13:50:03 +0000 | [diff] [blame] | 681 | // For z13 we prefer LDR over LER to avoid partial register dependencies. |
| 682 | Opcode = STI.hasVector() ? SystemZ::LDR32 : SystemZ::LER; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 683 | else if (SystemZ::FP64BitRegClass.contains(DestReg, SrcReg)) |
| 684 | Opcode = SystemZ::LDR; |
| 685 | else if (SystemZ::FP128BitRegClass.contains(DestReg, SrcReg)) |
| 686 | Opcode = SystemZ::LXR; |
Ulrich Weigand | 49506d7 | 2015-05-05 19:28:34 +0000 | [diff] [blame] | 687 | else if (SystemZ::VR32BitRegClass.contains(DestReg, SrcReg)) |
| 688 | Opcode = SystemZ::VLR32; |
| 689 | else if (SystemZ::VR64BitRegClass.contains(DestReg, SrcReg)) |
| 690 | Opcode = SystemZ::VLR64; |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame] | 691 | else if (SystemZ::VR128BitRegClass.contains(DestReg, SrcReg)) |
| 692 | Opcode = SystemZ::VLR; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 693 | else |
| 694 | llvm_unreachable("Impossible reg-to-reg copy"); |
| 695 | |
| 696 | BuildMI(MBB, MBBI, DL, get(Opcode), DestReg) |
| 697 | .addReg(SrcReg, getKillRegState(KillSrc)); |
| 698 | } |
| 699 | |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 700 | void SystemZInstrInfo::storeRegToStackSlot( |
| 701 | MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, |
| 702 | bool isKill, int FrameIdx, const TargetRegisterClass *RC, |
| 703 | const TargetRegisterInfo *TRI) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 704 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); |
| 705 | |
| 706 | // Callers may expect a single instruction, so keep 128-bit moves |
| 707 | // together for now and lower them after register allocation. |
| 708 | unsigned LoadOpcode, StoreOpcode; |
| 709 | getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode); |
| 710 | addFrameReference(BuildMI(MBB, MBBI, DL, get(StoreOpcode)) |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 711 | .addReg(SrcReg, getKillRegState(isKill)), |
| 712 | FrameIdx); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 713 | } |
| 714 | |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 715 | void SystemZInstrInfo::loadRegFromStackSlot( |
| 716 | MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, |
| 717 | int FrameIdx, const TargetRegisterClass *RC, |
| 718 | const TargetRegisterInfo *TRI) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 719 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); |
| 720 | |
| 721 | // Callers may expect a single instruction, so keep 128-bit moves |
| 722 | // together for now and lower them after register allocation. |
| 723 | unsigned LoadOpcode, StoreOpcode; |
| 724 | getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode); |
| 725 | addFrameReference(BuildMI(MBB, MBBI, DL, get(LoadOpcode), DestReg), |
| 726 | FrameIdx); |
| 727 | } |
| 728 | |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 729 | // Return true if MI is a simple load or store with a 12-bit displacement |
| 730 | // and no index. Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores. |
| 731 | static bool isSimpleBD12Move(const MachineInstr *MI, unsigned Flag) { |
| 732 | const MCInstrDesc &MCID = MI->getDesc(); |
| 733 | return ((MCID.TSFlags & Flag) && |
| 734 | isUInt<12>(MI->getOperand(2).getImm()) && |
| 735 | MI->getOperand(3).getReg() == 0); |
| 736 | } |
| 737 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 738 | namespace { |
Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 739 | struct LogicOp { |
| 740 | LogicOp() : RegSize(0), ImmLSB(0), ImmSize(0) {} |
| 741 | LogicOp(unsigned regSize, unsigned immLSB, unsigned immSize) |
| 742 | : RegSize(regSize), ImmLSB(immLSB), ImmSize(immSize) {} |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 743 | |
Aaron Ballman | b46962f | 2015-02-15 22:00:20 +0000 | [diff] [blame] | 744 | explicit operator bool() const { return RegSize; } |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 745 | |
Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 746 | unsigned RegSize, ImmLSB, ImmSize; |
| 747 | }; |
| 748 | } // end anonymous namespace |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 749 | |
| 750 | static LogicOp interpretAndImmediate(unsigned Opcode) { |
| 751 | switch (Opcode) { |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 752 | case SystemZ::NILMux: return LogicOp(32, 0, 16); |
| 753 | case SystemZ::NIHMux: return LogicOp(32, 16, 16); |
Richard Sandiford | 652784e | 2013-09-25 11:11:53 +0000 | [diff] [blame] | 754 | case SystemZ::NILL64: return LogicOp(64, 0, 16); |
| 755 | case SystemZ::NILH64: return LogicOp(64, 16, 16); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 756 | case SystemZ::NIHL64: return LogicOp(64, 32, 16); |
| 757 | case SystemZ::NIHH64: return LogicOp(64, 48, 16); |
| 758 | case SystemZ::NIFMux: return LogicOp(32, 0, 32); |
Richard Sandiford | 652784e | 2013-09-25 11:11:53 +0000 | [diff] [blame] | 759 | case SystemZ::NILF64: return LogicOp(64, 0, 32); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 760 | case SystemZ::NIHF64: return LogicOp(64, 32, 32); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 761 | default: return LogicOp(); |
| 762 | } |
| 763 | } |
| 764 | |
Jonas Paulsson | 9028acf | 2016-05-02 09:37:40 +0000 | [diff] [blame] | 765 | static void transferDeadCC(MachineInstr *OldMI, MachineInstr *NewMI) { |
| 766 | if (OldMI->registerDefIsDead(SystemZ::CC)) { |
| 767 | MachineOperand *CCDef = NewMI->findRegisterDefOperand(SystemZ::CC); |
| 768 | if (CCDef != nullptr) |
| 769 | CCDef->setIsDead(true); |
| 770 | } |
| 771 | } |
| 772 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 773 | // Used to return from convertToThreeAddress after replacing two-address |
| 774 | // instruction OldMI with three-address instruction NewMI. |
| 775 | static MachineInstr *finishConvertToThreeAddress(MachineInstr *OldMI, |
| 776 | MachineInstr *NewMI, |
| 777 | LiveVariables *LV) { |
| 778 | if (LV) { |
| 779 | unsigned NumOps = OldMI->getNumOperands(); |
| 780 | for (unsigned I = 1; I < NumOps; ++I) { |
| 781 | MachineOperand &Op = OldMI->getOperand(I); |
| 782 | if (Op.isReg() && Op.isKill()) |
Duncan P. N. Exon Smith | d26fdc8 | 2016-07-01 01:51:32 +0000 | [diff] [blame] | 783 | LV->replaceKillInstruction(Op.getReg(), *OldMI, *NewMI); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 784 | } |
| 785 | } |
Jonas Paulsson | 9028acf | 2016-05-02 09:37:40 +0000 | [diff] [blame] | 786 | transferDeadCC(OldMI, NewMI); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 787 | return NewMI; |
| 788 | } |
| 789 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 790 | MachineInstr *SystemZInstrInfo::convertToThreeAddress( |
| 791 | MachineFunction::iterator &MFI, MachineInstr &MI, LiveVariables *LV) const { |
| 792 | MachineBasicBlock *MBB = MI.getParent(); |
Jonas Paulsson | 7fa69cd | 2015-12-04 12:48:51 +0000 | [diff] [blame] | 793 | MachineFunction *MF = MBB->getParent(); |
| 794 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 795 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 796 | unsigned Opcode = MI.getOpcode(); |
| 797 | unsigned NumOps = MI.getNumOperands(); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 798 | |
| 799 | // Try to convert something like SLL into SLLK, if supported. |
| 800 | // We prefer to keep the two-operand form where possible both |
| 801 | // because it tends to be shorter and because some instructions |
| 802 | // have memory forms that can be used during spilling. |
Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 803 | if (STI.hasDistinctOps()) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 804 | MachineOperand &Dest = MI.getOperand(0); |
| 805 | MachineOperand &Src = MI.getOperand(1); |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 806 | unsigned DestReg = Dest.getReg(); |
| 807 | unsigned SrcReg = Src.getReg(); |
| 808 | // AHIMux is only really a three-operand instruction when both operands |
| 809 | // are low registers. Try to constrain both operands to be low if |
| 810 | // possible. |
| 811 | if (Opcode == SystemZ::AHIMux && |
| 812 | TargetRegisterInfo::isVirtualRegister(DestReg) && |
| 813 | TargetRegisterInfo::isVirtualRegister(SrcReg) && |
| 814 | MRI.getRegClass(DestReg)->contains(SystemZ::R1L) && |
| 815 | MRI.getRegClass(SrcReg)->contains(SystemZ::R1L)) { |
| 816 | MRI.constrainRegClass(DestReg, &SystemZ::GR32BitRegClass); |
| 817 | MRI.constrainRegClass(SrcReg, &SystemZ::GR32BitRegClass); |
| 818 | } |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 819 | int ThreeOperandOpcode = SystemZ::getThreeOperandOpcode(Opcode); |
| 820 | if (ThreeOperandOpcode >= 0) { |
Jonas Paulsson | 7fa69cd | 2015-12-04 12:48:51 +0000 | [diff] [blame] | 821 | // Create three address instruction without adding the implicit |
| 822 | // operands. Those will instead be copied over from the original |
| 823 | // instruction by the loop below. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 824 | MachineInstrBuilder MIB( |
| 825 | *MF, MF->CreateMachineInstr(get(ThreeOperandOpcode), MI.getDebugLoc(), |
| 826 | /*NoImplicit=*/true)); |
Jonas Paulsson | 7fa69cd | 2015-12-04 12:48:51 +0000 | [diff] [blame] | 827 | MIB.addOperand(Dest); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 828 | // Keep the kill state, but drop the tied flag. |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 829 | MIB.addReg(Src.getReg(), getKillRegState(Src.isKill()), Src.getSubReg()); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 830 | // Keep the remaining operands as-is. |
| 831 | for (unsigned I = 2; I < NumOps; ++I) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 832 | MIB.addOperand(MI.getOperand(I)); |
Jonas Paulsson | 7fa69cd | 2015-12-04 12:48:51 +0000 | [diff] [blame] | 833 | MBB->insert(MI, MIB); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 834 | return finishConvertToThreeAddress(&MI, MIB, LV); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 835 | } |
| 836 | } |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 837 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 838 | // Try to convert an AND into an RISBG-type instruction. |
| 839 | if (LogicOp And = interpretAndImmediate(Opcode)) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 840 | uint64_t Imm = MI.getOperand(2).getImm() << And.ImmLSB; |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 841 | // AND IMMEDIATE leaves the other bits of the register unchanged. |
| 842 | Imm |= allOnes(And.RegSize) & ~(allOnes(And.ImmSize) << And.ImmLSB); |
| 843 | unsigned Start, End; |
| 844 | if (isRxSBGMask(Imm, And.RegSize, Start, End)) { |
| 845 | unsigned NewOpcode; |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 846 | if (And.RegSize == 64) { |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 847 | NewOpcode = SystemZ::RISBG; |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 848 | // Prefer RISBGN if available, since it does not clobber CC. |
| 849 | if (STI.hasMiscellaneousExtensions()) |
| 850 | NewOpcode = SystemZ::RISBGN; |
| 851 | } else { |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 852 | NewOpcode = SystemZ::RISBMux; |
| 853 | Start &= 31; |
| 854 | End &= 31; |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 855 | } |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 856 | MachineOperand &Dest = MI.getOperand(0); |
| 857 | MachineOperand &Src = MI.getOperand(1); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 858 | MachineInstrBuilder MIB = |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 859 | BuildMI(*MBB, MI, MI.getDebugLoc(), get(NewOpcode)) |
| 860 | .addOperand(Dest) |
| 861 | .addReg(0) |
| 862 | .addReg(Src.getReg(), getKillRegState(Src.isKill()), |
| 863 | Src.getSubReg()) |
| 864 | .addImm(Start) |
| 865 | .addImm(End + 128) |
| 866 | .addImm(0); |
| 867 | return finishConvertToThreeAddress(&MI, MIB, LV); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 868 | } |
| 869 | } |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 870 | return nullptr; |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 873 | MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl( |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 874 | MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops, |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 875 | MachineBasicBlock::iterator InsertPt, int FrameIndex, |
| 876 | LiveIntervals *LIS) const { |
| 877 | const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame^] | 878 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 879 | unsigned Size = MFI.getObjectSize(FrameIndex); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 880 | unsigned Opcode = MI.getOpcode(); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 881 | |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 882 | if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 883 | if (LIS != nullptr && (Opcode == SystemZ::LA || Opcode == SystemZ::LAY) && |
| 884 | isInt<8>(MI.getOperand(2).getImm()) && !MI.getOperand(3).getReg()) { |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 885 | |
| 886 | // Check CC liveness, since new instruction introduces a dead |
| 887 | // def of CC. |
| 888 | MCRegUnitIterator CCUnit(SystemZ::CC, TRI); |
| 889 | LiveRange &CCLiveRange = LIS->getRegUnit(*CCUnit); |
| 890 | ++CCUnit; |
| 891 | assert (!CCUnit.isValid() && "CC only has one reg unit."); |
| 892 | SlotIndex MISlot = |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 893 | LIS->getSlotIndexes()->getInstructionIndex(MI).getRegSlot(); |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 894 | if (!CCLiveRange.liveAt(MISlot)) { |
| 895 | // LA(Y) %reg, CONST(%reg) -> AGSI %mem, CONST |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 896 | MachineInstr *BuiltMI = BuildMI(*InsertPt->getParent(), InsertPt, |
| 897 | MI.getDebugLoc(), get(SystemZ::AGSI)) |
| 898 | .addFrameIndex(FrameIndex) |
| 899 | .addImm(0) |
| 900 | .addImm(MI.getOperand(2).getImm()); |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 901 | BuiltMI->findRegisterDefOperand(SystemZ::CC)->setIsDead(true); |
| 902 | CCLiveRange.createDeadDef(MISlot, LIS->getVNInfoAllocator()); |
| 903 | return BuiltMI; |
| 904 | } |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 905 | } |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 906 | return nullptr; |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | // All other cases require a single operand. |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 910 | if (Ops.size() != 1) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 911 | return nullptr; |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 912 | |
| 913 | unsigned OpNum = Ops[0]; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 914 | assert(Size == |
| 915 | MF.getRegInfo() |
| 916 | .getRegClass(MI.getOperand(OpNum).getReg()) |
| 917 | ->getSize() && |
Benjamin Kramer | 421c8fb | 2013-07-02 21:17:31 +0000 | [diff] [blame] | 918 | "Invalid size combination"); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 919 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 920 | if ((Opcode == SystemZ::AHI || Opcode == SystemZ::AGHI) && OpNum == 0 && |
| 921 | isInt<8>(MI.getOperand(2).getImm())) { |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 922 | // A(G)HI %reg, CONST -> A(G)SI %mem, CONST |
| 923 | Opcode = (Opcode == SystemZ::AHI ? SystemZ::ASI : SystemZ::AGSI); |
Jonas Paulsson | 9028acf | 2016-05-02 09:37:40 +0000 | [diff] [blame] | 924 | MachineInstr *BuiltMI = |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 925 | BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), get(Opcode)) |
| 926 | .addFrameIndex(FrameIndex) |
| 927 | .addImm(0) |
| 928 | .addImm(MI.getOperand(2).getImm()); |
| 929 | transferDeadCC(&MI, BuiltMI); |
Jonas Paulsson | 9028acf | 2016-05-02 09:37:40 +0000 | [diff] [blame] | 930 | return BuiltMI; |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 931 | } |
| 932 | |
Richard Sandiford | 3f0edc2 | 2013-07-12 08:37:17 +0000 | [diff] [blame] | 933 | if (Opcode == SystemZ::LGDR || Opcode == SystemZ::LDGR) { |
| 934 | bool Op0IsGPR = (Opcode == SystemZ::LGDR); |
| 935 | bool Op1IsGPR = (Opcode == SystemZ::LDGR); |
| 936 | // If we're spilling the destination of an LDGR or LGDR, store the |
| 937 | // source register instead. |
| 938 | if (OpNum == 0) { |
| 939 | unsigned StoreOpcode = Op1IsGPR ? SystemZ::STG : SystemZ::STD; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 940 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 941 | get(StoreOpcode)) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 942 | .addOperand(MI.getOperand(1)) |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 943 | .addFrameIndex(FrameIndex) |
| 944 | .addImm(0) |
| 945 | .addReg(0); |
Richard Sandiford | 3f0edc2 | 2013-07-12 08:37:17 +0000 | [diff] [blame] | 946 | } |
| 947 | // If we're spilling the source of an LDGR or LGDR, load the |
| 948 | // destination register instead. |
| 949 | if (OpNum == 1) { |
| 950 | unsigned LoadOpcode = Op0IsGPR ? SystemZ::LG : SystemZ::LD; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 951 | unsigned Dest = MI.getOperand(0).getReg(); |
| 952 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 953 | get(LoadOpcode), Dest) |
| 954 | .addFrameIndex(FrameIndex) |
| 955 | .addImm(0) |
| 956 | .addReg(0); |
Richard Sandiford | 3f0edc2 | 2013-07-12 08:37:17 +0000 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 960 | // Look for cases where the source of a simple store or the destination |
| 961 | // of a simple load is being spilled. Try to use MVC instead. |
| 962 | // |
| 963 | // Although MVC is in practice a fast choice in these cases, it is still |
| 964 | // logically a bytewise copy. This means that we cannot use it if the |
Richard Sandiford | 067817e | 2013-09-27 15:29:20 +0000 | [diff] [blame] | 965 | // load or store is volatile. We also wouldn't be able to use MVC if |
| 966 | // the two memories partially overlap, but that case cannot occur here, |
| 967 | // because we know that one of the memories is a full frame index. |
| 968 | // |
| 969 | // For performance reasons, we also want to avoid using MVC if the addresses |
| 970 | // might be equal. We don't worry about that case here, because spill slot |
| 971 | // coloring happens later, and because we have special code to remove |
| 972 | // MVCs that turn out to be redundant. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 973 | if (OpNum == 0 && MI.hasOneMemOperand()) { |
| 974 | MachineMemOperand *MMO = *MI.memoperands_begin(); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 975 | if (MMO->getSize() == Size && !MMO->isVolatile()) { |
| 976 | // Handle conversion of loads. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 977 | if (isSimpleBD12Move(&MI, SystemZII::SimpleBDXLoad)) { |
| 978 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 979 | get(SystemZ::MVC)) |
| 980 | .addFrameIndex(FrameIndex) |
| 981 | .addImm(0) |
| 982 | .addImm(Size) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 983 | .addOperand(MI.getOperand(1)) |
| 984 | .addImm(MI.getOperand(2).getImm()) |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 985 | .addMemOperand(MMO); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 986 | } |
| 987 | // Handle conversion of stores. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 988 | if (isSimpleBD12Move(&MI, SystemZII::SimpleBDXStore)) { |
| 989 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 990 | get(SystemZ::MVC)) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 991 | .addOperand(MI.getOperand(1)) |
| 992 | .addImm(MI.getOperand(2).getImm()) |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 993 | .addImm(Size) |
| 994 | .addFrameIndex(FrameIndex) |
| 995 | .addImm(0) |
| 996 | .addMemOperand(MMO); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | } |
| 1000 | |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1001 | // If the spilled operand is the final one, try to change <INSN>R |
| 1002 | // into <INSN>. |
Richard Sandiford | 3f0edc2 | 2013-07-12 08:37:17 +0000 | [diff] [blame] | 1003 | int MemOpcode = SystemZ::getMemOpcode(Opcode); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1004 | if (MemOpcode >= 0) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1005 | unsigned NumOps = MI.getNumExplicitOperands(); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1006 | if (OpNum == NumOps - 1) { |
| 1007 | const MCInstrDesc &MemDesc = get(MemOpcode); |
| 1008 | uint64_t AccessBytes = SystemZII::getAccessSize(MemDesc.TSFlags); |
| 1009 | assert(AccessBytes != 0 && "Size of access should be known"); |
| 1010 | assert(AccessBytes <= Size && "Access outside the frame index"); |
| 1011 | uint64_t Offset = Size - AccessBytes; |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1012 | MachineInstrBuilder MIB = BuildMI(*InsertPt->getParent(), InsertPt, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1013 | MI.getDebugLoc(), get(MemOpcode)); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1014 | for (unsigned I = 0; I < OpNum; ++I) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1015 | MIB.addOperand(MI.getOperand(I)); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1016 | MIB.addFrameIndex(FrameIndex).addImm(Offset); |
| 1017 | if (MemDesc.TSFlags & SystemZII::HasIndex) |
| 1018 | MIB.addReg(0); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1019 | transferDeadCC(&MI, MIB); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1020 | return MIB; |
| 1021 | } |
| 1022 | } |
| 1023 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1024 | return nullptr; |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1027 | MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl( |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1028 | MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops, |
| 1029 | MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI, |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 1030 | LiveIntervals *LIS) const { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1031 | return nullptr; |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1034 | bool SystemZInstrInfo::expandPostRAPseudo(MachineInstr &MI) const { |
| 1035 | switch (MI.getOpcode()) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1036 | case SystemZ::L128: |
| 1037 | splitMove(MI, SystemZ::LG); |
| 1038 | return true; |
| 1039 | |
| 1040 | case SystemZ::ST128: |
| 1041 | splitMove(MI, SystemZ::STG); |
| 1042 | return true; |
| 1043 | |
| 1044 | case SystemZ::LX: |
| 1045 | splitMove(MI, SystemZ::LD); |
| 1046 | return true; |
| 1047 | |
| 1048 | case SystemZ::STX: |
| 1049 | splitMove(MI, SystemZ::STD); |
| 1050 | return true; |
| 1051 | |
Richard Sandiford | 89e160d | 2013-10-01 12:11:47 +0000 | [diff] [blame] | 1052 | case SystemZ::LBMux: |
| 1053 | expandRXYPseudo(MI, SystemZ::LB, SystemZ::LBH); |
| 1054 | return true; |
| 1055 | |
| 1056 | case SystemZ::LHMux: |
| 1057 | expandRXYPseudo(MI, SystemZ::LH, SystemZ::LHH); |
| 1058 | return true; |
| 1059 | |
Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 1060 | case SystemZ::LLCRMux: |
| 1061 | expandZExtPseudo(MI, SystemZ::LLCR, 8); |
| 1062 | return true; |
| 1063 | |
| 1064 | case SystemZ::LLHRMux: |
| 1065 | expandZExtPseudo(MI, SystemZ::LLHR, 16); |
| 1066 | return true; |
| 1067 | |
Richard Sandiford | 0d46b1a | 2013-10-01 12:19:08 +0000 | [diff] [blame] | 1068 | case SystemZ::LLCMux: |
| 1069 | expandRXYPseudo(MI, SystemZ::LLC, SystemZ::LLCH); |
| 1070 | return true; |
| 1071 | |
| 1072 | case SystemZ::LLHMux: |
| 1073 | expandRXYPseudo(MI, SystemZ::LLH, SystemZ::LLHH); |
| 1074 | return true; |
| 1075 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 1076 | case SystemZ::LMux: |
| 1077 | expandRXYPseudo(MI, SystemZ::L, SystemZ::LFH); |
| 1078 | return true; |
| 1079 | |
Richard Sandiford | 5469c39 | 2013-10-01 12:22:49 +0000 | [diff] [blame] | 1080 | case SystemZ::STCMux: |
| 1081 | expandRXYPseudo(MI, SystemZ::STC, SystemZ::STCH); |
| 1082 | return true; |
| 1083 | |
| 1084 | case SystemZ::STHMux: |
| 1085 | expandRXYPseudo(MI, SystemZ::STH, SystemZ::STHH); |
| 1086 | return true; |
| 1087 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 1088 | case SystemZ::STMux: |
| 1089 | expandRXYPseudo(MI, SystemZ::ST, SystemZ::STFH); |
| 1090 | return true; |
| 1091 | |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 1092 | case SystemZ::LHIMux: |
| 1093 | expandRIPseudo(MI, SystemZ::LHI, SystemZ::IIHF, true); |
| 1094 | return true; |
| 1095 | |
| 1096 | case SystemZ::IIFMux: |
| 1097 | expandRIPseudo(MI, SystemZ::IILF, SystemZ::IIHF, false); |
| 1098 | return true; |
| 1099 | |
Richard Sandiford | 1a56931 | 2013-10-01 13:18:56 +0000 | [diff] [blame] | 1100 | case SystemZ::IILMux: |
| 1101 | expandRIPseudo(MI, SystemZ::IILL, SystemZ::IIHL, false); |
| 1102 | return true; |
| 1103 | |
| 1104 | case SystemZ::IIHMux: |
| 1105 | expandRIPseudo(MI, SystemZ::IILH, SystemZ::IIHH, false); |
| 1106 | return true; |
| 1107 | |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1108 | case SystemZ::NIFMux: |
| 1109 | expandRIPseudo(MI, SystemZ::NILF, SystemZ::NIHF, false); |
| 1110 | return true; |
| 1111 | |
| 1112 | case SystemZ::NILMux: |
| 1113 | expandRIPseudo(MI, SystemZ::NILL, SystemZ::NIHL, false); |
| 1114 | return true; |
| 1115 | |
| 1116 | case SystemZ::NIHMux: |
| 1117 | expandRIPseudo(MI, SystemZ::NILH, SystemZ::NIHH, false); |
| 1118 | return true; |
| 1119 | |
Richard Sandiford | 6e96ac6 | 2013-10-01 13:22:41 +0000 | [diff] [blame] | 1120 | case SystemZ::OIFMux: |
| 1121 | expandRIPseudo(MI, SystemZ::OILF, SystemZ::OIHF, false); |
| 1122 | return true; |
| 1123 | |
| 1124 | case SystemZ::OILMux: |
| 1125 | expandRIPseudo(MI, SystemZ::OILL, SystemZ::OIHL, false); |
| 1126 | return true; |
| 1127 | |
| 1128 | case SystemZ::OIHMux: |
| 1129 | expandRIPseudo(MI, SystemZ::OILH, SystemZ::OIHH, false); |
| 1130 | return true; |
| 1131 | |
Richard Sandiford | 5718dac | 2013-10-01 14:08:44 +0000 | [diff] [blame] | 1132 | case SystemZ::XIFMux: |
| 1133 | expandRIPseudo(MI, SystemZ::XILF, SystemZ::XIHF, false); |
| 1134 | return true; |
| 1135 | |
Richard Sandiford | 2cac763 | 2013-10-01 14:41:52 +0000 | [diff] [blame] | 1136 | case SystemZ::TMLMux: |
| 1137 | expandRIPseudo(MI, SystemZ::TMLL, SystemZ::TMHL, false); |
| 1138 | return true; |
| 1139 | |
| 1140 | case SystemZ::TMHMux: |
| 1141 | expandRIPseudo(MI, SystemZ::TMLH, SystemZ::TMHH, false); |
| 1142 | return true; |
| 1143 | |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 1144 | case SystemZ::AHIMux: |
| 1145 | expandRIPseudo(MI, SystemZ::AHI, SystemZ::AIH, false); |
| 1146 | return true; |
| 1147 | |
| 1148 | case SystemZ::AHIMuxK: |
| 1149 | expandRIEPseudo(MI, SystemZ::AHI, SystemZ::AHIK, SystemZ::AIH); |
| 1150 | return true; |
| 1151 | |
| 1152 | case SystemZ::AFIMux: |
| 1153 | expandRIPseudo(MI, SystemZ::AFI, SystemZ::AIH, false); |
| 1154 | return true; |
| 1155 | |
Richard Sandiford | a9ac0e0 | 2013-10-01 14:56:23 +0000 | [diff] [blame] | 1156 | case SystemZ::CFIMux: |
| 1157 | expandRIPseudo(MI, SystemZ::CFI, SystemZ::CIH, false); |
| 1158 | return true; |
| 1159 | |
| 1160 | case SystemZ::CLFIMux: |
| 1161 | expandRIPseudo(MI, SystemZ::CLFI, SystemZ::CLIH, false); |
| 1162 | return true; |
| 1163 | |
Richard Sandiford | b63e300 | 2013-10-01 15:00:44 +0000 | [diff] [blame] | 1164 | case SystemZ::CMux: |
| 1165 | expandRXYPseudo(MI, SystemZ::C, SystemZ::CHF); |
| 1166 | return true; |
| 1167 | |
| 1168 | case SystemZ::CLMux: |
| 1169 | expandRXYPseudo(MI, SystemZ::CL, SystemZ::CLHF); |
| 1170 | return true; |
| 1171 | |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1172 | case SystemZ::RISBMux: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1173 | bool DestIsHigh = isHighReg(MI.getOperand(0).getReg()); |
| 1174 | bool SrcIsHigh = isHighReg(MI.getOperand(2).getReg()); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1175 | if (SrcIsHigh == DestIsHigh) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1176 | MI.setDesc(get(DestIsHigh ? SystemZ::RISBHH : SystemZ::RISBLL)); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1177 | else { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1178 | MI.setDesc(get(DestIsHigh ? SystemZ::RISBHL : SystemZ::RISBLH)); |
| 1179 | MI.getOperand(5).setImm(MI.getOperand(5).getImm() ^ 32); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1180 | } |
| 1181 | return true; |
| 1182 | } |
| 1183 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1184 | case SystemZ::ADJDYNALLOC: |
| 1185 | splitAdjDynAlloc(MI); |
| 1186 | return true; |
| 1187 | |
Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 1188 | case TargetOpcode::LOAD_STACK_GUARD: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1189 | expandLoadStackGuard(&MI); |
Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 1190 | return true; |
| 1191 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1192 | default: |
| 1193 | return false; |
| 1194 | } |
| 1195 | } |
| 1196 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1197 | uint64_t SystemZInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const { |
| 1198 | if (MI.getOpcode() == TargetOpcode::INLINEASM) { |
| 1199 | const MachineFunction *MF = MI.getParent()->getParent(); |
| 1200 | const char *AsmStr = MI.getOperand(0).getSymbolName(); |
Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 1201 | return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo()); |
| 1202 | } |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1203 | return MI.getDesc().getSize(); |
Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 1206 | SystemZII::Branch |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1207 | SystemZInstrInfo::getBranchInfo(const MachineInstr &MI) const { |
| 1208 | switch (MI.getOpcode()) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1209 | case SystemZ::BR: |
| 1210 | case SystemZ::J: |
| 1211 | case SystemZ::JG: |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1212 | return SystemZII::Branch(SystemZII::BranchNormal, SystemZ::CCMASK_ANY, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1213 | SystemZ::CCMASK_ANY, &MI.getOperand(0)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1214 | |
| 1215 | case SystemZ::BRC: |
| 1216 | case SystemZ::BRCL: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1217 | return SystemZII::Branch(SystemZII::BranchNormal, MI.getOperand(0).getImm(), |
| 1218 | MI.getOperand(1).getImm(), &MI.getOperand(2)); |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1219 | |
Richard Sandiford | c212125 | 2013-08-05 11:23:46 +0000 | [diff] [blame] | 1220 | case SystemZ::BRCT: |
| 1221 | return SystemZII::Branch(SystemZII::BranchCT, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1222 | SystemZ::CCMASK_CMP_NE, &MI.getOperand(2)); |
Richard Sandiford | c212125 | 2013-08-05 11:23:46 +0000 | [diff] [blame] | 1223 | |
| 1224 | case SystemZ::BRCTG: |
| 1225 | return SystemZII::Branch(SystemZII::BranchCTG, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1226 | SystemZ::CCMASK_CMP_NE, &MI.getOperand(2)); |
Richard Sandiford | c212125 | 2013-08-05 11:23:46 +0000 | [diff] [blame] | 1227 | |
Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 1228 | case SystemZ::CIJ: |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1229 | case SystemZ::CRJ: |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 1230 | return SystemZII::Branch(SystemZII::BranchC, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1231 | MI.getOperand(2).getImm(), &MI.getOperand(3)); |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1232 | |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1233 | case SystemZ::CLIJ: |
| 1234 | case SystemZ::CLRJ: |
| 1235 | return SystemZII::Branch(SystemZII::BranchCL, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1236 | MI.getOperand(2).getImm(), &MI.getOperand(3)); |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1237 | |
Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 1238 | case SystemZ::CGIJ: |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1239 | case SystemZ::CGRJ: |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 1240 | return SystemZII::Branch(SystemZII::BranchCG, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1241 | MI.getOperand(2).getImm(), &MI.getOperand(3)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1242 | |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1243 | case SystemZ::CLGIJ: |
| 1244 | case SystemZ::CLGRJ: |
| 1245 | return SystemZII::Branch(SystemZII::BranchCLG, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1246 | MI.getOperand(2).getImm(), &MI.getOperand(3)); |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1247 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1248 | default: |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 1249 | llvm_unreachable("Unrecognized branch opcode"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | void SystemZInstrInfo::getLoadStoreOpcodes(const TargetRegisterClass *RC, |
| 1254 | unsigned &LoadOpcode, |
| 1255 | unsigned &StoreOpcode) const { |
| 1256 | if (RC == &SystemZ::GR32BitRegClass || RC == &SystemZ::ADDR32BitRegClass) { |
| 1257 | LoadOpcode = SystemZ::L; |
Richard Sandiford | 6cbd7f0 | 2013-09-25 10:29:47 +0000 | [diff] [blame] | 1258 | StoreOpcode = SystemZ::ST; |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 1259 | } else if (RC == &SystemZ::GRH32BitRegClass) { |
| 1260 | LoadOpcode = SystemZ::LFH; |
| 1261 | StoreOpcode = SystemZ::STFH; |
| 1262 | } else if (RC == &SystemZ::GRX32BitRegClass) { |
| 1263 | LoadOpcode = SystemZ::LMux; |
| 1264 | StoreOpcode = SystemZ::STMux; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1265 | } else if (RC == &SystemZ::GR64BitRegClass || |
| 1266 | RC == &SystemZ::ADDR64BitRegClass) { |
| 1267 | LoadOpcode = SystemZ::LG; |
| 1268 | StoreOpcode = SystemZ::STG; |
| 1269 | } else if (RC == &SystemZ::GR128BitRegClass || |
| 1270 | RC == &SystemZ::ADDR128BitRegClass) { |
| 1271 | LoadOpcode = SystemZ::L128; |
| 1272 | StoreOpcode = SystemZ::ST128; |
| 1273 | } else if (RC == &SystemZ::FP32BitRegClass) { |
| 1274 | LoadOpcode = SystemZ::LE; |
| 1275 | StoreOpcode = SystemZ::STE; |
| 1276 | } else if (RC == &SystemZ::FP64BitRegClass) { |
| 1277 | LoadOpcode = SystemZ::LD; |
| 1278 | StoreOpcode = SystemZ::STD; |
| 1279 | } else if (RC == &SystemZ::FP128BitRegClass) { |
| 1280 | LoadOpcode = SystemZ::LX; |
| 1281 | StoreOpcode = SystemZ::STX; |
Ulrich Weigand | 49506d7 | 2015-05-05 19:28:34 +0000 | [diff] [blame] | 1282 | } else if (RC == &SystemZ::VR32BitRegClass) { |
| 1283 | LoadOpcode = SystemZ::VL32; |
| 1284 | StoreOpcode = SystemZ::VST32; |
| 1285 | } else if (RC == &SystemZ::VR64BitRegClass) { |
| 1286 | LoadOpcode = SystemZ::VL64; |
| 1287 | StoreOpcode = SystemZ::VST64; |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame] | 1288 | } else if (RC == &SystemZ::VF128BitRegClass || |
| 1289 | RC == &SystemZ::VR128BitRegClass) { |
| 1290 | LoadOpcode = SystemZ::VL; |
| 1291 | StoreOpcode = SystemZ::VST; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1292 | } else |
| 1293 | llvm_unreachable("Unsupported regclass to load or store"); |
| 1294 | } |
| 1295 | |
| 1296 | unsigned SystemZInstrInfo::getOpcodeForOffset(unsigned Opcode, |
| 1297 | int64_t Offset) const { |
| 1298 | const MCInstrDesc &MCID = get(Opcode); |
| 1299 | int64_t Offset2 = (MCID.TSFlags & SystemZII::Is128Bit ? Offset + 8 : Offset); |
| 1300 | if (isUInt<12>(Offset) && isUInt<12>(Offset2)) { |
| 1301 | // Get the instruction to use for unsigned 12-bit displacements. |
| 1302 | int Disp12Opcode = SystemZ::getDisp12Opcode(Opcode); |
| 1303 | if (Disp12Opcode >= 0) |
| 1304 | return Disp12Opcode; |
| 1305 | |
| 1306 | // All address-related instructions can use unsigned 12-bit |
| 1307 | // displacements. |
| 1308 | return Opcode; |
| 1309 | } |
| 1310 | if (isInt<20>(Offset) && isInt<20>(Offset2)) { |
| 1311 | // Get the instruction to use for signed 20-bit displacements. |
| 1312 | int Disp20Opcode = SystemZ::getDisp20Opcode(Opcode); |
| 1313 | if (Disp20Opcode >= 0) |
| 1314 | return Disp20Opcode; |
| 1315 | |
| 1316 | // Check whether Opcode allows signed 20-bit displacements. |
| 1317 | if (MCID.TSFlags & SystemZII::Has20BitOffset) |
| 1318 | return Opcode; |
| 1319 | } |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
Richard Sandiford | b49a3ab | 2013-08-05 11:03:20 +0000 | [diff] [blame] | 1323 | unsigned SystemZInstrInfo::getLoadAndTest(unsigned Opcode) const { |
| 1324 | switch (Opcode) { |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 1325 | case SystemZ::L: return SystemZ::LT; |
| 1326 | case SystemZ::LY: return SystemZ::LT; |
| 1327 | case SystemZ::LG: return SystemZ::LTG; |
| 1328 | case SystemZ::LGF: return SystemZ::LTGF; |
| 1329 | case SystemZ::LR: return SystemZ::LTR; |
| 1330 | case SystemZ::LGFR: return SystemZ::LTGFR; |
| 1331 | case SystemZ::LGR: return SystemZ::LTGR; |
| 1332 | case SystemZ::LER: return SystemZ::LTEBR; |
| 1333 | case SystemZ::LDR: return SystemZ::LTDBR; |
| 1334 | case SystemZ::LXR: return SystemZ::LTXBR; |
Jonas Paulsson | 1262932 | 2015-10-01 18:12:28 +0000 | [diff] [blame] | 1335 | case SystemZ::LCDFR: return SystemZ::LCDBR; |
| 1336 | case SystemZ::LPDFR: return SystemZ::LPDBR; |
| 1337 | case SystemZ::LNDFR: return SystemZ::LNDBR; |
| 1338 | case SystemZ::LCDFR_32: return SystemZ::LCEBR; |
| 1339 | case SystemZ::LPDFR_32: return SystemZ::LPEBR; |
| 1340 | case SystemZ::LNDFR_32: return SystemZ::LNEBR; |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 1341 | // On zEC12 we prefer to use RISBGN. But if there is a chance to |
| 1342 | // actually use the condition code, we may turn it back into RISGB. |
| 1343 | // Note that RISBG is not really a "load-and-test" instruction, |
| 1344 | // but sets the same condition code values, so is OK to use here. |
| 1345 | case SystemZ::RISBGN: return SystemZ::RISBG; |
| 1346 | default: return 0; |
Richard Sandiford | b49a3ab | 2013-08-05 11:03:20 +0000 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 1350 | // Return true if Mask matches the regexp 0*1+0*, given that zero masks |
| 1351 | // have already been filtered out. Store the first set bit in LSB and |
| 1352 | // the number of set bits in Length if so. |
| 1353 | static bool isStringOfOnes(uint64_t Mask, unsigned &LSB, unsigned &Length) { |
| 1354 | unsigned First = findFirstSet(Mask); |
| 1355 | uint64_t Top = (Mask >> First) + 1; |
| 1356 | if ((Top & -Top) == Top) { |
| 1357 | LSB = First; |
| 1358 | Length = findFirstSet(Top); |
| 1359 | return true; |
| 1360 | } |
| 1361 | return false; |
| 1362 | } |
| 1363 | |
| 1364 | bool SystemZInstrInfo::isRxSBGMask(uint64_t Mask, unsigned BitSize, |
| 1365 | unsigned &Start, unsigned &End) const { |
| 1366 | // Reject trivial all-zero masks. |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame] | 1367 | Mask &= allOnes(BitSize); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 1368 | if (Mask == 0) |
| 1369 | return false; |
| 1370 | |
| 1371 | // Handle the 1+0+ or 0+1+0* cases. Start then specifies the index of |
| 1372 | // the msb and End specifies the index of the lsb. |
| 1373 | unsigned LSB, Length; |
| 1374 | if (isStringOfOnes(Mask, LSB, Length)) { |
| 1375 | Start = 63 - (LSB + Length - 1); |
| 1376 | End = 63 - LSB; |
| 1377 | return true; |
| 1378 | } |
| 1379 | |
| 1380 | // Handle the wrap-around 1+0+1+ cases. Start then specifies the msb |
| 1381 | // of the low 1s and End specifies the lsb of the high 1s. |
| 1382 | if (isStringOfOnes(Mask ^ allOnes(BitSize), LSB, Length)) { |
| 1383 | assert(LSB > 0 && "Bottom bit must be set"); |
| 1384 | assert(LSB + Length < BitSize && "Top bit must be set"); |
| 1385 | Start = 63 - (LSB - 1); |
| 1386 | End = 63 - (LSB + Length); |
| 1387 | return true; |
| 1388 | } |
| 1389 | |
| 1390 | return false; |
| 1391 | } |
| 1392 | |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 1393 | unsigned SystemZInstrInfo::getFusedCompare(unsigned Opcode, |
| 1394 | SystemZII::FusedCompareType Type, |
| 1395 | const MachineInstr *MI) const { |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1396 | switch (Opcode) { |
Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 1397 | case SystemZ::CHI: |
Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 1398 | case SystemZ::CGHI: |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 1399 | if (!(MI && isInt<8>(MI->getOperand(1).getImm()))) |
| 1400 | return 0; |
| 1401 | break; |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1402 | case SystemZ::CLFI: |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1403 | case SystemZ::CLGFI: |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 1404 | if (!(MI && isUInt<8>(MI->getOperand(1).getImm()))) |
| 1405 | return 0; |
| 1406 | } |
| 1407 | switch (Type) { |
| 1408 | case SystemZII::CompareAndBranch: |
| 1409 | switch (Opcode) { |
| 1410 | case SystemZ::CR: |
| 1411 | return SystemZ::CRJ; |
| 1412 | case SystemZ::CGR: |
| 1413 | return SystemZ::CGRJ; |
| 1414 | case SystemZ::CHI: |
| 1415 | return SystemZ::CIJ; |
| 1416 | case SystemZ::CGHI: |
| 1417 | return SystemZ::CGIJ; |
| 1418 | case SystemZ::CLR: |
| 1419 | return SystemZ::CLRJ; |
| 1420 | case SystemZ::CLGR: |
| 1421 | return SystemZ::CLGRJ; |
| 1422 | case SystemZ::CLFI: |
| 1423 | return SystemZ::CLIJ; |
| 1424 | case SystemZ::CLGFI: |
| 1425 | return SystemZ::CLGIJ; |
| 1426 | default: |
| 1427 | return 0; |
| 1428 | } |
| 1429 | case SystemZII::CompareAndReturn: |
| 1430 | switch (Opcode) { |
| 1431 | case SystemZ::CR: |
| 1432 | return SystemZ::CRBReturn; |
| 1433 | case SystemZ::CGR: |
| 1434 | return SystemZ::CGRBReturn; |
| 1435 | case SystemZ::CHI: |
| 1436 | return SystemZ::CIBReturn; |
| 1437 | case SystemZ::CGHI: |
| 1438 | return SystemZ::CGIBReturn; |
| 1439 | case SystemZ::CLR: |
| 1440 | return SystemZ::CLRBReturn; |
| 1441 | case SystemZ::CLGR: |
| 1442 | return SystemZ::CLGRBReturn; |
| 1443 | case SystemZ::CLFI: |
| 1444 | return SystemZ::CLIBReturn; |
| 1445 | case SystemZ::CLGFI: |
| 1446 | return SystemZ::CLGIBReturn; |
| 1447 | default: |
| 1448 | return 0; |
| 1449 | } |
Ulrich Weigand | 848a513 | 2016-04-11 12:12:32 +0000 | [diff] [blame] | 1450 | case SystemZII::CompareAndSibcall: |
| 1451 | switch (Opcode) { |
| 1452 | case SystemZ::CR: |
| 1453 | return SystemZ::CRBCall; |
| 1454 | case SystemZ::CGR: |
| 1455 | return SystemZ::CGRBCall; |
| 1456 | case SystemZ::CHI: |
| 1457 | return SystemZ::CIBCall; |
| 1458 | case SystemZ::CGHI: |
| 1459 | return SystemZ::CGIBCall; |
| 1460 | case SystemZ::CLR: |
| 1461 | return SystemZ::CLRBCall; |
| 1462 | case SystemZ::CLGR: |
| 1463 | return SystemZ::CLGRBCall; |
| 1464 | case SystemZ::CLFI: |
| 1465 | return SystemZ::CLIBCall; |
| 1466 | case SystemZ::CLGFI: |
| 1467 | return SystemZ::CLGIBCall; |
| 1468 | default: |
| 1469 | return 0; |
| 1470 | } |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 1471 | case SystemZII::CompareAndTrap: |
| 1472 | switch (Opcode) { |
| 1473 | case SystemZ::CR: |
| 1474 | return SystemZ::CRT; |
| 1475 | case SystemZ::CGR: |
| 1476 | return SystemZ::CGRT; |
| 1477 | case SystemZ::CHI: |
| 1478 | return SystemZ::CIT; |
| 1479 | case SystemZ::CGHI: |
| 1480 | return SystemZ::CGIT; |
| 1481 | case SystemZ::CLR: |
| 1482 | return SystemZ::CLRT; |
| 1483 | case SystemZ::CLGR: |
| 1484 | return SystemZ::CLGRT; |
| 1485 | case SystemZ::CLFI: |
| 1486 | return SystemZ::CLFIT; |
| 1487 | case SystemZ::CLGFI: |
| 1488 | return SystemZ::CLGIT; |
| 1489 | default: |
| 1490 | return 0; |
| 1491 | } |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1492 | } |
Ulrich Weigand | 79391ee | 2016-04-07 16:33:25 +0000 | [diff] [blame] | 1493 | return 0; |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1496 | void SystemZInstrInfo::loadImmediate(MachineBasicBlock &MBB, |
| 1497 | MachineBasicBlock::iterator MBBI, |
| 1498 | unsigned Reg, uint64_t Value) const { |
| 1499 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); |
| 1500 | unsigned Opcode; |
| 1501 | if (isInt<16>(Value)) |
| 1502 | Opcode = SystemZ::LGHI; |
| 1503 | else if (SystemZ::isImmLL(Value)) |
| 1504 | Opcode = SystemZ::LLILL; |
| 1505 | else if (SystemZ::isImmLH(Value)) { |
| 1506 | Opcode = SystemZ::LLILH; |
| 1507 | Value >>= 16; |
| 1508 | } else { |
| 1509 | assert(isInt<32>(Value) && "Huge values not handled yet"); |
| 1510 | Opcode = SystemZ::LGFI; |
| 1511 | } |
| 1512 | BuildMI(MBB, MBBI, DL, get(Opcode), Reg).addImm(Value); |
| 1513 | } |