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