LLVM API Documentation
00001 //===-- SystemZISelDAGToDAG.cpp - A dag to dag inst selector for SystemZ --===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines an instruction selector for the SystemZ target. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "SystemZTargetMachine.h" 00015 #include "llvm/Analysis/AliasAnalysis.h" 00016 #include "llvm/CodeGen/SelectionDAGISel.h" 00017 #include "llvm/Support/Debug.h" 00018 #include "llvm/Support/raw_ostream.h" 00019 00020 using namespace llvm; 00021 00022 #define DEBUG_TYPE "systemz-isel" 00023 00024 namespace { 00025 // Used to build addressing modes. 00026 struct SystemZAddressingMode { 00027 // The shape of the address. 00028 enum AddrForm { 00029 // base+displacement 00030 FormBD, 00031 00032 // base+displacement+index for load and store operands 00033 FormBDXNormal, 00034 00035 // base+displacement+index for load address operands 00036 FormBDXLA, 00037 00038 // base+displacement+index+ADJDYNALLOC 00039 FormBDXDynAlloc 00040 }; 00041 AddrForm Form; 00042 00043 // The type of displacement. The enum names here correspond directly 00044 // to the definitions in SystemZOperand.td. We could split them into 00045 // flags -- single/pair, 128-bit, etc. -- but it hardly seems worth it. 00046 enum DispRange { 00047 Disp12Only, 00048 Disp12Pair, 00049 Disp20Only, 00050 Disp20Only128, 00051 Disp20Pair 00052 }; 00053 DispRange DR; 00054 00055 // The parts of the address. The address is equivalent to: 00056 // 00057 // Base + Disp + Index + (IncludesDynAlloc ? ADJDYNALLOC : 0) 00058 SDValue Base; 00059 int64_t Disp; 00060 SDValue Index; 00061 bool IncludesDynAlloc; 00062 00063 SystemZAddressingMode(AddrForm form, DispRange dr) 00064 : Form(form), DR(dr), Base(), Disp(0), Index(), 00065 IncludesDynAlloc(false) {} 00066 00067 // True if the address can have an index register. 00068 bool hasIndexField() { return Form != FormBD; } 00069 00070 // True if the address can (and must) include ADJDYNALLOC. 00071 bool isDynAlloc() { return Form == FormBDXDynAlloc; } 00072 00073 void dump() { 00074 errs() << "SystemZAddressingMode " << this << '\n'; 00075 00076 errs() << " Base "; 00077 if (Base.getNode()) 00078 Base.getNode()->dump(); 00079 else 00080 errs() << "null\n"; 00081 00082 if (hasIndexField()) { 00083 errs() << " Index "; 00084 if (Index.getNode()) 00085 Index.getNode()->dump(); 00086 else 00087 errs() << "null\n"; 00088 } 00089 00090 errs() << " Disp " << Disp; 00091 if (IncludesDynAlloc) 00092 errs() << " + ADJDYNALLOC"; 00093 errs() << '\n'; 00094 } 00095 }; 00096 00097 // Return a mask with Count low bits set. 00098 static uint64_t allOnes(unsigned int Count) { 00099 return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1; 00100 } 00101 00102 // Represents operands 2 to 5 of the ROTATE AND ... SELECTED BITS operation 00103 // given by Opcode. The operands are: Input (R2), Start (I3), End (I4) and 00104 // Rotate (I5). The combined operand value is effectively: 00105 // 00106 // (or (rotl Input, Rotate), ~Mask) 00107 // 00108 // for RNSBG and: 00109 // 00110 // (and (rotl Input, Rotate), Mask) 00111 // 00112 // otherwise. The output value has BitSize bits, although Input may be 00113 // narrower (in which case the upper bits are don't care). 00114 struct RxSBGOperands { 00115 RxSBGOperands(unsigned Op, SDValue N) 00116 : Opcode(Op), BitSize(N.getValueType().getSizeInBits()), 00117 Mask(allOnes(BitSize)), Input(N), Start(64 - BitSize), End(63), 00118 Rotate(0) {} 00119 00120 unsigned Opcode; 00121 unsigned BitSize; 00122 uint64_t Mask; 00123 SDValue Input; 00124 unsigned Start; 00125 unsigned End; 00126 unsigned Rotate; 00127 }; 00128 00129 class SystemZDAGToDAGISel : public SelectionDAGISel { 00130 const SystemZTargetLowering &Lowering; 00131 const SystemZSubtarget &Subtarget; 00132 00133 // Used by SystemZOperands.td to create integer constants. 00134 inline SDValue getImm(const SDNode *Node, uint64_t Imm) const { 00135 return CurDAG->getTargetConstant(Imm, Node->getValueType(0)); 00136 } 00137 00138 const SystemZTargetMachine &getTargetMachine() const { 00139 return static_cast<const SystemZTargetMachine &>(TM); 00140 } 00141 00142 const SystemZInstrInfo *getInstrInfo() const { 00143 return getTargetMachine().getSubtargetImpl()->getInstrInfo(); 00144 } 00145 00146 // Try to fold more of the base or index of AM into AM, where IsBase 00147 // selects between the base and index. 00148 bool expandAddress(SystemZAddressingMode &AM, bool IsBase) const; 00149 00150 // Try to describe N in AM, returning true on success. 00151 bool selectAddress(SDValue N, SystemZAddressingMode &AM) const; 00152 00153 // Extract individual target operands from matched address AM. 00154 void getAddressOperands(const SystemZAddressingMode &AM, EVT VT, 00155 SDValue &Base, SDValue &Disp) const; 00156 void getAddressOperands(const SystemZAddressingMode &AM, EVT VT, 00157 SDValue &Base, SDValue &Disp, SDValue &Index) const; 00158 00159 // Try to match Addr as a FormBD address with displacement type DR. 00160 // Return true on success, storing the base and displacement in 00161 // Base and Disp respectively. 00162 bool selectBDAddr(SystemZAddressingMode::DispRange DR, SDValue Addr, 00163 SDValue &Base, SDValue &Disp) const; 00164 00165 // Try to match Addr as a FormBDX address with displacement type DR. 00166 // Return true on success and if the result had no index. Store the 00167 // base and displacement in Base and Disp respectively. 00168 bool selectMVIAddr(SystemZAddressingMode::DispRange DR, SDValue Addr, 00169 SDValue &Base, SDValue &Disp) const; 00170 00171 // Try to match Addr as a FormBDX* address of form Form with 00172 // displacement type DR. Return true on success, storing the base, 00173 // displacement and index in Base, Disp and Index respectively. 00174 bool selectBDXAddr(SystemZAddressingMode::AddrForm Form, 00175 SystemZAddressingMode::DispRange DR, SDValue Addr, 00176 SDValue &Base, SDValue &Disp, SDValue &Index) const; 00177 00178 // PC-relative address matching routines used by SystemZOperands.td. 00179 bool selectPCRelAddress(SDValue Addr, SDValue &Target) const { 00180 if (SystemZISD::isPCREL(Addr.getOpcode())) { 00181 Target = Addr.getOperand(0); 00182 return true; 00183 } 00184 return false; 00185 } 00186 00187 // BD matching routines used by SystemZOperands.td. 00188 bool selectBDAddr12Only(SDValue Addr, SDValue &Base, SDValue &Disp) const { 00189 return selectBDAddr(SystemZAddressingMode::Disp12Only, Addr, Base, Disp); 00190 } 00191 bool selectBDAddr12Pair(SDValue Addr, SDValue &Base, SDValue &Disp) const { 00192 return selectBDAddr(SystemZAddressingMode::Disp12Pair, Addr, Base, Disp); 00193 } 00194 bool selectBDAddr20Only(SDValue Addr, SDValue &Base, SDValue &Disp) const { 00195 return selectBDAddr(SystemZAddressingMode::Disp20Only, Addr, Base, Disp); 00196 } 00197 bool selectBDAddr20Pair(SDValue Addr, SDValue &Base, SDValue &Disp) const { 00198 return selectBDAddr(SystemZAddressingMode::Disp20Pair, Addr, Base, Disp); 00199 } 00200 00201 // MVI matching routines used by SystemZOperands.td. 00202 bool selectMVIAddr12Pair(SDValue Addr, SDValue &Base, SDValue &Disp) const { 00203 return selectMVIAddr(SystemZAddressingMode::Disp12Pair, Addr, Base, Disp); 00204 } 00205 bool selectMVIAddr20Pair(SDValue Addr, SDValue &Base, SDValue &Disp) const { 00206 return selectMVIAddr(SystemZAddressingMode::Disp20Pair, Addr, Base, Disp); 00207 } 00208 00209 // BDX matching routines used by SystemZOperands.td. 00210 bool selectBDXAddr12Only(SDValue Addr, SDValue &Base, SDValue &Disp, 00211 SDValue &Index) const { 00212 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, 00213 SystemZAddressingMode::Disp12Only, 00214 Addr, Base, Disp, Index); 00215 } 00216 bool selectBDXAddr12Pair(SDValue Addr, SDValue &Base, SDValue &Disp, 00217 SDValue &Index) const { 00218 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, 00219 SystemZAddressingMode::Disp12Pair, 00220 Addr, Base, Disp, Index); 00221 } 00222 bool selectDynAlloc12Only(SDValue Addr, SDValue &Base, SDValue &Disp, 00223 SDValue &Index) const { 00224 return selectBDXAddr(SystemZAddressingMode::FormBDXDynAlloc, 00225 SystemZAddressingMode::Disp12Only, 00226 Addr, Base, Disp, Index); 00227 } 00228 bool selectBDXAddr20Only(SDValue Addr, SDValue &Base, SDValue &Disp, 00229 SDValue &Index) const { 00230 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, 00231 SystemZAddressingMode::Disp20Only, 00232 Addr, Base, Disp, Index); 00233 } 00234 bool selectBDXAddr20Only128(SDValue Addr, SDValue &Base, SDValue &Disp, 00235 SDValue &Index) const { 00236 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, 00237 SystemZAddressingMode::Disp20Only128, 00238 Addr, Base, Disp, Index); 00239 } 00240 bool selectBDXAddr20Pair(SDValue Addr, SDValue &Base, SDValue &Disp, 00241 SDValue &Index) const { 00242 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal, 00243 SystemZAddressingMode::Disp20Pair, 00244 Addr, Base, Disp, Index); 00245 } 00246 bool selectLAAddr12Pair(SDValue Addr, SDValue &Base, SDValue &Disp, 00247 SDValue &Index) const { 00248 return selectBDXAddr(SystemZAddressingMode::FormBDXLA, 00249 SystemZAddressingMode::Disp12Pair, 00250 Addr, Base, Disp, Index); 00251 } 00252 bool selectLAAddr20Pair(SDValue Addr, SDValue &Base, SDValue &Disp, 00253 SDValue &Index) const { 00254 return selectBDXAddr(SystemZAddressingMode::FormBDXLA, 00255 SystemZAddressingMode::Disp20Pair, 00256 Addr, Base, Disp, Index); 00257 } 00258 00259 // Check whether (or Op (and X InsertMask)) is effectively an insertion 00260 // of X into bits InsertMask of some Y != Op. Return true if so and 00261 // set Op to that Y. 00262 bool detectOrAndInsertion(SDValue &Op, uint64_t InsertMask) const; 00263 00264 // Try to update RxSBG so that only the bits of RxSBG.Input in Mask are used. 00265 // Return true on success. 00266 bool refineRxSBGMask(RxSBGOperands &RxSBG, uint64_t Mask) const; 00267 00268 // Try to fold some of RxSBG.Input into other fields of RxSBG. 00269 // Return true on success. 00270 bool expandRxSBG(RxSBGOperands &RxSBG) const; 00271 00272 // Return an undefined value of type VT. 00273 SDValue getUNDEF(SDLoc DL, EVT VT) const; 00274 00275 // Convert N to VT, if it isn't already. 00276 SDValue convertTo(SDLoc DL, EVT VT, SDValue N) const; 00277 00278 // Try to implement AND or shift node N using RISBG with the zero flag set. 00279 // Return the selected node on success, otherwise return null. 00280 SDNode *tryRISBGZero(SDNode *N); 00281 00282 // Try to use RISBG or Opcode to implement OR or XOR node N. 00283 // Return the selected node on success, otherwise return null. 00284 SDNode *tryRxSBG(SDNode *N, unsigned Opcode); 00285 00286 // If Op0 is null, then Node is a constant that can be loaded using: 00287 // 00288 // (Opcode UpperVal LowerVal) 00289 // 00290 // If Op0 is nonnull, then Node can be implemented using: 00291 // 00292 // (Opcode (Opcode Op0 UpperVal) LowerVal) 00293 SDNode *splitLargeImmediate(unsigned Opcode, SDNode *Node, SDValue Op0, 00294 uint64_t UpperVal, uint64_t LowerVal); 00295 00296 // Return true if Load and Store are loads and stores of the same size 00297 // and are guaranteed not to overlap. Such operations can be implemented 00298 // using block (SS-format) instructions. 00299 // 00300 // Partial overlap would lead to incorrect code, since the block operations 00301 // are logically bytewise, even though they have a fast path for the 00302 // non-overlapping case. We also need to avoid full overlap (i.e. two 00303 // addresses that might be equal at run time) because although that case 00304 // would be handled correctly, it might be implemented by millicode. 00305 bool canUseBlockOperation(StoreSDNode *Store, LoadSDNode *Load) const; 00306 00307 // N is a (store (load Y), X) pattern. Return true if it can use an MVC 00308 // from Y to X. 00309 bool storeLoadCanUseMVC(SDNode *N) const; 00310 00311 // N is a (store (op (load A[0]), (load A[1])), X) pattern. Return true 00312 // if A[1 - I] == X and if N can use a block operation like NC from A[I] 00313 // to X. 00314 bool storeLoadCanUseBlockBinary(SDNode *N, unsigned I) const; 00315 00316 public: 00317 SystemZDAGToDAGISel(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel) 00318 : SelectionDAGISel(TM, OptLevel), 00319 Lowering(*TM.getSubtargetImpl()->getTargetLowering()), 00320 Subtarget(*TM.getSubtargetImpl()) {} 00321 00322 // Override MachineFunctionPass. 00323 const char *getPassName() const override { 00324 return "SystemZ DAG->DAG Pattern Instruction Selection"; 00325 } 00326 00327 // Override SelectionDAGISel. 00328 SDNode *Select(SDNode *Node) override; 00329 bool SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode, 00330 std::vector<SDValue> &OutOps) override; 00331 00332 // Include the pieces autogenerated from the target description. 00333 #include "SystemZGenDAGISel.inc" 00334 }; 00335 } // end anonymous namespace 00336 00337 FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM, 00338 CodeGenOpt::Level OptLevel) { 00339 return new SystemZDAGToDAGISel(TM, OptLevel); 00340 } 00341 00342 // Return true if Val should be selected as a displacement for an address 00343 // with range DR. Here we're interested in the range of both the instruction 00344 // described by DR and of any pairing instruction. 00345 static bool selectDisp(SystemZAddressingMode::DispRange DR, int64_t Val) { 00346 switch (DR) { 00347 case SystemZAddressingMode::Disp12Only: 00348 return isUInt<12>(Val); 00349 00350 case SystemZAddressingMode::Disp12Pair: 00351 case SystemZAddressingMode::Disp20Only: 00352 case SystemZAddressingMode::Disp20Pair: 00353 return isInt<20>(Val); 00354 00355 case SystemZAddressingMode::Disp20Only128: 00356 return isInt<20>(Val) && isInt<20>(Val + 8); 00357 } 00358 llvm_unreachable("Unhandled displacement range"); 00359 } 00360 00361 // Change the base or index in AM to Value, where IsBase selects 00362 // between the base and index. 00363 static void changeComponent(SystemZAddressingMode &AM, bool IsBase, 00364 SDValue Value) { 00365 if (IsBase) 00366 AM.Base = Value; 00367 else 00368 AM.Index = Value; 00369 } 00370 00371 // The base or index of AM is equivalent to Value + ADJDYNALLOC, 00372 // where IsBase selects between the base and index. Try to fold the 00373 // ADJDYNALLOC into AM. 00374 static bool expandAdjDynAlloc(SystemZAddressingMode &AM, bool IsBase, 00375 SDValue Value) { 00376 if (AM.isDynAlloc() && !AM.IncludesDynAlloc) { 00377 changeComponent(AM, IsBase, Value); 00378 AM.IncludesDynAlloc = true; 00379 return true; 00380 } 00381 return false; 00382 } 00383 00384 // The base of AM is equivalent to Base + Index. Try to use Index as 00385 // the index register. 00386 static bool expandIndex(SystemZAddressingMode &AM, SDValue Base, 00387 SDValue Index) { 00388 if (AM.hasIndexField() && !AM.Index.getNode()) { 00389 AM.Base = Base; 00390 AM.Index = Index; 00391 return true; 00392 } 00393 return false; 00394 } 00395 00396 // The base or index of AM is equivalent to Op0 + Op1, where IsBase selects 00397 // between the base and index. Try to fold Op1 into AM's displacement. 00398 static bool expandDisp(SystemZAddressingMode &AM, bool IsBase, 00399 SDValue Op0, uint64_t Op1) { 00400 // First try adjusting the displacement. 00401 int64_t TestDisp = AM.Disp + Op1; 00402 if (selectDisp(AM.DR, TestDisp)) { 00403 changeComponent(AM, IsBase, Op0); 00404 AM.Disp = TestDisp; 00405 return true; 00406 } 00407 00408 // We could consider forcing the displacement into a register and 00409 // using it as an index, but it would need to be carefully tuned. 00410 return false; 00411 } 00412 00413 bool SystemZDAGToDAGISel::expandAddress(SystemZAddressingMode &AM, 00414 bool IsBase) const { 00415 SDValue N = IsBase ? AM.Base : AM.Index; 00416 unsigned Opcode = N.getOpcode(); 00417 if (Opcode == ISD::TRUNCATE) { 00418 N = N.getOperand(0); 00419 Opcode = N.getOpcode(); 00420 } 00421 if (Opcode == ISD::ADD || CurDAG->isBaseWithConstantOffset(N)) { 00422 SDValue Op0 = N.getOperand(0); 00423 SDValue Op1 = N.getOperand(1); 00424 00425 unsigned Op0Code = Op0->getOpcode(); 00426 unsigned Op1Code = Op1->getOpcode(); 00427 00428 if (Op0Code == SystemZISD::ADJDYNALLOC) 00429 return expandAdjDynAlloc(AM, IsBase, Op1); 00430 if (Op1Code == SystemZISD::ADJDYNALLOC) 00431 return expandAdjDynAlloc(AM, IsBase, Op0); 00432 00433 if (Op0Code == ISD::Constant) 00434 return expandDisp(AM, IsBase, Op1, 00435 cast<ConstantSDNode>(Op0)->getSExtValue()); 00436 if (Op1Code == ISD::Constant) 00437 return expandDisp(AM, IsBase, Op0, 00438 cast<ConstantSDNode>(Op1)->getSExtValue()); 00439 00440 if (IsBase && expandIndex(AM, Op0, Op1)) 00441 return true; 00442 } 00443 if (Opcode == SystemZISD::PCREL_OFFSET) { 00444 SDValue Full = N.getOperand(0); 00445 SDValue Base = N.getOperand(1); 00446 SDValue Anchor = Base.getOperand(0); 00447 uint64_t Offset = (cast<GlobalAddressSDNode>(Full)->getOffset() - 00448 cast<GlobalAddressSDNode>(Anchor)->getOffset()); 00449 return expandDisp(AM, IsBase, Base, Offset); 00450 } 00451 return false; 00452 } 00453 00454 // Return true if an instruction with displacement range DR should be 00455 // used for displacement value Val. selectDisp(DR, Val) must already hold. 00456 static bool isValidDisp(SystemZAddressingMode::DispRange DR, int64_t Val) { 00457 assert(selectDisp(DR, Val) && "Invalid displacement"); 00458 switch (DR) { 00459 case SystemZAddressingMode::Disp12Only: 00460 case SystemZAddressingMode::Disp20Only: 00461 case SystemZAddressingMode::Disp20Only128: 00462 return true; 00463 00464 case SystemZAddressingMode::Disp12Pair: 00465 // Use the other instruction if the displacement is too large. 00466 return isUInt<12>(Val); 00467 00468 case SystemZAddressingMode::Disp20Pair: 00469 // Use the other instruction if the displacement is small enough. 00470 return !isUInt<12>(Val); 00471 } 00472 llvm_unreachable("Unhandled displacement range"); 00473 } 00474 00475 // Return true if Base + Disp + Index should be performed by LA(Y). 00476 static bool shouldUseLA(SDNode *Base, int64_t Disp, SDNode *Index) { 00477 // Don't use LA(Y) for constants. 00478 if (!Base) 00479 return false; 00480 00481 // Always use LA(Y) for frame addresses, since we know that the destination 00482 // register is almost always (perhaps always) going to be different from 00483 // the frame register. 00484 if (Base->getOpcode() == ISD::FrameIndex) 00485 return true; 00486 00487 if (Disp) { 00488 // Always use LA(Y) if there is a base, displacement and index. 00489 if (Index) 00490 return true; 00491 00492 // Always use LA if the displacement is small enough. It should always 00493 // be no worse than AGHI (and better if it avoids a move). 00494 if (isUInt<12>(Disp)) 00495 return true; 00496 00497 // For similar reasons, always use LAY if the constant is too big for AGHI. 00498 // LAY should be no worse than AGFI. 00499 if (!isInt<16>(Disp)) 00500 return true; 00501 } else { 00502 // Don't use LA for plain registers. 00503 if (!Index) 00504 return false; 00505 00506 // Don't use LA for plain addition if the index operand is only used 00507 // once. It should be a natural two-operand addition in that case. 00508 if (Index->hasOneUse()) 00509 return false; 00510 00511 // Prefer addition if the second operation is sign-extended, in the 00512 // hope of using AGF. 00513 unsigned IndexOpcode = Index->getOpcode(); 00514 if (IndexOpcode == ISD::SIGN_EXTEND || 00515 IndexOpcode == ISD::SIGN_EXTEND_INREG) 00516 return false; 00517 } 00518 00519 // Don't use LA for two-operand addition if either operand is only 00520 // used once. The addition instructions are better in that case. 00521 if (Base->hasOneUse()) 00522 return false; 00523 00524 return true; 00525 } 00526 00527 // Return true if Addr is suitable for AM, updating AM if so. 00528 bool SystemZDAGToDAGISel::selectAddress(SDValue Addr, 00529 SystemZAddressingMode &AM) const { 00530 // Start out assuming that the address will need to be loaded separately, 00531 // then try to extend it as much as we can. 00532 AM.Base = Addr; 00533 00534 // First try treating the address as a constant. 00535 if (Addr.getOpcode() == ISD::Constant && 00536 expandDisp(AM, true, SDValue(), 00537 cast<ConstantSDNode>(Addr)->getSExtValue())) 00538 ; 00539 else 00540 // Otherwise try expanding each component. 00541 while (expandAddress(AM, true) || 00542 (AM.Index.getNode() && expandAddress(AM, false))) 00543 continue; 00544 00545 // Reject cases where it isn't profitable to use LA(Y). 00546 if (AM.Form == SystemZAddressingMode::FormBDXLA && 00547 !shouldUseLA(AM.Base.getNode(), AM.Disp, AM.Index.getNode())) 00548 return false; 00549 00550 // Reject cases where the other instruction in a pair should be used. 00551 if (!isValidDisp(AM.DR, AM.Disp)) 00552 return false; 00553 00554 // Make sure that ADJDYNALLOC is included where necessary. 00555 if (AM.isDynAlloc() && !AM.IncludesDynAlloc) 00556 return false; 00557 00558 DEBUG(AM.dump()); 00559 return true; 00560 } 00561 00562 // Insert a node into the DAG at least before Pos. This will reposition 00563 // the node as needed, and will assign it a node ID that is <= Pos's ID. 00564 // Note that this does *not* preserve the uniqueness of node IDs! 00565 // The selection DAG must no longer depend on their uniqueness when this 00566 // function is used. 00567 static void insertDAGNode(SelectionDAG *DAG, SDNode *Pos, SDValue N) { 00568 if (N.getNode()->getNodeId() == -1 || 00569 N.getNode()->getNodeId() > Pos->getNodeId()) { 00570 DAG->RepositionNode(Pos, N.getNode()); 00571 N.getNode()->setNodeId(Pos->getNodeId()); 00572 } 00573 } 00574 00575 void SystemZDAGToDAGISel::getAddressOperands(const SystemZAddressingMode &AM, 00576 EVT VT, SDValue &Base, 00577 SDValue &Disp) const { 00578 Base = AM.Base; 00579 if (!Base.getNode()) 00580 // Register 0 means "no base". This is mostly useful for shifts. 00581 Base = CurDAG->getRegister(0, VT); 00582 else if (Base.getOpcode() == ISD::FrameIndex) { 00583 // Lower a FrameIndex to a TargetFrameIndex. 00584 int64_t FrameIndex = cast<FrameIndexSDNode>(Base)->getIndex(); 00585 Base = CurDAG->getTargetFrameIndex(FrameIndex, VT); 00586 } else if (Base.getValueType() != VT) { 00587 // Truncate values from i64 to i32, for shifts. 00588 assert(VT == MVT::i32 && Base.getValueType() == MVT::i64 && 00589 "Unexpected truncation"); 00590 SDLoc DL(Base); 00591 SDValue Trunc = CurDAG->getNode(ISD::TRUNCATE, DL, VT, Base); 00592 insertDAGNode(CurDAG, Base.getNode(), Trunc); 00593 Base = Trunc; 00594 } 00595 00596 // Lower the displacement to a TargetConstant. 00597 Disp = CurDAG->getTargetConstant(AM.Disp, VT); 00598 } 00599 00600 void SystemZDAGToDAGISel::getAddressOperands(const SystemZAddressingMode &AM, 00601 EVT VT, SDValue &Base, 00602 SDValue &Disp, 00603 SDValue &Index) const { 00604 getAddressOperands(AM, VT, Base, Disp); 00605 00606 Index = AM.Index; 00607 if (!Index.getNode()) 00608 // Register 0 means "no index". 00609 Index = CurDAG->getRegister(0, VT); 00610 } 00611 00612 bool SystemZDAGToDAGISel::selectBDAddr(SystemZAddressingMode::DispRange DR, 00613 SDValue Addr, SDValue &Base, 00614 SDValue &Disp) const { 00615 SystemZAddressingMode AM(SystemZAddressingMode::FormBD, DR); 00616 if (!selectAddress(Addr, AM)) 00617 return false; 00618 00619 getAddressOperands(AM, Addr.getValueType(), Base, Disp); 00620 return true; 00621 } 00622 00623 bool SystemZDAGToDAGISel::selectMVIAddr(SystemZAddressingMode::DispRange DR, 00624 SDValue Addr, SDValue &Base, 00625 SDValue &Disp) const { 00626 SystemZAddressingMode AM(SystemZAddressingMode::FormBDXNormal, DR); 00627 if (!selectAddress(Addr, AM) || AM.Index.getNode()) 00628 return false; 00629 00630 getAddressOperands(AM, Addr.getValueType(), Base, Disp); 00631 return true; 00632 } 00633 00634 bool SystemZDAGToDAGISel::selectBDXAddr(SystemZAddressingMode::AddrForm Form, 00635 SystemZAddressingMode::DispRange DR, 00636 SDValue Addr, SDValue &Base, 00637 SDValue &Disp, SDValue &Index) const { 00638 SystemZAddressingMode AM(Form, DR); 00639 if (!selectAddress(Addr, AM)) 00640 return false; 00641 00642 getAddressOperands(AM, Addr.getValueType(), Base, Disp, Index); 00643 return true; 00644 } 00645 00646 bool SystemZDAGToDAGISel::detectOrAndInsertion(SDValue &Op, 00647 uint64_t InsertMask) const { 00648 // We're only interested in cases where the insertion is into some operand 00649 // of Op, rather than into Op itself. The only useful case is an AND. 00650 if (Op.getOpcode() != ISD::AND) 00651 return false; 00652 00653 // We need a constant mask. 00654 auto *MaskNode = dyn_cast<ConstantSDNode>(Op.getOperand(1).getNode()); 00655 if (!MaskNode) 00656 return false; 00657 00658 // It's not an insertion of Op.getOperand(0) if the two masks overlap. 00659 uint64_t AndMask = MaskNode->getZExtValue(); 00660 if (InsertMask & AndMask) 00661 return false; 00662 00663 // It's only an insertion if all bits are covered or are known to be zero. 00664 // The inner check covers all cases but is more expensive. 00665 uint64_t Used = allOnes(Op.getValueType().getSizeInBits()); 00666 if (Used != (AndMask | InsertMask)) { 00667 APInt KnownZero, KnownOne; 00668 CurDAG->computeKnownBits(Op.getOperand(0), KnownZero, KnownOne); 00669 if (Used != (AndMask | InsertMask | KnownZero.getZExtValue())) 00670 return false; 00671 } 00672 00673 Op = Op.getOperand(0); 00674 return true; 00675 } 00676 00677 bool SystemZDAGToDAGISel::refineRxSBGMask(RxSBGOperands &RxSBG, 00678 uint64_t Mask) const { 00679 const SystemZInstrInfo *TII = getInstrInfo(); 00680 if (RxSBG.Rotate != 0) 00681 Mask = (Mask << RxSBG.Rotate) | (Mask >> (64 - RxSBG.Rotate)); 00682 Mask &= RxSBG.Mask; 00683 if (TII->isRxSBGMask(Mask, RxSBG.BitSize, RxSBG.Start, RxSBG.End)) { 00684 RxSBG.Mask = Mask; 00685 return true; 00686 } 00687 return false; 00688 } 00689 00690 // Return true if any bits of (RxSBG.Input & Mask) are significant. 00691 static bool maskMatters(RxSBGOperands &RxSBG, uint64_t Mask) { 00692 // Rotate the mask in the same way as RxSBG.Input is rotated. 00693 if (RxSBG.Rotate != 0) 00694 Mask = ((Mask << RxSBG.Rotate) | (Mask >> (64 - RxSBG.Rotate))); 00695 return (Mask & RxSBG.Mask) != 0; 00696 } 00697 00698 bool SystemZDAGToDAGISel::expandRxSBG(RxSBGOperands &RxSBG) const { 00699 SDValue N = RxSBG.Input; 00700 unsigned Opcode = N.getOpcode(); 00701 switch (Opcode) { 00702 case ISD::AND: { 00703 if (RxSBG.Opcode == SystemZ::RNSBG) 00704 return false; 00705 00706 auto *MaskNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); 00707 if (!MaskNode) 00708 return false; 00709 00710 SDValue Input = N.getOperand(0); 00711 uint64_t Mask = MaskNode->getZExtValue(); 00712 if (!refineRxSBGMask(RxSBG, Mask)) { 00713 // If some bits of Input are already known zeros, those bits will have 00714 // been removed from the mask. See if adding them back in makes the 00715 // mask suitable. 00716 APInt KnownZero, KnownOne; 00717 CurDAG->computeKnownBits(Input, KnownZero, KnownOne); 00718 Mask |= KnownZero.getZExtValue(); 00719 if (!refineRxSBGMask(RxSBG, Mask)) 00720 return false; 00721 } 00722 RxSBG.Input = Input; 00723 return true; 00724 } 00725 00726 case ISD::OR: { 00727 if (RxSBG.Opcode != SystemZ::RNSBG) 00728 return false; 00729 00730 auto *MaskNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); 00731 if (!MaskNode) 00732 return false; 00733 00734 SDValue Input = N.getOperand(0); 00735 uint64_t Mask = ~MaskNode->getZExtValue(); 00736 if (!refineRxSBGMask(RxSBG, Mask)) { 00737 // If some bits of Input are already known ones, those bits will have 00738 // been removed from the mask. See if adding them back in makes the 00739 // mask suitable. 00740 APInt KnownZero, KnownOne; 00741 CurDAG->computeKnownBits(Input, KnownZero, KnownOne); 00742 Mask &= ~KnownOne.getZExtValue(); 00743 if (!refineRxSBGMask(RxSBG, Mask)) 00744 return false; 00745 } 00746 RxSBG.Input = Input; 00747 return true; 00748 } 00749 00750 case ISD::ROTL: { 00751 // Any 64-bit rotate left can be merged into the RxSBG. 00752 if (RxSBG.BitSize != 64 || N.getValueType() != MVT::i64) 00753 return false; 00754 auto *CountNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); 00755 if (!CountNode) 00756 return false; 00757 00758 RxSBG.Rotate = (RxSBG.Rotate + CountNode->getZExtValue()) & 63; 00759 RxSBG.Input = N.getOperand(0); 00760 return true; 00761 } 00762 00763 case ISD::ANY_EXTEND: 00764 // Bits above the extended operand are don't-care. 00765 RxSBG.Input = N.getOperand(0); 00766 return true; 00767 00768 case ISD::ZERO_EXTEND: 00769 if (RxSBG.Opcode != SystemZ::RNSBG) { 00770 // Restrict the mask to the extended operand. 00771 unsigned InnerBitSize = N.getOperand(0).getValueType().getSizeInBits(); 00772 if (!refineRxSBGMask(RxSBG, allOnes(InnerBitSize))) 00773 return false; 00774 00775 RxSBG.Input = N.getOperand(0); 00776 return true; 00777 } 00778 // Fall through. 00779 00780 case ISD::SIGN_EXTEND: { 00781 // Check that the extension bits are don't-care (i.e. are masked out 00782 // by the final mask). 00783 unsigned InnerBitSize = N.getOperand(0).getValueType().getSizeInBits(); 00784 if (maskMatters(RxSBG, allOnes(RxSBG.BitSize) - allOnes(InnerBitSize))) 00785 return false; 00786 00787 RxSBG.Input = N.getOperand(0); 00788 return true; 00789 } 00790 00791 case ISD::SHL: { 00792 auto *CountNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); 00793 if (!CountNode) 00794 return false; 00795 00796 uint64_t Count = CountNode->getZExtValue(); 00797 unsigned BitSize = N.getValueType().getSizeInBits(); 00798 if (Count < 1 || Count >= BitSize) 00799 return false; 00800 00801 if (RxSBG.Opcode == SystemZ::RNSBG) { 00802 // Treat (shl X, count) as (rotl X, size-count) as long as the bottom 00803 // count bits from RxSBG.Input are ignored. 00804 if (maskMatters(RxSBG, allOnes(Count))) 00805 return false; 00806 } else { 00807 // Treat (shl X, count) as (and (rotl X, count), ~0<<count). 00808 if (!refineRxSBGMask(RxSBG, allOnes(BitSize - Count) << Count)) 00809 return false; 00810 } 00811 00812 RxSBG.Rotate = (RxSBG.Rotate + Count) & 63; 00813 RxSBG.Input = N.getOperand(0); 00814 return true; 00815 } 00816 00817 case ISD::SRL: 00818 case ISD::SRA: { 00819 auto *CountNode = dyn_cast<ConstantSDNode>(N.getOperand(1).getNode()); 00820 if (!CountNode) 00821 return false; 00822 00823 uint64_t Count = CountNode->getZExtValue(); 00824 unsigned BitSize = N.getValueType().getSizeInBits(); 00825 if (Count < 1 || Count >= BitSize) 00826 return false; 00827 00828 if (RxSBG.Opcode == SystemZ::RNSBG || Opcode == ISD::SRA) { 00829 // Treat (srl|sra X, count) as (rotl X, size-count) as long as the top 00830 // count bits from RxSBG.Input are ignored. 00831 if (maskMatters(RxSBG, allOnes(Count) << (BitSize - Count))) 00832 return false; 00833 } else { 00834 // Treat (srl X, count), mask) as (and (rotl X, size-count), ~0>>count), 00835 // which is similar to SLL above. 00836 if (!refineRxSBGMask(RxSBG, allOnes(BitSize - Count))) 00837 return false; 00838 } 00839 00840 RxSBG.Rotate = (RxSBG.Rotate - Count) & 63; 00841 RxSBG.Input = N.getOperand(0); 00842 return true; 00843 } 00844 default: 00845 return false; 00846 } 00847 } 00848 00849 SDValue SystemZDAGToDAGISel::getUNDEF(SDLoc DL, EVT VT) const { 00850 SDNode *N = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, VT); 00851 return SDValue(N, 0); 00852 } 00853 00854 SDValue SystemZDAGToDAGISel::convertTo(SDLoc DL, EVT VT, SDValue N) const { 00855 if (N.getValueType() == MVT::i32 && VT == MVT::i64) 00856 return CurDAG->getTargetInsertSubreg(SystemZ::subreg_l32, 00857 DL, VT, getUNDEF(DL, MVT::i64), N); 00858 if (N.getValueType() == MVT::i64 && VT == MVT::i32) 00859 return CurDAG->getTargetExtractSubreg(SystemZ::subreg_l32, DL, VT, N); 00860 assert(N.getValueType() == VT && "Unexpected value types"); 00861 return N; 00862 } 00863 00864 SDNode *SystemZDAGToDAGISel::tryRISBGZero(SDNode *N) { 00865 EVT VT = N->getValueType(0); 00866 RxSBGOperands RISBG(SystemZ::RISBG, SDValue(N, 0)); 00867 unsigned Count = 0; 00868 while (expandRxSBG(RISBG)) 00869 if (RISBG.Input.getOpcode() != ISD::ANY_EXTEND) 00870 Count += 1; 00871 if (Count == 0) 00872 return nullptr; 00873 if (Count == 1) { 00874 // Prefer to use normal shift instructions over RISBG, since they can handle 00875 // all cases and are sometimes shorter. 00876 if (N->getOpcode() != ISD::AND) 00877 return nullptr; 00878 00879 // Prefer register extensions like LLC over RISBG. Also prefer to start 00880 // out with normal ANDs if one instruction would be enough. We can convert 00881 // these ANDs into an RISBG later if a three-address instruction is useful. 00882 if (VT == MVT::i32 || 00883 RISBG.Mask == 0xff || 00884 RISBG.Mask == 0xffff || 00885 SystemZ::isImmLF(~RISBG.Mask) || 00886 SystemZ::isImmHF(~RISBG.Mask)) { 00887 // Force the new mask into the DAG, since it may include known-one bits. 00888 auto *MaskN = cast<ConstantSDNode>(N->getOperand(1).getNode()); 00889 if (MaskN->getZExtValue() != RISBG.Mask) { 00890 SDValue NewMask = CurDAG->getConstant(RISBG.Mask, VT); 00891 N = CurDAG->UpdateNodeOperands(N, N->getOperand(0), NewMask); 00892 return SelectCode(N); 00893 } 00894 return nullptr; 00895 } 00896 } 00897 00898 unsigned Opcode = SystemZ::RISBG; 00899 EVT OpcodeVT = MVT::i64; 00900 if (VT == MVT::i32 && Subtarget.hasHighWord()) { 00901 Opcode = SystemZ::RISBMux; 00902 OpcodeVT = MVT::i32; 00903 RISBG.Start &= 31; 00904 RISBG.End &= 31; 00905 } 00906 SDValue Ops[5] = { 00907 getUNDEF(SDLoc(N), OpcodeVT), 00908 convertTo(SDLoc(N), OpcodeVT, RISBG.Input), 00909 CurDAG->getTargetConstant(RISBG.Start, MVT::i32), 00910 CurDAG->getTargetConstant(RISBG.End | 128, MVT::i32), 00911 CurDAG->getTargetConstant(RISBG.Rotate, MVT::i32) 00912 }; 00913 N = CurDAG->getMachineNode(Opcode, SDLoc(N), OpcodeVT, Ops); 00914 return convertTo(SDLoc(N), VT, SDValue(N, 0)).getNode(); 00915 } 00916 00917 SDNode *SystemZDAGToDAGISel::tryRxSBG(SDNode *N, unsigned Opcode) { 00918 // Try treating each operand of N as the second operand of the RxSBG 00919 // and see which goes deepest. 00920 RxSBGOperands RxSBG[] = { 00921 RxSBGOperands(Opcode, N->getOperand(0)), 00922 RxSBGOperands(Opcode, N->getOperand(1)) 00923 }; 00924 unsigned Count[] = { 0, 0 }; 00925 for (unsigned I = 0; I < 2; ++I) 00926 while (expandRxSBG(RxSBG[I])) 00927 if (RxSBG[I].Input.getOpcode() != ISD::ANY_EXTEND) 00928 Count[I] += 1; 00929 00930 // Do nothing if neither operand is suitable. 00931 if (Count[0] == 0 && Count[1] == 0) 00932 return nullptr; 00933 00934 // Pick the deepest second operand. 00935 unsigned I = Count[0] > Count[1] ? 0 : 1; 00936 SDValue Op0 = N->getOperand(I ^ 1); 00937 00938 // Prefer IC for character insertions from memory. 00939 if (Opcode == SystemZ::ROSBG && (RxSBG[I].Mask & 0xff) == 0) 00940 if (auto *Load = dyn_cast<LoadSDNode>(Op0.getNode())) 00941 if (Load->getMemoryVT() == MVT::i8) 00942 return nullptr; 00943 00944 // See whether we can avoid an AND in the first operand by converting 00945 // ROSBG to RISBG. 00946 if (Opcode == SystemZ::ROSBG && detectOrAndInsertion(Op0, RxSBG[I].Mask)) 00947 Opcode = SystemZ::RISBG; 00948 00949 EVT VT = N->getValueType(0); 00950 SDValue Ops[5] = { 00951 convertTo(SDLoc(N), MVT::i64, Op0), 00952 convertTo(SDLoc(N), MVT::i64, RxSBG[I].Input), 00953 CurDAG->getTargetConstant(RxSBG[I].Start, MVT::i32), 00954 CurDAG->getTargetConstant(RxSBG[I].End, MVT::i32), 00955 CurDAG->getTargetConstant(RxSBG[I].Rotate, MVT::i32) 00956 }; 00957 N = CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i64, Ops); 00958 return convertTo(SDLoc(N), VT, SDValue(N, 0)).getNode(); 00959 } 00960 00961 SDNode *SystemZDAGToDAGISel::splitLargeImmediate(unsigned Opcode, SDNode *Node, 00962 SDValue Op0, uint64_t UpperVal, 00963 uint64_t LowerVal) { 00964 EVT VT = Node->getValueType(0); 00965 SDLoc DL(Node); 00966 SDValue Upper = CurDAG->getConstant(UpperVal, VT); 00967 if (Op0.getNode()) 00968 Upper = CurDAG->getNode(Opcode, DL, VT, Op0, Upper); 00969 Upper = SDValue(Select(Upper.getNode()), 0); 00970 00971 SDValue Lower = CurDAG->getConstant(LowerVal, VT); 00972 SDValue Or = CurDAG->getNode(Opcode, DL, VT, Upper, Lower); 00973 return Or.getNode(); 00974 } 00975 00976 bool SystemZDAGToDAGISel::canUseBlockOperation(StoreSDNode *Store, 00977 LoadSDNode *Load) const { 00978 // Check that the two memory operands have the same size. 00979 if (Load->getMemoryVT() != Store->getMemoryVT()) 00980 return false; 00981 00982 // Volatility stops an access from being decomposed. 00983 if (Load->isVolatile() || Store->isVolatile()) 00984 return false; 00985 00986 // There's no chance of overlap if the load is invariant. 00987 if (Load->isInvariant()) 00988 return true; 00989 00990 // Otherwise we need to check whether there's an alias. 00991 const Value *V1 = Load->getMemOperand()->getValue(); 00992 const Value *V2 = Store->getMemOperand()->getValue(); 00993 if (!V1 || !V2) 00994 return false; 00995 00996 // Reject equality. 00997 uint64_t Size = Load->getMemoryVT().getStoreSize(); 00998 int64_t End1 = Load->getSrcValueOffset() + Size; 00999 int64_t End2 = Store->getSrcValueOffset() + Size; 01000 if (V1 == V2 && End1 == End2) 01001 return false; 01002 01003 return !AA->alias(AliasAnalysis::Location(V1, End1, Load->getAAInfo()), 01004 AliasAnalysis::Location(V2, End2, Store->getAAInfo())); 01005 } 01006 01007 bool SystemZDAGToDAGISel::storeLoadCanUseMVC(SDNode *N) const { 01008 auto *Store = cast<StoreSDNode>(N); 01009 auto *Load = cast<LoadSDNode>(Store->getValue()); 01010 01011 // Prefer not to use MVC if either address can use ... RELATIVE LONG 01012 // instructions. 01013 uint64_t Size = Load->getMemoryVT().getStoreSize(); 01014 if (Size > 1 && Size <= 8) { 01015 // Prefer LHRL, LRL and LGRL. 01016 if (SystemZISD::isPCREL(Load->getBasePtr().getOpcode())) 01017 return false; 01018 // Prefer STHRL, STRL and STGRL. 01019 if (SystemZISD::isPCREL(Store->getBasePtr().getOpcode())) 01020 return false; 01021 } 01022 01023 return canUseBlockOperation(Store, Load); 01024 } 01025 01026 bool SystemZDAGToDAGISel::storeLoadCanUseBlockBinary(SDNode *N, 01027 unsigned I) const { 01028 auto *StoreA = cast<StoreSDNode>(N); 01029 auto *LoadA = cast<LoadSDNode>(StoreA->getValue().getOperand(1 - I)); 01030 auto *LoadB = cast<LoadSDNode>(StoreA->getValue().getOperand(I)); 01031 return !LoadA->isVolatile() && canUseBlockOperation(StoreA, LoadB); 01032 } 01033 01034 SDNode *SystemZDAGToDAGISel::Select(SDNode *Node) { 01035 // Dump information about the Node being selected 01036 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n"); 01037 01038 // If we have a custom node, we already have selected! 01039 if (Node->isMachineOpcode()) { 01040 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n"); 01041 Node->setNodeId(-1); 01042 return nullptr; 01043 } 01044 01045 unsigned Opcode = Node->getOpcode(); 01046 SDNode *ResNode = nullptr; 01047 switch (Opcode) { 01048 case ISD::OR: 01049 if (Node->getOperand(1).getOpcode() != ISD::Constant) 01050 ResNode = tryRxSBG(Node, SystemZ::ROSBG); 01051 goto or_xor; 01052 01053 case ISD::XOR: 01054 if (Node->getOperand(1).getOpcode() != ISD::Constant) 01055 ResNode = tryRxSBG(Node, SystemZ::RXSBG); 01056 // Fall through. 01057 or_xor: 01058 // If this is a 64-bit operation in which both 32-bit halves are nonzero, 01059 // split the operation into two. 01060 if (!ResNode && Node->getValueType(0) == MVT::i64) 01061 if (auto *Op1 = dyn_cast<ConstantSDNode>(Node->getOperand(1))) { 01062 uint64_t Val = Op1->getZExtValue(); 01063 if (!SystemZ::isImmLF(Val) && !SystemZ::isImmHF(Val)) 01064 Node = splitLargeImmediate(Opcode, Node, Node->getOperand(0), 01065 Val - uint32_t(Val), uint32_t(Val)); 01066 } 01067 break; 01068 01069 case ISD::AND: 01070 if (Node->getOperand(1).getOpcode() != ISD::Constant) 01071 ResNode = tryRxSBG(Node, SystemZ::RNSBG); 01072 // Fall through. 01073 case ISD::ROTL: 01074 case ISD::SHL: 01075 case ISD::SRL: 01076 case ISD::ZERO_EXTEND: 01077 if (!ResNode) 01078 ResNode = tryRISBGZero(Node); 01079 break; 01080 01081 case ISD::Constant: 01082 // If this is a 64-bit constant that is out of the range of LLILF, 01083 // LLIHF and LGFI, split it into two 32-bit pieces. 01084 if (Node->getValueType(0) == MVT::i64) { 01085 uint64_t Val = cast<ConstantSDNode>(Node)->getZExtValue(); 01086 if (!SystemZ::isImmLF(Val) && !SystemZ::isImmHF(Val) && !isInt<32>(Val)) 01087 Node = splitLargeImmediate(ISD::OR, Node, SDValue(), 01088 Val - uint32_t(Val), uint32_t(Val)); 01089 } 01090 break; 01091 01092 case SystemZISD::SELECT_CCMASK: { 01093 SDValue Op0 = Node->getOperand(0); 01094 SDValue Op1 = Node->getOperand(1); 01095 // Prefer to put any load first, so that it can be matched as a 01096 // conditional load. 01097 if (Op1.getOpcode() == ISD::LOAD && Op0.getOpcode() != ISD::LOAD) { 01098 SDValue CCValid = Node->getOperand(2); 01099 SDValue CCMask = Node->getOperand(3); 01100 uint64_t ConstCCValid = 01101 cast<ConstantSDNode>(CCValid.getNode())->getZExtValue(); 01102 uint64_t ConstCCMask = 01103 cast<ConstantSDNode>(CCMask.getNode())->getZExtValue(); 01104 // Invert the condition. 01105 CCMask = CurDAG->getConstant(ConstCCValid ^ ConstCCMask, 01106 CCMask.getValueType()); 01107 SDValue Op4 = Node->getOperand(4); 01108 Node = CurDAG->UpdateNodeOperands(Node, Op1, Op0, CCValid, CCMask, Op4); 01109 } 01110 break; 01111 } 01112 } 01113 01114 // Select the default instruction 01115 if (!ResNode) 01116 ResNode = SelectCode(Node); 01117 01118 DEBUG(errs() << "=> "; 01119 if (ResNode == nullptr || ResNode == Node) 01120 Node->dump(CurDAG); 01121 else 01122 ResNode->dump(CurDAG); 01123 errs() << "\n"; 01124 ); 01125 return ResNode; 01126 } 01127 01128 bool SystemZDAGToDAGISel:: 01129 SelectInlineAsmMemoryOperand(const SDValue &Op, 01130 char ConstraintCode, 01131 std::vector<SDValue> &OutOps) { 01132 assert(ConstraintCode == 'm' && "Unexpected constraint code"); 01133 // Accept addresses with short displacements, which are compatible 01134 // with Q, R, S and T. But keep the index operand for future expansion. 01135 SDValue Base, Disp, Index; 01136 if (!selectBDXAddr(SystemZAddressingMode::FormBD, 01137 SystemZAddressingMode::Disp12Only, 01138 Op, Base, Disp, Index)) 01139 return true; 01140 OutOps.push_back(Base); 01141 OutOps.push_back(Disp); 01142 OutOps.push_back(Index); 01143 return false; 01144 }