Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1 | //===-- SystemZISelDAGToDAG.cpp - A dag to dag inst selector for SystemZ --===// |
| 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 defines an instruction selector for the SystemZ target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SystemZTargetMachine.h" |
Richard Sandiford | 9784649 | 2013-07-09 09:46:39 +0000 | [diff] [blame] | 15 | #include "llvm/Analysis/AliasAnalysis.h" |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 17 | #include "llvm/Support/Debug.h" |
| 18 | #include "llvm/Support/raw_ostream.h" |
| 19 | |
| 20 | using namespace llvm; |
| 21 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 22 | #define DEBUG_TYPE "systemz-isel" |
| 23 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | // Used to build addressing modes. |
| 26 | struct SystemZAddressingMode { |
| 27 | // The shape of the address. |
| 28 | enum AddrForm { |
| 29 | // base+displacement |
| 30 | FormBD, |
| 31 | |
| 32 | // base+displacement+index for load and store operands |
| 33 | FormBDXNormal, |
| 34 | |
| 35 | // base+displacement+index for load address operands |
| 36 | FormBDXLA, |
| 37 | |
| 38 | // base+displacement+index+ADJDYNALLOC |
| 39 | FormBDXDynAlloc |
| 40 | }; |
| 41 | AddrForm Form; |
| 42 | |
| 43 | // The type of displacement. The enum names here correspond directly |
| 44 | // to the definitions in SystemZOperand.td. We could split them into |
| 45 | // flags -- single/pair, 128-bit, etc. -- but it hardly seems worth it. |
| 46 | enum DispRange { |
| 47 | Disp12Only, |
| 48 | Disp12Pair, |
| 49 | Disp20Only, |
| 50 | Disp20Only128, |
| 51 | Disp20Pair |
| 52 | }; |
| 53 | DispRange DR; |
| 54 | |
| 55 | // The parts of the address. The address is equivalent to: |
| 56 | // |
| 57 | // Base + Disp + Index + (IncludesDynAlloc ? ADJDYNALLOC : 0) |
| 58 | SDValue Base; |
| 59 | int64_t Disp; |
| 60 | SDValue Index; |
| 61 | bool IncludesDynAlloc; |
| 62 | |
| 63 | SystemZAddressingMode(AddrForm form, DispRange dr) |
| 64 | : Form(form), DR(dr), Base(), Disp(0), Index(), |
| 65 | IncludesDynAlloc(false) {} |
| 66 | |
| 67 | // True if the address can have an index register. |
| 68 | bool hasIndexField() { return Form != FormBD; } |
| 69 | |
| 70 | // True if the address can (and must) include ADJDYNALLOC. |
| 71 | bool isDynAlloc() { return Form == FormBDXDynAlloc; } |
| 72 | |
| 73 | void dump() { |
| 74 | errs() << "SystemZAddressingMode " << this << '\n'; |
| 75 | |
| 76 | errs() << " Base "; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 77 | if (Base.getNode()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 78 | Base.getNode()->dump(); |
| 79 | else |
| 80 | errs() << "null\n"; |
| 81 | |
| 82 | if (hasIndexField()) { |
| 83 | errs() << " Index "; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 84 | if (Index.getNode()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 85 | Index.getNode()->dump(); |
| 86 | else |
| 87 | errs() << "null\n"; |
| 88 | } |
| 89 | |
| 90 | errs() << " Disp " << Disp; |
| 91 | if (IncludesDynAlloc) |
| 92 | errs() << " + ADJDYNALLOC"; |
| 93 | errs() << '\n'; |
| 94 | } |
| 95 | }; |
| 96 | |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 97 | // Return a mask with Count low bits set. |
| 98 | static uint64_t allOnes(unsigned int Count) { |
| 99 | return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1; |
| 100 | } |
| 101 | |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 102 | // Represents operands 2 to 5 of the ROTATE AND ... SELECTED BITS operation |
| 103 | // given by Opcode. The operands are: Input (R2), Start (I3), End (I4) and |
| 104 | // Rotate (I5). The combined operand value is effectively: |
| 105 | // |
| 106 | // (or (rotl Input, Rotate), ~Mask) |
| 107 | // |
| 108 | // for RNSBG and: |
| 109 | // |
| 110 | // (and (rotl Input, Rotate), Mask) |
| 111 | // |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 112 | // otherwise. The output value has BitSize bits, although Input may be |
| 113 | // narrower (in which case the upper bits are don't care). |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 114 | struct RxSBGOperands { |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 115 | RxSBGOperands(unsigned Op, SDValue N) |
| 116 | : Opcode(Op), BitSize(N.getValueType().getSizeInBits()), |
| 117 | Mask(allOnes(BitSize)), Input(N), Start(64 - BitSize), End(63), |
| 118 | Rotate(0) {} |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 119 | |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 120 | unsigned Opcode; |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 121 | unsigned BitSize; |
| 122 | uint64_t Mask; |
| 123 | SDValue Input; |
| 124 | unsigned Start; |
| 125 | unsigned End; |
| 126 | unsigned Rotate; |
| 127 | }; |
| 128 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 129 | class SystemZDAGToDAGISel : public SelectionDAGISel { |
Eric Christopher | a673417 | 2015-01-31 00:06:45 +0000 | [diff] [blame] | 130 | const SystemZSubtarget *Subtarget; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 131 | |
| 132 | // Used by SystemZOperands.td to create integer constants. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 133 | inline SDValue getImm(const SDNode *Node, uint64_t Imm) const { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 134 | return CurDAG->getTargetConstant(Imm, SDLoc(Node), Node->getValueType(0)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 137 | const SystemZTargetMachine &getTargetMachine() const { |
| 138 | return static_cast<const SystemZTargetMachine &>(TM); |
| 139 | } |
| 140 | |
| 141 | const SystemZInstrInfo *getInstrInfo() const { |
Eric Christopher | a673417 | 2015-01-31 00:06:45 +0000 | [diff] [blame] | 142 | return Subtarget->getInstrInfo(); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 145 | // Try to fold more of the base or index of AM into AM, where IsBase |
| 146 | // selects between the base and index. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 147 | bool expandAddress(SystemZAddressingMode &AM, bool IsBase) const; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 148 | |
| 149 | // Try to describe N in AM, returning true on success. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 150 | bool selectAddress(SDValue N, SystemZAddressingMode &AM) const; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 151 | |
| 152 | // Extract individual target operands from matched address AM. |
| 153 | void getAddressOperands(const SystemZAddressingMode &AM, EVT VT, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 154 | SDValue &Base, SDValue &Disp) const; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 155 | void getAddressOperands(const SystemZAddressingMode &AM, EVT VT, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 156 | SDValue &Base, SDValue &Disp, SDValue &Index) const; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 157 | |
| 158 | // Try to match Addr as a FormBD address with displacement type DR. |
| 159 | // Return true on success, storing the base and displacement in |
| 160 | // Base and Disp respectively. |
| 161 | bool selectBDAddr(SystemZAddressingMode::DispRange DR, SDValue Addr, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 162 | SDValue &Base, SDValue &Disp) const; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 163 | |
Richard Sandiford | a481f58 | 2013-08-23 11:18:53 +0000 | [diff] [blame] | 164 | // Try to match Addr as a FormBDX address with displacement type DR. |
| 165 | // Return true on success and if the result had no index. Store the |
| 166 | // base and displacement in Base and Disp respectively. |
| 167 | bool selectMVIAddr(SystemZAddressingMode::DispRange DR, SDValue Addr, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 168 | SDValue &Base, SDValue &Disp) const; |
Richard Sandiford | a481f58 | 2013-08-23 11:18:53 +0000 | [diff] [blame] | 169 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 170 | // Try to match Addr as a FormBDX* address of form Form with |
| 171 | // displacement type DR. Return true on success, storing the base, |
| 172 | // displacement and index in Base, Disp and Index respectively. |
| 173 | bool selectBDXAddr(SystemZAddressingMode::AddrForm Form, |
| 174 | SystemZAddressingMode::DispRange DR, SDValue Addr, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 175 | SDValue &Base, SDValue &Disp, SDValue &Index) const; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 176 | |
| 177 | // PC-relative address matching routines used by SystemZOperands.td. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 178 | bool selectPCRelAddress(SDValue Addr, SDValue &Target) const { |
| 179 | if (SystemZISD::isPCREL(Addr.getOpcode())) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 180 | Target = Addr.getOperand(0); |
| 181 | return true; |
| 182 | } |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | // BD matching routines used by SystemZOperands.td. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 187 | bool selectBDAddr12Only(SDValue Addr, SDValue &Base, SDValue &Disp) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 188 | return selectBDAddr(SystemZAddressingMode::Disp12Only, Addr, Base, Disp); |
| 189 | } |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 190 | bool selectBDAddr12Pair(SDValue Addr, SDValue &Base, SDValue &Disp) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 191 | return selectBDAddr(SystemZAddressingMode::Disp12Pair, Addr, Base, Disp); |
| 192 | } |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 193 | bool selectBDAddr20Only(SDValue Addr, SDValue &Base, SDValue &Disp) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 194 | return selectBDAddr(SystemZAddressingMode::Disp20Only, Addr, Base, Disp); |
| 195 | } |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 196 | bool selectBDAddr20Pair(SDValue Addr, SDValue &Base, SDValue &Disp) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 197 | return selectBDAddr(SystemZAddressingMode::Disp20Pair, Addr, Base, Disp); |
| 198 | } |
| 199 | |
Richard Sandiford | a481f58 | 2013-08-23 11:18:53 +0000 | [diff] [blame] | 200 | // MVI matching routines used by SystemZOperands.td. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 201 | bool selectMVIAddr12Pair(SDValue Addr, SDValue &Base, SDValue &Disp) const { |
Richard Sandiford | a481f58 | 2013-08-23 11:18:53 +0000 | [diff] [blame] | 202 | return selectMVIAddr(SystemZAddressingMode::Disp12Pair, Addr, Base, Disp); |
| 203 | } |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 204 | bool selectMVIAddr20Pair(SDValue Addr, SDValue &Base, SDValue &Disp) const { |
Richard Sandiford | a481f58 | 2013-08-23 11:18:53 +0000 | [diff] [blame] | 205 | return selectMVIAddr(SystemZAddressingMode::Disp20Pair, Addr, Base, Disp); |
| 206 | } |
| 207 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 208 | // BDX matching routines used by SystemZOperands.td. |
| 209 | bool selectBDXAddr12Only(SDValue Addr, SDValue &Base, SDValue &Disp, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 210 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 211 | return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, |
| 212 | SystemZAddressingMode::Disp12Only, |
| 213 | Addr, Base, Disp, Index); |
| 214 | } |
| 215 | bool selectBDXAddr12Pair(SDValue Addr, SDValue &Base, SDValue &Disp, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 216 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 217 | return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, |
| 218 | SystemZAddressingMode::Disp12Pair, |
| 219 | Addr, Base, Disp, Index); |
| 220 | } |
| 221 | bool selectDynAlloc12Only(SDValue Addr, SDValue &Base, SDValue &Disp, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 222 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 223 | return selectBDXAddr(SystemZAddressingMode::FormBDXDynAlloc, |
| 224 | SystemZAddressingMode::Disp12Only, |
| 225 | Addr, Base, Disp, Index); |
| 226 | } |
| 227 | bool selectBDXAddr20Only(SDValue Addr, SDValue &Base, SDValue &Disp, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 228 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 229 | return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, |
| 230 | SystemZAddressingMode::Disp20Only, |
| 231 | Addr, Base, Disp, Index); |
| 232 | } |
| 233 | bool selectBDXAddr20Only128(SDValue Addr, SDValue &Base, SDValue &Disp, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 234 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 235 | return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, |
| 236 | SystemZAddressingMode::Disp20Only128, |
| 237 | Addr, Base, Disp, Index); |
| 238 | } |
| 239 | bool selectBDXAddr20Pair(SDValue Addr, SDValue &Base, SDValue &Disp, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 240 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 241 | return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, |
| 242 | SystemZAddressingMode::Disp20Pair, |
| 243 | Addr, Base, Disp, Index); |
| 244 | } |
| 245 | bool selectLAAddr12Pair(SDValue Addr, SDValue &Base, SDValue &Disp, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 246 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 247 | return selectBDXAddr(SystemZAddressingMode::FormBDXLA, |
| 248 | SystemZAddressingMode::Disp12Pair, |
| 249 | Addr, Base, Disp, Index); |
| 250 | } |
| 251 | bool selectLAAddr20Pair(SDValue Addr, SDValue &Base, SDValue &Disp, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 252 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 253 | return selectBDXAddr(SystemZAddressingMode::FormBDXLA, |
| 254 | SystemZAddressingMode::Disp20Pair, |
| 255 | Addr, Base, Disp, Index); |
| 256 | } |
| 257 | |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame^] | 258 | // Try to match Addr as an address with a base, 12-bit displacement |
| 259 | // and index, where the index is element Elem of a vector. |
| 260 | // Return true on success, storing the base, displacement and vector |
| 261 | // in Base, Disp and Index respectively. |
| 262 | bool selectBDVAddr12Only(SDValue Addr, SDValue Elem, SDValue &Base, |
| 263 | SDValue &Disp, SDValue &Index) const; |
| 264 | |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 265 | // Check whether (or Op (and X InsertMask)) is effectively an insertion |
| 266 | // of X into bits InsertMask of some Y != Op. Return true if so and |
| 267 | // set Op to that Y. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 268 | bool detectOrAndInsertion(SDValue &Op, uint64_t InsertMask) const; |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 269 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 270 | // Try to update RxSBG so that only the bits of RxSBG.Input in Mask are used. |
| 271 | // Return true on success. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 272 | bool refineRxSBGMask(RxSBGOperands &RxSBG, uint64_t Mask) const; |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 273 | |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 274 | // Try to fold some of RxSBG.Input into other fields of RxSBG. |
| 275 | // Return true on success. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 276 | bool expandRxSBG(RxSBGOperands &RxSBG) const; |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 277 | |
Richard Sandiford | 3ad5a15 | 2013-10-01 14:36:20 +0000 | [diff] [blame] | 278 | // Return an undefined value of type VT. |
| 279 | SDValue getUNDEF(SDLoc DL, EVT VT) const; |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 280 | |
| 281 | // Convert N to VT, if it isn't already. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 282 | SDValue convertTo(SDLoc DL, EVT VT, SDValue N) const; |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 283 | |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 284 | // Try to implement AND or shift node N using RISBG with the zero flag set. |
| 285 | // Return the selected node on success, otherwise return null. |
| 286 | SDNode *tryRISBGZero(SDNode *N); |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 287 | |
Richard Sandiford | 7878b85 | 2013-07-18 10:06:15 +0000 | [diff] [blame] | 288 | // Try to use RISBG or Opcode to implement OR or XOR node N. |
| 289 | // Return the selected node on success, otherwise return null. |
| 290 | SDNode *tryRxSBG(SDNode *N, unsigned Opcode); |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 291 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 292 | // If Op0 is null, then Node is a constant that can be loaded using: |
| 293 | // |
| 294 | // (Opcode UpperVal LowerVal) |
| 295 | // |
| 296 | // If Op0 is nonnull, then Node can be implemented using: |
| 297 | // |
| 298 | // (Opcode (Opcode Op0 UpperVal) LowerVal) |
| 299 | SDNode *splitLargeImmediate(unsigned Opcode, SDNode *Node, SDValue Op0, |
| 300 | uint64_t UpperVal, uint64_t LowerVal); |
| 301 | |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame^] | 302 | // Try to use gather instruction Opcode to implement vector insertion N. |
| 303 | SDNode *tryGather(SDNode *N, unsigned Opcode); |
| 304 | |
| 305 | // Try to use scatter instruction Opcode to implement store Store. |
| 306 | SDNode *tryScatter(StoreSDNode *Store, unsigned Opcode); |
| 307 | |
Richard Sandiford | 067817e | 2013-09-27 15:29:20 +0000 | [diff] [blame] | 308 | // Return true if Load and Store are loads and stores of the same size |
| 309 | // and are guaranteed not to overlap. Such operations can be implemented |
| 310 | // using block (SS-format) instructions. |
| 311 | // |
| 312 | // Partial overlap would lead to incorrect code, since the block operations |
| 313 | // are logically bytewise, even though they have a fast path for the |
| 314 | // non-overlapping case. We also need to avoid full overlap (i.e. two |
| 315 | // addresses that might be equal at run time) because although that case |
| 316 | // would be handled correctly, it might be implemented by millicode. |
| 317 | bool canUseBlockOperation(StoreSDNode *Store, LoadSDNode *Load) const; |
| 318 | |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 319 | // N is a (store (load Y), X) pattern. Return true if it can use an MVC |
| 320 | // from Y to X. |
Richard Sandiford | 9784649 | 2013-07-09 09:46:39 +0000 | [diff] [blame] | 321 | bool storeLoadCanUseMVC(SDNode *N) const; |
| 322 | |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 323 | // N is a (store (op (load A[0]), (load A[1])), X) pattern. Return true |
| 324 | // if A[1 - I] == X and if N can use a block operation like NC from A[I] |
| 325 | // to X. |
| 326 | bool storeLoadCanUseBlockBinary(SDNode *N, unsigned I) const; |
| 327 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 328 | public: |
| 329 | SystemZDAGToDAGISel(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel) |
Eric Christopher | a673417 | 2015-01-31 00:06:45 +0000 | [diff] [blame] | 330 | : SelectionDAGISel(TM, OptLevel) {} |
| 331 | |
| 332 | bool runOnMachineFunction(MachineFunction &MF) override { |
| 333 | Subtarget = &MF.getSubtarget<SystemZSubtarget>(); |
| 334 | return SelectionDAGISel::runOnMachineFunction(MF); |
| 335 | } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 336 | |
| 337 | // Override MachineFunctionPass. |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 338 | const char *getPassName() const override { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 339 | return "SystemZ DAG->DAG Pattern Instruction Selection"; |
| 340 | } |
| 341 | |
| 342 | // Override SelectionDAGISel. |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 343 | SDNode *Select(SDNode *Node) override; |
Daniel Sanders | 60f1db0 | 2015-03-13 12:45:09 +0000 | [diff] [blame] | 344 | bool SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID, |
Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 345 | std::vector<SDValue> &OutOps) override; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 346 | |
| 347 | // Include the pieces autogenerated from the target description. |
| 348 | #include "SystemZGenDAGISel.inc" |
| 349 | }; |
| 350 | } // end anonymous namespace |
| 351 | |
| 352 | FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM, |
| 353 | CodeGenOpt::Level OptLevel) { |
| 354 | return new SystemZDAGToDAGISel(TM, OptLevel); |
| 355 | } |
| 356 | |
| 357 | // Return true if Val should be selected as a displacement for an address |
| 358 | // with range DR. Here we're interested in the range of both the instruction |
| 359 | // described by DR and of any pairing instruction. |
| 360 | static bool selectDisp(SystemZAddressingMode::DispRange DR, int64_t Val) { |
| 361 | switch (DR) { |
| 362 | case SystemZAddressingMode::Disp12Only: |
| 363 | return isUInt<12>(Val); |
| 364 | |
| 365 | case SystemZAddressingMode::Disp12Pair: |
| 366 | case SystemZAddressingMode::Disp20Only: |
| 367 | case SystemZAddressingMode::Disp20Pair: |
| 368 | return isInt<20>(Val); |
| 369 | |
| 370 | case SystemZAddressingMode::Disp20Only128: |
| 371 | return isInt<20>(Val) && isInt<20>(Val + 8); |
| 372 | } |
| 373 | llvm_unreachable("Unhandled displacement range"); |
| 374 | } |
| 375 | |
| 376 | // Change the base or index in AM to Value, where IsBase selects |
| 377 | // between the base and index. |
| 378 | static void changeComponent(SystemZAddressingMode &AM, bool IsBase, |
| 379 | SDValue Value) { |
| 380 | if (IsBase) |
| 381 | AM.Base = Value; |
| 382 | else |
| 383 | AM.Index = Value; |
| 384 | } |
| 385 | |
| 386 | // The base or index of AM is equivalent to Value + ADJDYNALLOC, |
| 387 | // where IsBase selects between the base and index. Try to fold the |
| 388 | // ADJDYNALLOC into AM. |
| 389 | static bool expandAdjDynAlloc(SystemZAddressingMode &AM, bool IsBase, |
| 390 | SDValue Value) { |
| 391 | if (AM.isDynAlloc() && !AM.IncludesDynAlloc) { |
| 392 | changeComponent(AM, IsBase, Value); |
| 393 | AM.IncludesDynAlloc = true; |
| 394 | return true; |
| 395 | } |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | // The base of AM is equivalent to Base + Index. Try to use Index as |
| 400 | // the index register. |
| 401 | static bool expandIndex(SystemZAddressingMode &AM, SDValue Base, |
| 402 | SDValue Index) { |
| 403 | if (AM.hasIndexField() && !AM.Index.getNode()) { |
| 404 | AM.Base = Base; |
| 405 | AM.Index = Index; |
| 406 | return true; |
| 407 | } |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | // The base or index of AM is equivalent to Op0 + Op1, where IsBase selects |
| 412 | // between the base and index. Try to fold Op1 into AM's displacement. |
| 413 | static bool expandDisp(SystemZAddressingMode &AM, bool IsBase, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 414 | SDValue Op0, uint64_t Op1) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 415 | // First try adjusting the displacement. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 416 | int64_t TestDisp = AM.Disp + Op1; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 417 | if (selectDisp(AM.DR, TestDisp)) { |
| 418 | changeComponent(AM, IsBase, Op0); |
| 419 | AM.Disp = TestDisp; |
| 420 | return true; |
| 421 | } |
| 422 | |
| 423 | // We could consider forcing the displacement into a register and |
| 424 | // using it as an index, but it would need to be carefully tuned. |
| 425 | return false; |
| 426 | } |
| 427 | |
| 428 | bool SystemZDAGToDAGISel::expandAddress(SystemZAddressingMode &AM, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 429 | bool IsBase) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 430 | SDValue N = IsBase ? AM.Base : AM.Index; |
| 431 | unsigned Opcode = N.getOpcode(); |
| 432 | if (Opcode == ISD::TRUNCATE) { |
| 433 | N = N.getOperand(0); |
| 434 | Opcode = N.getOpcode(); |
| 435 | } |
| 436 | if (Opcode == ISD::ADD || CurDAG->isBaseWithConstantOffset(N)) { |
| 437 | SDValue Op0 = N.getOperand(0); |
| 438 | SDValue Op1 = N.getOperand(1); |
| 439 | |
| 440 | unsigned Op0Code = Op0->getOpcode(); |
| 441 | unsigned Op1Code = Op1->getOpcode(); |
| 442 | |
| 443 | if (Op0Code == SystemZISD::ADJDYNALLOC) |
| 444 | return expandAdjDynAlloc(AM, IsBase, Op1); |
| 445 | if (Op1Code == SystemZISD::ADJDYNALLOC) |
| 446 | return expandAdjDynAlloc(AM, IsBase, Op0); |
| 447 | |
| 448 | if (Op0Code == ISD::Constant) |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 449 | return expandDisp(AM, IsBase, Op1, |
| 450 | cast<ConstantSDNode>(Op0)->getSExtValue()); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 451 | if (Op1Code == ISD::Constant) |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 452 | return expandDisp(AM, IsBase, Op0, |
| 453 | cast<ConstantSDNode>(Op1)->getSExtValue()); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 454 | |
| 455 | if (IsBase && expandIndex(AM, Op0, Op1)) |
| 456 | return true; |
| 457 | } |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 458 | if (Opcode == SystemZISD::PCREL_OFFSET) { |
| 459 | SDValue Full = N.getOperand(0); |
| 460 | SDValue Base = N.getOperand(1); |
| 461 | SDValue Anchor = Base.getOperand(0); |
| 462 | uint64_t Offset = (cast<GlobalAddressSDNode>(Full)->getOffset() - |
| 463 | cast<GlobalAddressSDNode>(Anchor)->getOffset()); |
| 464 | return expandDisp(AM, IsBase, Base, Offset); |
| 465 | } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 466 | return false; |
| 467 | } |
| 468 | |
| 469 | // Return true if an instruction with displacement range DR should be |
| 470 | // used for displacement value Val. selectDisp(DR, Val) must already hold. |
| 471 | static bool isValidDisp(SystemZAddressingMode::DispRange DR, int64_t Val) { |
| 472 | assert(selectDisp(DR, Val) && "Invalid displacement"); |
| 473 | switch (DR) { |
| 474 | case SystemZAddressingMode::Disp12Only: |
| 475 | case SystemZAddressingMode::Disp20Only: |
| 476 | case SystemZAddressingMode::Disp20Only128: |
| 477 | return true; |
| 478 | |
| 479 | case SystemZAddressingMode::Disp12Pair: |
| 480 | // Use the other instruction if the displacement is too large. |
| 481 | return isUInt<12>(Val); |
| 482 | |
| 483 | case SystemZAddressingMode::Disp20Pair: |
| 484 | // Use the other instruction if the displacement is small enough. |
| 485 | return !isUInt<12>(Val); |
| 486 | } |
| 487 | llvm_unreachable("Unhandled displacement range"); |
| 488 | } |
| 489 | |
| 490 | // Return true if Base + Disp + Index should be performed by LA(Y). |
| 491 | static bool shouldUseLA(SDNode *Base, int64_t Disp, SDNode *Index) { |
| 492 | // Don't use LA(Y) for constants. |
| 493 | if (!Base) |
| 494 | return false; |
| 495 | |
| 496 | // Always use LA(Y) for frame addresses, since we know that the destination |
| 497 | // register is almost always (perhaps always) going to be different from |
| 498 | // the frame register. |
| 499 | if (Base->getOpcode() == ISD::FrameIndex) |
| 500 | return true; |
| 501 | |
| 502 | if (Disp) { |
| 503 | // Always use LA(Y) if there is a base, displacement and index. |
| 504 | if (Index) |
| 505 | return true; |
| 506 | |
| 507 | // Always use LA if the displacement is small enough. It should always |
| 508 | // be no worse than AGHI (and better if it avoids a move). |
| 509 | if (isUInt<12>(Disp)) |
| 510 | return true; |
| 511 | |
| 512 | // For similar reasons, always use LAY if the constant is too big for AGHI. |
| 513 | // LAY should be no worse than AGFI. |
| 514 | if (!isInt<16>(Disp)) |
| 515 | return true; |
| 516 | } else { |
| 517 | // Don't use LA for plain registers. |
| 518 | if (!Index) |
| 519 | return false; |
| 520 | |
| 521 | // Don't use LA for plain addition if the index operand is only used |
| 522 | // once. It should be a natural two-operand addition in that case. |
| 523 | if (Index->hasOneUse()) |
| 524 | return false; |
| 525 | |
| 526 | // Prefer addition if the second operation is sign-extended, in the |
| 527 | // hope of using AGF. |
| 528 | unsigned IndexOpcode = Index->getOpcode(); |
| 529 | if (IndexOpcode == ISD::SIGN_EXTEND || |
| 530 | IndexOpcode == ISD::SIGN_EXTEND_INREG) |
| 531 | return false; |
| 532 | } |
| 533 | |
| 534 | // Don't use LA for two-operand addition if either operand is only |
| 535 | // used once. The addition instructions are better in that case. |
| 536 | if (Base->hasOneUse()) |
| 537 | return false; |
| 538 | |
| 539 | return true; |
| 540 | } |
| 541 | |
| 542 | // Return true if Addr is suitable for AM, updating AM if so. |
| 543 | bool SystemZDAGToDAGISel::selectAddress(SDValue Addr, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 544 | SystemZAddressingMode &AM) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 545 | // Start out assuming that the address will need to be loaded separately, |
| 546 | // then try to extend it as much as we can. |
| 547 | AM.Base = Addr; |
| 548 | |
| 549 | // First try treating the address as a constant. |
| 550 | if (Addr.getOpcode() == ISD::Constant && |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 551 | expandDisp(AM, true, SDValue(), |
| 552 | cast<ConstantSDNode>(Addr)->getSExtValue())) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 553 | ; |
| 554 | else |
| 555 | // Otherwise try expanding each component. |
| 556 | while (expandAddress(AM, true) || |
| 557 | (AM.Index.getNode() && expandAddress(AM, false))) |
| 558 | continue; |
| 559 | |
| 560 | // Reject cases where it isn't profitable to use LA(Y). |
| 561 | if (AM.Form == SystemZAddressingMode::FormBDXLA && |
| 562 | !shouldUseLA(AM.Base.getNode(), AM.Disp, AM.Index.getNode())) |
| 563 | return false; |
| 564 | |
| 565 | // Reject cases where the other instruction in a pair should be used. |
| 566 | if (!isValidDisp(AM.DR, AM.Disp)) |
| 567 | return false; |
| 568 | |
| 569 | // Make sure that ADJDYNALLOC is included where necessary. |
| 570 | if (AM.isDynAlloc() && !AM.IncludesDynAlloc) |
| 571 | return false; |
| 572 | |
| 573 | DEBUG(AM.dump()); |
| 574 | return true; |
| 575 | } |
| 576 | |
| 577 | // Insert a node into the DAG at least before Pos. This will reposition |
| 578 | // the node as needed, and will assign it a node ID that is <= Pos's ID. |
| 579 | // Note that this does *not* preserve the uniqueness of node IDs! |
| 580 | // The selection DAG must no longer depend on their uniqueness when this |
| 581 | // function is used. |
| 582 | static void insertDAGNode(SelectionDAG *DAG, SDNode *Pos, SDValue N) { |
| 583 | if (N.getNode()->getNodeId() == -1 || |
| 584 | N.getNode()->getNodeId() > Pos->getNodeId()) { |
| 585 | DAG->RepositionNode(Pos, N.getNode()); |
| 586 | N.getNode()->setNodeId(Pos->getNodeId()); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | void SystemZDAGToDAGISel::getAddressOperands(const SystemZAddressingMode &AM, |
| 591 | EVT VT, SDValue &Base, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 592 | SDValue &Disp) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 593 | Base = AM.Base; |
| 594 | if (!Base.getNode()) |
| 595 | // Register 0 means "no base". This is mostly useful for shifts. |
| 596 | Base = CurDAG->getRegister(0, VT); |
| 597 | else if (Base.getOpcode() == ISD::FrameIndex) { |
| 598 | // Lower a FrameIndex to a TargetFrameIndex. |
| 599 | int64_t FrameIndex = cast<FrameIndexSDNode>(Base)->getIndex(); |
| 600 | Base = CurDAG->getTargetFrameIndex(FrameIndex, VT); |
| 601 | } else if (Base.getValueType() != VT) { |
| 602 | // Truncate values from i64 to i32, for shifts. |
| 603 | assert(VT == MVT::i32 && Base.getValueType() == MVT::i64 && |
| 604 | "Unexpected truncation"); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 605 | SDLoc DL(Base); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 606 | SDValue Trunc = CurDAG->getNode(ISD::TRUNCATE, DL, VT, Base); |
| 607 | insertDAGNode(CurDAG, Base.getNode(), Trunc); |
| 608 | Base = Trunc; |
| 609 | } |
| 610 | |
| 611 | // Lower the displacement to a TargetConstant. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 612 | Disp = CurDAG->getTargetConstant(AM.Disp, SDLoc(Base), VT); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | void SystemZDAGToDAGISel::getAddressOperands(const SystemZAddressingMode &AM, |
| 616 | EVT VT, SDValue &Base, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 617 | SDValue &Disp, |
| 618 | SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 619 | getAddressOperands(AM, VT, Base, Disp); |
| 620 | |
| 621 | Index = AM.Index; |
| 622 | if (!Index.getNode()) |
| 623 | // Register 0 means "no index". |
| 624 | Index = CurDAG->getRegister(0, VT); |
| 625 | } |
| 626 | |
| 627 | bool SystemZDAGToDAGISel::selectBDAddr(SystemZAddressingMode::DispRange DR, |
| 628 | SDValue Addr, SDValue &Base, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 629 | SDValue &Disp) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 630 | SystemZAddressingMode AM(SystemZAddressingMode::FormBD, DR); |
| 631 | if (!selectAddress(Addr, AM)) |
| 632 | return false; |
| 633 | |
| 634 | getAddressOperands(AM, Addr.getValueType(), Base, Disp); |
| 635 | return true; |
| 636 | } |
| 637 | |
Richard Sandiford | a481f58 | 2013-08-23 11:18:53 +0000 | [diff] [blame] | 638 | bool SystemZDAGToDAGISel::selectMVIAddr(SystemZAddressingMode::DispRange DR, |
| 639 | SDValue Addr, SDValue &Base, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 640 | SDValue &Disp) const { |
Richard Sandiford | a481f58 | 2013-08-23 11:18:53 +0000 | [diff] [blame] | 641 | SystemZAddressingMode AM(SystemZAddressingMode::FormBDXNormal, DR); |
| 642 | if (!selectAddress(Addr, AM) || AM.Index.getNode()) |
| 643 | return false; |
| 644 | |
| 645 | getAddressOperands(AM, Addr.getValueType(), Base, Disp); |
| 646 | return true; |
| 647 | } |
| 648 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 649 | bool SystemZDAGToDAGISel::selectBDXAddr(SystemZAddressingMode::AddrForm Form, |
| 650 | SystemZAddressingMode::DispRange DR, |
| 651 | SDValue Addr, SDValue &Base, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 652 | SDValue &Disp, SDValue &Index) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 653 | SystemZAddressingMode AM(Form, DR); |
| 654 | if (!selectAddress(Addr, AM)) |
| 655 | return false; |
| 656 | |
| 657 | getAddressOperands(AM, Addr.getValueType(), Base, Disp, Index); |
| 658 | return true; |
| 659 | } |
| 660 | |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame^] | 661 | bool SystemZDAGToDAGISel::selectBDVAddr12Only(SDValue Addr, SDValue Elem, |
| 662 | SDValue &Base, |
| 663 | SDValue &Disp, |
| 664 | SDValue &Index) const { |
| 665 | SDValue Regs[2]; |
| 666 | if (selectBDXAddr12Only(Addr, Regs[0], Disp, Regs[1]) && |
| 667 | Regs[0].getNode() && Regs[1].getNode()) { |
| 668 | for (unsigned int I = 0; I < 2; ++I) { |
| 669 | Base = Regs[I]; |
| 670 | Index = Regs[1 - I]; |
| 671 | // We can't tell here whether the index vector has the right type |
| 672 | // for the access; the caller needs to do that instead. |
| 673 | if (Index.getOpcode() == ISD::ZERO_EXTEND) |
| 674 | Index = Index.getOperand(0); |
| 675 | if (Index.getOpcode() == ISD::EXTRACT_VECTOR_ELT && |
| 676 | Index.getOperand(1) == Elem) { |
| 677 | Index = Index.getOperand(0); |
| 678 | return true; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | return false; |
| 683 | } |
| 684 | |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 685 | bool SystemZDAGToDAGISel::detectOrAndInsertion(SDValue &Op, |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 686 | uint64_t InsertMask) const { |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 687 | // We're only interested in cases where the insertion is into some operand |
| 688 | // of Op, rather than into Op itself. The only useful case is an AND. |
| 689 | if (Op.getOpcode() != ISD::AND) |
| 690 | return false; |
| 691 | |
| 692 | // We need a constant mask. |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 693 | auto *MaskNode = dyn_cast<ConstantSDNode>(Op.getOperand(1).getNode()); |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 694 | if (!MaskNode) |
| 695 | return false; |
| 696 | |
| 697 | // It's not an insertion of Op.getOperand(0) if the two masks overlap. |
| 698 | uint64_t AndMask = MaskNode->getZExtValue(); |
| 699 | if (InsertMask & AndMask) |
| 700 | return false; |
| 701 | |
| 702 | // It's only an insertion if all bits are covered or are known to be zero. |
| 703 | // The inner check covers all cases but is more expensive. |
| 704 | uint64_t Used = allOnes(Op.getValueType().getSizeInBits()); |
| 705 | if (Used != (AndMask | InsertMask)) { |
| 706 | APInt KnownZero, KnownOne; |
Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 707 | CurDAG->computeKnownBits(Op.getOperand(0), KnownZero, KnownOne); |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 708 | if (Used != (AndMask | InsertMask | KnownZero.getZExtValue())) |
| 709 | return false; |
| 710 | } |
| 711 | |
| 712 | Op = Op.getOperand(0); |
| 713 | return true; |
| 714 | } |
| 715 | |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 716 | bool SystemZDAGToDAGISel::refineRxSBGMask(RxSBGOperands &RxSBG, |
| 717 | uint64_t Mask) const { |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 718 | const SystemZInstrInfo *TII = getInstrInfo(); |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 719 | if (RxSBG.Rotate != 0) |
| 720 | Mask = (Mask << RxSBG.Rotate) | (Mask >> (64 - RxSBG.Rotate)); |
| 721 | Mask &= RxSBG.Mask; |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 722 | if (TII->isRxSBGMask(Mask, RxSBG.BitSize, RxSBG.Start, RxSBG.End)) { |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 723 | RxSBG.Mask = Mask; |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 724 | return true; |
| 725 | } |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 726 | return false; |
| 727 | } |
| 728 | |
Richard Sandiford | dd7dd93 | 2013-11-26 10:53:16 +0000 | [diff] [blame] | 729 | // Return true if any bits of (RxSBG.Input & Mask) are significant. |
| 730 | static bool maskMatters(RxSBGOperands &RxSBG, uint64_t Mask) { |
| 731 | // Rotate the mask in the same way as RxSBG.Input is rotated. |
Richard Sandiford | 297f7d2 | 2013-07-18 10:14:55 +0000 | [diff] [blame] | 732 | if (RxSBG.Rotate != 0) |
Richard Sandiford | dd7dd93 | 2013-11-26 10:53:16 +0000 | [diff] [blame] | 733 | Mask = ((Mask << RxSBG.Rotate) | (Mask >> (64 - RxSBG.Rotate))); |
| 734 | return (Mask & RxSBG.Mask) != 0; |
Richard Sandiford | 297f7d2 | 2013-07-18 10:14:55 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 737 | bool SystemZDAGToDAGISel::expandRxSBG(RxSBGOperands &RxSBG) const { |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 738 | SDValue N = RxSBG.Input; |
Richard Sandiford | 297f7d2 | 2013-07-18 10:14:55 +0000 | [diff] [blame] | 739 | unsigned Opcode = N.getOpcode(); |
| 740 | switch (Opcode) { |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 741 | case ISD::AND: { |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 742 | if (RxSBG.Opcode == SystemZ::RNSBG) |
| 743 | return false; |
| 744 | |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 745 | auto *MaskNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 746 | if (!MaskNode) |
| 747 | return false; |
| 748 | |
| 749 | SDValue Input = N.getOperand(0); |
| 750 | uint64_t Mask = MaskNode->getZExtValue(); |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 751 | if (!refineRxSBGMask(RxSBG, Mask)) { |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 752 | // If some bits of Input are already known zeros, those bits will have |
| 753 | // been removed from the mask. See if adding them back in makes the |
| 754 | // mask suitable. |
| 755 | APInt KnownZero, KnownOne; |
Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 756 | CurDAG->computeKnownBits(Input, KnownZero, KnownOne); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 757 | Mask |= KnownZero.getZExtValue(); |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 758 | if (!refineRxSBGMask(RxSBG, Mask)) |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 759 | return false; |
| 760 | } |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 761 | RxSBG.Input = Input; |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 762 | return true; |
| 763 | } |
| 764 | |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 765 | case ISD::OR: { |
| 766 | if (RxSBG.Opcode != SystemZ::RNSBG) |
| 767 | return false; |
| 768 | |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 769 | auto *MaskNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 770 | if (!MaskNode) |
| 771 | return false; |
| 772 | |
| 773 | SDValue Input = N.getOperand(0); |
| 774 | uint64_t Mask = ~MaskNode->getZExtValue(); |
| 775 | if (!refineRxSBGMask(RxSBG, Mask)) { |
| 776 | // If some bits of Input are already known ones, those bits will have |
| 777 | // been removed from the mask. See if adding them back in makes the |
| 778 | // mask suitable. |
| 779 | APInt KnownZero, KnownOne; |
Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 780 | CurDAG->computeKnownBits(Input, KnownZero, KnownOne); |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 781 | Mask &= ~KnownOne.getZExtValue(); |
| 782 | if (!refineRxSBGMask(RxSBG, Mask)) |
| 783 | return false; |
| 784 | } |
| 785 | RxSBG.Input = Input; |
| 786 | return true; |
| 787 | } |
| 788 | |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 789 | case ISD::ROTL: { |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 790 | // Any 64-bit rotate left can be merged into the RxSBG. |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 791 | if (RxSBG.BitSize != 64 || N.getValueType() != MVT::i64) |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 792 | return false; |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 793 | auto *CountNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 794 | if (!CountNode) |
| 795 | return false; |
| 796 | |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 797 | RxSBG.Rotate = (RxSBG.Rotate + CountNode->getZExtValue()) & 63; |
| 798 | RxSBG.Input = N.getOperand(0); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 799 | return true; |
| 800 | } |
| 801 | |
Richard Sandiford | 220ee49 | 2013-12-20 11:49:48 +0000 | [diff] [blame] | 802 | case ISD::ANY_EXTEND: |
| 803 | // Bits above the extended operand are don't-care. |
| 804 | RxSBG.Input = N.getOperand(0); |
| 805 | return true; |
| 806 | |
Richard Sandiford | 3875cb6 | 2014-01-09 11:28:53 +0000 | [diff] [blame] | 807 | case ISD::ZERO_EXTEND: |
| 808 | if (RxSBG.Opcode != SystemZ::RNSBG) { |
| 809 | // Restrict the mask to the extended operand. |
| 810 | unsigned InnerBitSize = N.getOperand(0).getValueType().getSizeInBits(); |
| 811 | if (!refineRxSBGMask(RxSBG, allOnes(InnerBitSize))) |
| 812 | return false; |
Richard Sandiford | 220ee49 | 2013-12-20 11:49:48 +0000 | [diff] [blame] | 813 | |
Richard Sandiford | 3875cb6 | 2014-01-09 11:28:53 +0000 | [diff] [blame] | 814 | RxSBG.Input = N.getOperand(0); |
| 815 | return true; |
| 816 | } |
| 817 | // Fall through. |
Richard Sandiford | 220ee49 | 2013-12-20 11:49:48 +0000 | [diff] [blame] | 818 | |
| 819 | case ISD::SIGN_EXTEND: { |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 820 | // Check that the extension bits are don't-care (i.e. are masked out |
| 821 | // by the final mask). |
| 822 | unsigned InnerBitSize = N.getOperand(0).getValueType().getSizeInBits(); |
Richard Sandiford | dd7dd93 | 2013-11-26 10:53:16 +0000 | [diff] [blame] | 823 | if (maskMatters(RxSBG, allOnes(RxSBG.BitSize) - allOnes(InnerBitSize))) |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 824 | return false; |
| 825 | |
| 826 | RxSBG.Input = N.getOperand(0); |
| 827 | return true; |
| 828 | } |
| 829 | |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 830 | case ISD::SHL: { |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 831 | auto *CountNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 832 | if (!CountNode) |
| 833 | return false; |
| 834 | |
| 835 | uint64_t Count = CountNode->getZExtValue(); |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 836 | unsigned BitSize = N.getValueType().getSizeInBits(); |
| 837 | if (Count < 1 || Count >= BitSize) |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 838 | return false; |
| 839 | |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 840 | if (RxSBG.Opcode == SystemZ::RNSBG) { |
| 841 | // Treat (shl X, count) as (rotl X, size-count) as long as the bottom |
| 842 | // count bits from RxSBG.Input are ignored. |
Richard Sandiford | dd7dd93 | 2013-11-26 10:53:16 +0000 | [diff] [blame] | 843 | if (maskMatters(RxSBG, allOnes(Count))) |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 844 | return false; |
| 845 | } else { |
| 846 | // Treat (shl X, count) as (and (rotl X, count), ~0<<count). |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 847 | if (!refineRxSBGMask(RxSBG, allOnes(BitSize - Count) << Count)) |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 848 | return false; |
| 849 | } |
| 850 | |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 851 | RxSBG.Rotate = (RxSBG.Rotate + Count) & 63; |
| 852 | RxSBG.Input = N.getOperand(0); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 853 | return true; |
| 854 | } |
| 855 | |
Richard Sandiford | 297f7d2 | 2013-07-18 10:14:55 +0000 | [diff] [blame] | 856 | case ISD::SRL: |
| 857 | case ISD::SRA: { |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 858 | auto *CountNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 859 | if (!CountNode) |
| 860 | return false; |
| 861 | |
| 862 | uint64_t Count = CountNode->getZExtValue(); |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 863 | unsigned BitSize = N.getValueType().getSizeInBits(); |
| 864 | if (Count < 1 || Count >= BitSize) |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 865 | return false; |
| 866 | |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 867 | if (RxSBG.Opcode == SystemZ::RNSBG || Opcode == ISD::SRA) { |
| 868 | // Treat (srl|sra X, count) as (rotl X, size-count) as long as the top |
| 869 | // count bits from RxSBG.Input are ignored. |
Richard Sandiford | dd7dd93 | 2013-11-26 10:53:16 +0000 | [diff] [blame] | 870 | if (maskMatters(RxSBG, allOnes(Count) << (BitSize - Count))) |
Richard Sandiford | 297f7d2 | 2013-07-18 10:14:55 +0000 | [diff] [blame] | 871 | return false; |
| 872 | } else { |
| 873 | // Treat (srl X, count), mask) as (and (rotl X, size-count), ~0>>count), |
| 874 | // which is similar to SLL above. |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 875 | if (!refineRxSBGMask(RxSBG, allOnes(BitSize - Count))) |
Richard Sandiford | 297f7d2 | 2013-07-18 10:14:55 +0000 | [diff] [blame] | 876 | return false; |
| 877 | } |
| 878 | |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 879 | RxSBG.Rotate = (RxSBG.Rotate - Count) & 63; |
| 880 | RxSBG.Input = N.getOperand(0); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 881 | return true; |
| 882 | } |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 883 | default: |
| 884 | return false; |
| 885 | } |
| 886 | } |
| 887 | |
Richard Sandiford | 3ad5a15 | 2013-10-01 14:36:20 +0000 | [diff] [blame] | 888 | SDValue SystemZDAGToDAGISel::getUNDEF(SDLoc DL, EVT VT) const { |
| 889 | SDNode *N = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, VT); |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 890 | return SDValue(N, 0); |
| 891 | } |
| 892 | |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 893 | SDValue SystemZDAGToDAGISel::convertTo(SDLoc DL, EVT VT, SDValue N) const { |
Richard Sandiford | d816320 | 2013-09-13 09:12:44 +0000 | [diff] [blame] | 894 | if (N.getValueType() == MVT::i32 && VT == MVT::i64) |
Richard Sandiford | 87a4436 | 2013-09-30 10:28:35 +0000 | [diff] [blame] | 895 | return CurDAG->getTargetInsertSubreg(SystemZ::subreg_l32, |
Richard Sandiford | 3ad5a15 | 2013-10-01 14:36:20 +0000 | [diff] [blame] | 896 | DL, VT, getUNDEF(DL, MVT::i64), N); |
Richard Sandiford | d816320 | 2013-09-13 09:12:44 +0000 | [diff] [blame] | 897 | if (N.getValueType() == MVT::i64 && VT == MVT::i32) |
Richard Sandiford | 87a4436 | 2013-09-30 10:28:35 +0000 | [diff] [blame] | 898 | return CurDAG->getTargetExtractSubreg(SystemZ::subreg_l32, DL, VT, N); |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 899 | assert(N.getValueType() == VT && "Unexpected value types"); |
| 900 | return N; |
| 901 | } |
| 902 | |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 903 | SDNode *SystemZDAGToDAGISel::tryRISBGZero(SDNode *N) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 904 | SDLoc DL(N); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 905 | EVT VT = N->getValueType(0); |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 906 | RxSBGOperands RISBG(SystemZ::RISBG, SDValue(N, 0)); |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 907 | unsigned Count = 0; |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 908 | while (expandRxSBG(RISBG)) |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 909 | if (RISBG.Input.getOpcode() != ISD::ANY_EXTEND) |
| 910 | Count += 1; |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 911 | if (Count == 0) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 912 | return nullptr; |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 913 | if (Count == 1) { |
| 914 | // Prefer to use normal shift instructions over RISBG, since they can handle |
| 915 | // all cases and are sometimes shorter. |
| 916 | if (N->getOpcode() != ISD::AND) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 917 | return nullptr; |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 918 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 919 | // Prefer register extensions like LLC over RISBG. Also prefer to start |
| 920 | // out with normal ANDs if one instruction would be enough. We can convert |
| 921 | // these ANDs into an RISBG later if a three-address instruction is useful. |
| 922 | if (VT == MVT::i32 || |
| 923 | RISBG.Mask == 0xff || |
| 924 | RISBG.Mask == 0xffff || |
| 925 | SystemZ::isImmLF(~RISBG.Mask) || |
| 926 | SystemZ::isImmHF(~RISBG.Mask)) { |
| 927 | // Force the new mask into the DAG, since it may include known-one bits. |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 928 | auto *MaskN = cast<ConstantSDNode>(N->getOperand(1).getNode()); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 929 | if (MaskN->getZExtValue() != RISBG.Mask) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 930 | SDValue NewMask = CurDAG->getConstant(RISBG.Mask, DL, VT); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 931 | N = CurDAG->UpdateNodeOperands(N, N->getOperand(0), NewMask); |
| 932 | return SelectCode(N); |
| 933 | } |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 934 | return nullptr; |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 935 | } |
| 936 | } |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 937 | |
Richard Sandiford | 3ad5a15 | 2013-10-01 14:36:20 +0000 | [diff] [blame] | 938 | unsigned Opcode = SystemZ::RISBG; |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 939 | // Prefer RISBGN if available, since it does not clobber CC. |
| 940 | if (Subtarget->hasMiscellaneousExtensions()) |
| 941 | Opcode = SystemZ::RISBGN; |
Richard Sandiford | 3ad5a15 | 2013-10-01 14:36:20 +0000 | [diff] [blame] | 942 | EVT OpcodeVT = MVT::i64; |
Eric Christopher | a673417 | 2015-01-31 00:06:45 +0000 | [diff] [blame] | 943 | if (VT == MVT::i32 && Subtarget->hasHighWord()) { |
Richard Sandiford | 3ad5a15 | 2013-10-01 14:36:20 +0000 | [diff] [blame] | 944 | Opcode = SystemZ::RISBMux; |
| 945 | OpcodeVT = MVT::i32; |
| 946 | RISBG.Start &= 31; |
| 947 | RISBG.End &= 31; |
| 948 | } |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 949 | SDValue Ops[5] = { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 950 | getUNDEF(DL, OpcodeVT), |
| 951 | convertTo(DL, OpcodeVT, RISBG.Input), |
| 952 | CurDAG->getTargetConstant(RISBG.Start, DL, MVT::i32), |
| 953 | CurDAG->getTargetConstant(RISBG.End | 128, DL, MVT::i32), |
| 954 | CurDAG->getTargetConstant(RISBG.Rotate, DL, MVT::i32) |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 955 | }; |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 956 | N = CurDAG->getMachineNode(Opcode, DL, OpcodeVT, Ops); |
| 957 | return convertTo(DL, VT, SDValue(N, 0)).getNode(); |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Richard Sandiford | 7878b85 | 2013-07-18 10:06:15 +0000 | [diff] [blame] | 960 | SDNode *SystemZDAGToDAGISel::tryRxSBG(SDNode *N, unsigned Opcode) { |
| 961 | // Try treating each operand of N as the second operand of the RxSBG |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 962 | // and see which goes deepest. |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 963 | RxSBGOperands RxSBG[] = { |
| 964 | RxSBGOperands(Opcode, N->getOperand(0)), |
| 965 | RxSBGOperands(Opcode, N->getOperand(1)) |
| 966 | }; |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 967 | unsigned Count[] = { 0, 0 }; |
| 968 | for (unsigned I = 0; I < 2; ++I) |
Richard Sandiford | 5cbac96 | 2013-07-18 09:45:08 +0000 | [diff] [blame] | 969 | while (expandRxSBG(RxSBG[I])) |
Richard Sandiford | 3e38297 | 2013-10-16 13:35:13 +0000 | [diff] [blame] | 970 | if (RxSBG[I].Input.getOpcode() != ISD::ANY_EXTEND) |
| 971 | Count[I] += 1; |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 972 | |
| 973 | // Do nothing if neither operand is suitable. |
| 974 | if (Count[0] == 0 && Count[1] == 0) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 975 | return nullptr; |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 976 | |
| 977 | // Pick the deepest second operand. |
| 978 | unsigned I = Count[0] > Count[1] ? 0 : 1; |
| 979 | SDValue Op0 = N->getOperand(I ^ 1); |
| 980 | |
| 981 | // Prefer IC for character insertions from memory. |
Richard Sandiford | 7878b85 | 2013-07-18 10:06:15 +0000 | [diff] [blame] | 982 | if (Opcode == SystemZ::ROSBG && (RxSBG[I].Mask & 0xff) == 0) |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 983 | if (auto *Load = dyn_cast<LoadSDNode>(Op0.getNode())) |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 984 | if (Load->getMemoryVT() == MVT::i8) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 985 | return nullptr; |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 986 | |
| 987 | // See whether we can avoid an AND in the first operand by converting |
| 988 | // ROSBG to RISBG. |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 989 | if (Opcode == SystemZ::ROSBG && detectOrAndInsertion(Op0, RxSBG[I].Mask)) { |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 990 | Opcode = SystemZ::RISBG; |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 991 | // Prefer RISBGN if available, since it does not clobber CC. |
| 992 | if (Subtarget->hasMiscellaneousExtensions()) |
| 993 | Opcode = SystemZ::RISBGN; |
| 994 | } |
| 995 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 996 | SDLoc DL(N); |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 997 | EVT VT = N->getValueType(0); |
| 998 | SDValue Ops[5] = { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 999 | convertTo(DL, MVT::i64, Op0), |
| 1000 | convertTo(DL, MVT::i64, RxSBG[I].Input), |
| 1001 | CurDAG->getTargetConstant(RxSBG[I].Start, DL, MVT::i32), |
| 1002 | CurDAG->getTargetConstant(RxSBG[I].End, DL, MVT::i32), |
| 1003 | CurDAG->getTargetConstant(RxSBG[I].Rotate, DL, MVT::i32) |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 1004 | }; |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1005 | N = CurDAG->getMachineNode(Opcode, DL, MVT::i64, Ops); |
| 1006 | return convertTo(DL, VT, SDValue(N, 0)).getNode(); |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1009 | SDNode *SystemZDAGToDAGISel::splitLargeImmediate(unsigned Opcode, SDNode *Node, |
| 1010 | SDValue Op0, uint64_t UpperVal, |
| 1011 | uint64_t LowerVal) { |
| 1012 | EVT VT = Node->getValueType(0); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1013 | SDLoc DL(Node); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1014 | SDValue Upper = CurDAG->getConstant(UpperVal, DL, VT); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1015 | if (Op0.getNode()) |
| 1016 | Upper = CurDAG->getNode(Opcode, DL, VT, Op0, Upper); |
| 1017 | Upper = SDValue(Select(Upper.getNode()), 0); |
| 1018 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1019 | SDValue Lower = CurDAG->getConstant(LowerVal, DL, VT); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1020 | SDValue Or = CurDAG->getNode(Opcode, DL, VT, Upper, Lower); |
| 1021 | return Or.getNode(); |
| 1022 | } |
| 1023 | |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame^] | 1024 | SDNode *SystemZDAGToDAGISel::tryGather(SDNode *N, unsigned Opcode) { |
| 1025 | SDValue ElemV = N->getOperand(2); |
| 1026 | auto *ElemN = dyn_cast<ConstantSDNode>(ElemV); |
| 1027 | if (!ElemN) |
| 1028 | return 0; |
| 1029 | |
| 1030 | unsigned Elem = ElemN->getZExtValue(); |
| 1031 | EVT VT = N->getValueType(0); |
| 1032 | if (Elem >= VT.getVectorNumElements()) |
| 1033 | return 0; |
| 1034 | |
| 1035 | auto *Load = dyn_cast<LoadSDNode>(N->getOperand(1)); |
| 1036 | if (!Load || !Load->hasOneUse()) |
| 1037 | return 0; |
| 1038 | if (Load->getMemoryVT().getSizeInBits() != |
| 1039 | Load->getValueType(0).getSizeInBits()) |
| 1040 | return 0; |
| 1041 | |
| 1042 | SDValue Base, Disp, Index; |
| 1043 | if (!selectBDVAddr12Only(Load->getBasePtr(), ElemV, Base, Disp, Index) || |
| 1044 | Index.getValueType() != VT.changeVectorElementTypeToInteger()) |
| 1045 | return 0; |
| 1046 | |
| 1047 | SDLoc DL(Load); |
| 1048 | SDValue Ops[] = { |
| 1049 | N->getOperand(0), Base, Disp, Index, |
| 1050 | CurDAG->getTargetConstant(Elem, DL, MVT::i32), Load->getChain() |
| 1051 | }; |
| 1052 | SDNode *Res = CurDAG->getMachineNode(Opcode, DL, VT, MVT::Other, Ops); |
| 1053 | ReplaceUses(SDValue(Load, 1), SDValue(Res, 1)); |
| 1054 | return Res; |
| 1055 | } |
| 1056 | |
| 1057 | SDNode *SystemZDAGToDAGISel::tryScatter(StoreSDNode *Store, unsigned Opcode) { |
| 1058 | SDValue Value = Store->getValue(); |
| 1059 | if (Value.getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 1060 | return 0; |
| 1061 | if (Store->getMemoryVT().getSizeInBits() != |
| 1062 | Value.getValueType().getSizeInBits()) |
| 1063 | return 0; |
| 1064 | |
| 1065 | SDValue ElemV = Value.getOperand(1); |
| 1066 | auto *ElemN = dyn_cast<ConstantSDNode>(ElemV); |
| 1067 | if (!ElemN) |
| 1068 | return 0; |
| 1069 | |
| 1070 | SDValue Vec = Value.getOperand(0); |
| 1071 | EVT VT = Vec.getValueType(); |
| 1072 | unsigned Elem = ElemN->getZExtValue(); |
| 1073 | if (Elem >= VT.getVectorNumElements()) |
| 1074 | return 0; |
| 1075 | |
| 1076 | SDValue Base, Disp, Index; |
| 1077 | if (!selectBDVAddr12Only(Store->getBasePtr(), ElemV, Base, Disp, Index) || |
| 1078 | Index.getValueType() != VT.changeVectorElementTypeToInteger()) |
| 1079 | return 0; |
| 1080 | |
| 1081 | SDLoc DL(Store); |
| 1082 | SDValue Ops[] = { |
| 1083 | Vec, Base, Disp, Index, CurDAG->getTargetConstant(Elem, DL, MVT::i32), |
| 1084 | Store->getChain() |
| 1085 | }; |
| 1086 | return CurDAG->getMachineNode(Opcode, DL, MVT::Other, Ops); |
| 1087 | } |
| 1088 | |
Richard Sandiford | 067817e | 2013-09-27 15:29:20 +0000 | [diff] [blame] | 1089 | bool SystemZDAGToDAGISel::canUseBlockOperation(StoreSDNode *Store, |
| 1090 | LoadSDNode *Load) const { |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 1091 | // Check that the two memory operands have the same size. |
| 1092 | if (Load->getMemoryVT() != Store->getMemoryVT()) |
Richard Sandiford | 9784649 | 2013-07-09 09:46:39 +0000 | [diff] [blame] | 1093 | return false; |
| 1094 | |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 1095 | // Volatility stops an access from being decomposed. |
| 1096 | if (Load->isVolatile() || Store->isVolatile()) |
| 1097 | return false; |
Richard Sandiford | 9784649 | 2013-07-09 09:46:39 +0000 | [diff] [blame] | 1098 | |
| 1099 | // There's no chance of overlap if the load is invariant. |
| 1100 | if (Load->isInvariant()) |
| 1101 | return true; |
| 1102 | |
Richard Sandiford | 9784649 | 2013-07-09 09:46:39 +0000 | [diff] [blame] | 1103 | // Otherwise we need to check whether there's an alias. |
Nick Lewycky | aad475b | 2014-04-15 07:22:52 +0000 | [diff] [blame] | 1104 | const Value *V1 = Load->getMemOperand()->getValue(); |
| 1105 | const Value *V2 = Store->getMemOperand()->getValue(); |
Richard Sandiford | 9784649 | 2013-07-09 09:46:39 +0000 | [diff] [blame] | 1106 | if (!V1 || !V2) |
| 1107 | return false; |
| 1108 | |
Richard Sandiford | 067817e | 2013-09-27 15:29:20 +0000 | [diff] [blame] | 1109 | // Reject equality. |
| 1110 | uint64_t Size = Load->getMemoryVT().getStoreSize(); |
Richard Sandiford | 9784649 | 2013-07-09 09:46:39 +0000 | [diff] [blame] | 1111 | int64_t End1 = Load->getSrcValueOffset() + Size; |
| 1112 | int64_t End2 = Store->getSrcValueOffset() + Size; |
Richard Sandiford | 067817e | 2013-09-27 15:29:20 +0000 | [diff] [blame] | 1113 | if (V1 == V2 && End1 == End2) |
| 1114 | return false; |
| 1115 | |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 1116 | return !AA->alias(AliasAnalysis::Location(V1, End1, Load->getAAInfo()), |
| 1117 | AliasAnalysis::Location(V2, End2, Store->getAAInfo())); |
Richard Sandiford | 9784649 | 2013-07-09 09:46:39 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 1120 | bool SystemZDAGToDAGISel::storeLoadCanUseMVC(SDNode *N) const { |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 1121 | auto *Store = cast<StoreSDNode>(N); |
| 1122 | auto *Load = cast<LoadSDNode>(Store->getValue()); |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 1123 | |
| 1124 | // Prefer not to use MVC if either address can use ... RELATIVE LONG |
| 1125 | // instructions. |
| 1126 | uint64_t Size = Load->getMemoryVT().getStoreSize(); |
| 1127 | if (Size > 1 && Size <= 8) { |
| 1128 | // Prefer LHRL, LRL and LGRL. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 1129 | if (SystemZISD::isPCREL(Load->getBasePtr().getOpcode())) |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 1130 | return false; |
| 1131 | // Prefer STHRL, STRL and STGRL. |
Richard Sandiford | 54b3691 | 2013-09-27 15:14:04 +0000 | [diff] [blame] | 1132 | if (SystemZISD::isPCREL(Store->getBasePtr().getOpcode())) |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 1133 | return false; |
| 1134 | } |
| 1135 | |
Richard Sandiford | 067817e | 2013-09-27 15:29:20 +0000 | [diff] [blame] | 1136 | return canUseBlockOperation(Store, Load); |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | bool SystemZDAGToDAGISel::storeLoadCanUseBlockBinary(SDNode *N, |
| 1140 | unsigned I) const { |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 1141 | auto *StoreA = cast<StoreSDNode>(N); |
| 1142 | auto *LoadA = cast<LoadSDNode>(StoreA->getValue().getOperand(1 - I)); |
| 1143 | auto *LoadB = cast<LoadSDNode>(StoreA->getValue().getOperand(I)); |
Richard Sandiford | 067817e | 2013-09-27 15:29:20 +0000 | [diff] [blame] | 1144 | return !LoadA->isVolatile() && canUseBlockOperation(StoreA, LoadB); |
Richard Sandiford | 178273a | 2013-09-05 10:36:45 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1147 | SDNode *SystemZDAGToDAGISel::Select(SDNode *Node) { |
| 1148 | // Dump information about the Node being selected |
| 1149 | DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n"); |
| 1150 | |
| 1151 | // If we have a custom node, we already have selected! |
| 1152 | if (Node->isMachineOpcode()) { |
| 1153 | DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n"); |
Tim Northover | 31d093c | 2013-09-22 08:21:56 +0000 | [diff] [blame] | 1154 | Node->setNodeId(-1); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1155 | return nullptr; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | unsigned Opcode = Node->getOpcode(); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1159 | SDNode *ResNode = nullptr; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1160 | switch (Opcode) { |
| 1161 | case ISD::OR: |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 1162 | if (Node->getOperand(1).getOpcode() != ISD::Constant) |
Richard Sandiford | 7878b85 | 2013-07-18 10:06:15 +0000 | [diff] [blame] | 1163 | ResNode = tryRxSBG(Node, SystemZ::ROSBG); |
| 1164 | goto or_xor; |
| 1165 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1166 | case ISD::XOR: |
Richard Sandiford | 7878b85 | 2013-07-18 10:06:15 +0000 | [diff] [blame] | 1167 | if (Node->getOperand(1).getOpcode() != ISD::Constant) |
| 1168 | ResNode = tryRxSBG(Node, SystemZ::RXSBG); |
| 1169 | // Fall through. |
| 1170 | or_xor: |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1171 | // If this is a 64-bit operation in which both 32-bit halves are nonzero, |
| 1172 | // split the operation into two. |
Richard Sandiford | 885140c | 2013-07-16 11:55:57 +0000 | [diff] [blame] | 1173 | if (!ResNode && Node->getValueType(0) == MVT::i64) |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 1174 | if (auto *Op1 = dyn_cast<ConstantSDNode>(Node->getOperand(1))) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1175 | uint64_t Val = Op1->getZExtValue(); |
| 1176 | if (!SystemZ::isImmLF(Val) && !SystemZ::isImmHF(Val)) |
| 1177 | Node = splitLargeImmediate(Opcode, Node, Node->getOperand(0), |
| 1178 | Val - uint32_t(Val), uint32_t(Val)); |
| 1179 | } |
| 1180 | break; |
| 1181 | |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 1182 | case ISD::AND: |
Richard Sandiford | 5109321 | 2013-07-18 10:40:35 +0000 | [diff] [blame] | 1183 | if (Node->getOperand(1).getOpcode() != ISD::Constant) |
| 1184 | ResNode = tryRxSBG(Node, SystemZ::RNSBG); |
| 1185 | // Fall through. |
Richard Sandiford | 82ec87d | 2013-07-16 11:02:24 +0000 | [diff] [blame] | 1186 | case ISD::ROTL: |
| 1187 | case ISD::SHL: |
| 1188 | case ISD::SRL: |
Richard Sandiford | 220ee49 | 2013-12-20 11:49:48 +0000 | [diff] [blame] | 1189 | case ISD::ZERO_EXTEND: |
Richard Sandiford | 7878b85 | 2013-07-18 10:06:15 +0000 | [diff] [blame] | 1190 | if (!ResNode) |
| 1191 | ResNode = tryRISBGZero(Node); |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 1192 | break; |
| 1193 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1194 | case ISD::Constant: |
| 1195 | // If this is a 64-bit constant that is out of the range of LLILF, |
| 1196 | // LLIHF and LGFI, split it into two 32-bit pieces. |
| 1197 | if (Node->getValueType(0) == MVT::i64) { |
| 1198 | uint64_t Val = cast<ConstantSDNode>(Node)->getZExtValue(); |
| 1199 | if (!SystemZ::isImmLF(Val) && !SystemZ::isImmHF(Val) && !isInt<32>(Val)) |
| 1200 | Node = splitLargeImmediate(ISD::OR, Node, SDValue(), |
| 1201 | Val - uint32_t(Val), uint32_t(Val)); |
| 1202 | } |
| 1203 | break; |
| 1204 | |
Richard Sandiford | ee83438 | 2013-07-31 12:38:08 +0000 | [diff] [blame] | 1205 | case SystemZISD::SELECT_CCMASK: { |
| 1206 | SDValue Op0 = Node->getOperand(0); |
| 1207 | SDValue Op1 = Node->getOperand(1); |
| 1208 | // Prefer to put any load first, so that it can be matched as a |
| 1209 | // conditional load. |
| 1210 | if (Op1.getOpcode() == ISD::LOAD && Op0.getOpcode() != ISD::LOAD) { |
| 1211 | SDValue CCValid = Node->getOperand(2); |
| 1212 | SDValue CCMask = Node->getOperand(3); |
| 1213 | uint64_t ConstCCValid = |
| 1214 | cast<ConstantSDNode>(CCValid.getNode())->getZExtValue(); |
| 1215 | uint64_t ConstCCMask = |
| 1216 | cast<ConstantSDNode>(CCMask.getNode())->getZExtValue(); |
| 1217 | // Invert the condition. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1218 | CCMask = CurDAG->getConstant(ConstCCValid ^ ConstCCMask, SDLoc(Node), |
Richard Sandiford | ee83438 | 2013-07-31 12:38:08 +0000 | [diff] [blame] | 1219 | CCMask.getValueType()); |
| 1220 | SDValue Op4 = Node->getOperand(4); |
| 1221 | Node = CurDAG->UpdateNodeOperands(Node, Op1, Op0, CCValid, CCMask, Op4); |
| 1222 | } |
| 1223 | break; |
| 1224 | } |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame^] | 1225 | |
| 1226 | case ISD::INSERT_VECTOR_ELT: { |
| 1227 | EVT VT = Node->getValueType(0); |
| 1228 | unsigned ElemBitSize = VT.getVectorElementType().getSizeInBits(); |
| 1229 | if (ElemBitSize == 32) |
| 1230 | ResNode = tryGather(Node, SystemZ::VGEF); |
| 1231 | else if (ElemBitSize == 64) |
| 1232 | ResNode = tryGather(Node, SystemZ::VGEG); |
| 1233 | break; |
| 1234 | } |
| 1235 | |
| 1236 | case ISD::STORE: { |
| 1237 | auto *Store = cast<StoreSDNode>(Node); |
| 1238 | unsigned ElemBitSize = Store->getValue().getValueType().getSizeInBits(); |
| 1239 | if (ElemBitSize == 32) |
| 1240 | ResNode = tryScatter(Store, SystemZ::VSCEF); |
| 1241 | else if (ElemBitSize == 64) |
| 1242 | ResNode = tryScatter(Store, SystemZ::VSCEG); |
| 1243 | break; |
| 1244 | } |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | // Select the default instruction |
Richard Sandiford | 84f54a3 | 2013-07-11 08:59:12 +0000 | [diff] [blame] | 1248 | if (!ResNode) |
| 1249 | ResNode = SelectCode(Node); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1250 | |
| 1251 | DEBUG(errs() << "=> "; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1252 | if (ResNode == nullptr || ResNode == Node) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1253 | Node->dump(CurDAG); |
| 1254 | else |
| 1255 | ResNode->dump(CurDAG); |
| 1256 | errs() << "\n"; |
| 1257 | ); |
| 1258 | return ResNode; |
| 1259 | } |
| 1260 | |
| 1261 | bool SystemZDAGToDAGISel:: |
| 1262 | SelectInlineAsmMemoryOperand(const SDValue &Op, |
Daniel Sanders | 60f1db0 | 2015-03-13 12:45:09 +0000 | [diff] [blame] | 1263 | unsigned ConstraintID, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1264 | std::vector<SDValue> &OutOps) { |
Daniel Sanders | 2eeace2 | 2015-03-17 16:16:14 +0000 | [diff] [blame] | 1265 | switch(ConstraintID) { |
| 1266 | default: |
| 1267 | llvm_unreachable("Unexpected asm memory constraint"); |
| 1268 | case InlineAsm::Constraint_i: |
| 1269 | case InlineAsm::Constraint_m: |
| 1270 | case InlineAsm::Constraint_Q: |
| 1271 | case InlineAsm::Constraint_R: |
| 1272 | case InlineAsm::Constraint_S: |
| 1273 | case InlineAsm::Constraint_T: |
| 1274 | // Accept addresses with short displacements, which are compatible |
| 1275 | // with Q, R, S and T. But keep the index operand for future expansion. |
| 1276 | SDValue Base, Disp, Index; |
| 1277 | if (selectBDXAddr(SystemZAddressingMode::FormBD, |
| 1278 | SystemZAddressingMode::Disp12Only, |
| 1279 | Op, Base, Disp, Index)) { |
| 1280 | OutOps.push_back(Base); |
| 1281 | OutOps.push_back(Disp); |
| 1282 | OutOps.push_back(Index); |
| 1283 | return false; |
| 1284 | } |
| 1285 | break; |
| 1286 | } |
| 1287 | return true; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1288 | } |