b9eecbe16f3f864029998a5846d7ac425d332f9b
[oota-llvm.git] / lib / Target / PowerPC / PPCISelDAGToDAG.cpp
1 //===-- PPCISelDAGToDAG.cpp - PPC --pattern matching inst selector --------===//
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 a pattern matching instruction selector for PowerPC,
11 // converting from a legalized dag to a PPC dag.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #define DEBUG_TYPE "ppc-codegen"
16 #include "PPC.h"
17 #include "MCTargetDesc/PPCPredicates.h"
18 #include "PPCTargetMachine.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineInstrBuilder.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.h"
22 #include "llvm/CodeGen/SelectionDAG.h"
23 #include "llvm/CodeGen/SelectionDAGISel.h"
24 #include "llvm/IR/Constants.h"
25 #include "llvm/IR/Function.h"
26 #include "llvm/IR/GlobalAlias.h"
27 #include "llvm/IR/GlobalValue.h"
28 #include "llvm/IR/GlobalVariable.h"
29 #include "llvm/IR/Intrinsics.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/Debug.h"
32 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Support/MathExtras.h"
34 #include "llvm/Support/raw_ostream.h"
35 #include "llvm/Target/TargetOptions.h"
36 using namespace llvm;
37
38 // FIXME: Remove this once the bug has been fixed!
39 cl::opt<bool> ANDIGlueBug("expose-ppc-andi-glue-bug",
40 cl::desc("expose the ANDI glue bug on PPC"), cl::Hidden);
41
42 namespace llvm {
43   void initializePPCDAGToDAGISelPass(PassRegistry&);
44 }
45
46 namespace {
47   //===--------------------------------------------------------------------===//
48   /// PPCDAGToDAGISel - PPC specific code to select PPC machine
49   /// instructions for SelectionDAG operations.
50   ///
51   class PPCDAGToDAGISel : public SelectionDAGISel {
52     const PPCTargetMachine &TM;
53     const PPCTargetLowering &PPCLowering;
54     const PPCSubtarget &PPCSubTarget;
55     unsigned GlobalBaseReg;
56   public:
57     explicit PPCDAGToDAGISel(PPCTargetMachine &tm)
58       : SelectionDAGISel(tm), TM(tm),
59         PPCLowering(*TM.getTargetLowering()),
60         PPCSubTarget(*TM.getSubtargetImpl()) {
61       initializePPCDAGToDAGISelPass(*PassRegistry::getPassRegistry());
62     }
63
64     virtual bool runOnMachineFunction(MachineFunction &MF) {
65       // Make sure we re-emit a set of the global base reg if necessary
66       GlobalBaseReg = 0;
67       SelectionDAGISel::runOnMachineFunction(MF);
68
69       if (!PPCSubTarget.isSVR4ABI())
70         InsertVRSaveCode(MF);
71
72       return true;
73     }
74
75     virtual void PostprocessISelDAG();
76
77     /// getI32Imm - Return a target constant with the specified value, of type
78     /// i32.
79     inline SDValue getI32Imm(unsigned Imm) {
80       return CurDAG->getTargetConstant(Imm, MVT::i32);
81     }
82
83     /// getI64Imm - Return a target constant with the specified value, of type
84     /// i64.
85     inline SDValue getI64Imm(uint64_t Imm) {
86       return CurDAG->getTargetConstant(Imm, MVT::i64);
87     }
88
89     /// getSmallIPtrImm - Return a target constant of pointer type.
90     inline SDValue getSmallIPtrImm(unsigned Imm) {
91       return CurDAG->getTargetConstant(Imm, PPCLowering.getPointerTy());
92     }
93
94     /// isRunOfOnes - Returns true iff Val consists of one contiguous run of 1s
95     /// with any number of 0s on either side.  The 1s are allowed to wrap from
96     /// LSB to MSB, so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs.
97     /// 0x0F0F0000 is not, since all 1s are not contiguous.
98     static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME);
99
100
101     /// isRotateAndMask - Returns true if Mask and Shift can be folded into a
102     /// rotate and mask opcode and mask operation.
103     static bool isRotateAndMask(SDNode *N, unsigned Mask, bool isShiftMask,
104                                 unsigned &SH, unsigned &MB, unsigned &ME);
105
106     /// getGlobalBaseReg - insert code into the entry mbb to materialize the PIC
107     /// base register.  Return the virtual register that holds this value.
108     SDNode *getGlobalBaseReg();
109
110     // Select - Convert the specified operand from a target-independent to a
111     // target-specific node if it hasn't already been changed.
112     SDNode *Select(SDNode *N);
113
114     SDNode *SelectBitfieldInsert(SDNode *N);
115
116     /// SelectCC - Select a comparison of the specified values with the
117     /// specified condition code, returning the CR# of the expression.
118     SDValue SelectCC(SDValue LHS, SDValue RHS, ISD::CondCode CC, SDLoc dl);
119
120     /// SelectAddrImm - Returns true if the address N can be represented by
121     /// a base register plus a signed 16-bit displacement [r+imm].
122     bool SelectAddrImm(SDValue N, SDValue &Disp,
123                        SDValue &Base) {
124       return PPCLowering.SelectAddressRegImm(N, Disp, Base, *CurDAG, false);
125     }
126
127     /// SelectAddrImmOffs - Return true if the operand is valid for a preinc
128     /// immediate field.  Note that the operand at this point is already the
129     /// result of a prior SelectAddressRegImm call.
130     bool SelectAddrImmOffs(SDValue N, SDValue &Out) const {
131       if (N.getOpcode() == ISD::TargetConstant ||
132           N.getOpcode() == ISD::TargetGlobalAddress) {
133         Out = N;
134         return true;
135       }
136
137       return false;
138     }
139
140     /// SelectAddrIdx - Given the specified addressed, check to see if it can be
141     /// represented as an indexed [r+r] operation.  Returns false if it can
142     /// be represented by [r+imm], which are preferred.
143     bool SelectAddrIdx(SDValue N, SDValue &Base, SDValue &Index) {
144       return PPCLowering.SelectAddressRegReg(N, Base, Index, *CurDAG);
145     }
146
147     /// SelectAddrIdxOnly - Given the specified addressed, force it to be
148     /// represented as an indexed [r+r] operation.
149     bool SelectAddrIdxOnly(SDValue N, SDValue &Base, SDValue &Index) {
150       return PPCLowering.SelectAddressRegRegOnly(N, Base, Index, *CurDAG);
151     }
152
153     /// SelectAddrImmX4 - Returns true if the address N can be represented by
154     /// a base register plus a signed 16-bit displacement that is a multiple of 4.
155     /// Suitable for use by STD and friends.
156     bool SelectAddrImmX4(SDValue N, SDValue &Disp, SDValue &Base) {
157       return PPCLowering.SelectAddressRegImm(N, Disp, Base, *CurDAG, true);
158     }
159
160     // Select an address into a single register.
161     bool SelectAddr(SDValue N, SDValue &Base) {
162       Base = N;
163       return true;
164     }
165
166     /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
167     /// inline asm expressions.  It is always correct to compute the value into
168     /// a register.  The case of adding a (possibly relocatable) constant to a
169     /// register can be improved, but it is wrong to substitute Reg+Reg for
170     /// Reg in an asm, because the load or store opcode would have to change.
171    virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
172                                               char ConstraintCode,
173                                               std::vector<SDValue> &OutOps) {
174       OutOps.push_back(Op);
175       return false;
176     }
177
178     void InsertVRSaveCode(MachineFunction &MF);
179
180     virtual const char *getPassName() const {
181       return "PowerPC DAG->DAG Pattern Instruction Selection";
182     }
183
184 // Include the pieces autogenerated from the target description.
185 #include "PPCGenDAGISel.inc"
186
187 private:
188     SDNode *SelectSETCC(SDNode *N);
189
190     void PeepholePPC64();
191     void PeepholdCROps();
192   };
193 }
194
195 /// InsertVRSaveCode - Once the entire function has been instruction selected,
196 /// all virtual registers are created and all machine instructions are built,
197 /// check to see if we need to save/restore VRSAVE.  If so, do it.
198 void PPCDAGToDAGISel::InsertVRSaveCode(MachineFunction &Fn) {
199   // Check to see if this function uses vector registers, which means we have to
200   // save and restore the VRSAVE register and update it with the regs we use.
201   //
202   // In this case, there will be virtual registers of vector type created
203   // by the scheduler.  Detect them now.
204   bool HasVectorVReg = false;
205   for (unsigned i = 0, e = RegInfo->getNumVirtRegs(); i != e; ++i) {
206     unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
207     if (RegInfo->getRegClass(Reg) == &PPC::VRRCRegClass) {
208       HasVectorVReg = true;
209       break;
210     }
211   }
212   if (!HasVectorVReg) return;  // nothing to do.
213
214   // If we have a vector register, we want to emit code into the entry and exit
215   // blocks to save and restore the VRSAVE register.  We do this here (instead
216   // of marking all vector instructions as clobbering VRSAVE) for two reasons:
217   //
218   // 1. This (trivially) reduces the load on the register allocator, by not
219   //    having to represent the live range of the VRSAVE register.
220   // 2. This (more significantly) allows us to create a temporary virtual
221   //    register to hold the saved VRSAVE value, allowing this temporary to be
222   //    register allocated, instead of forcing it to be spilled to the stack.
223
224   // Create two vregs - one to hold the VRSAVE register that is live-in to the
225   // function and one for the value after having bits or'd into it.
226   unsigned InVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
227   unsigned UpdatedVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
228
229   const TargetInstrInfo &TII = *TM.getInstrInfo();
230   MachineBasicBlock &EntryBB = *Fn.begin();
231   DebugLoc dl;
232   // Emit the following code into the entry block:
233   // InVRSAVE = MFVRSAVE
234   // UpdatedVRSAVE = UPDATE_VRSAVE InVRSAVE
235   // MTVRSAVE UpdatedVRSAVE
236   MachineBasicBlock::iterator IP = EntryBB.begin();  // Insert Point
237   BuildMI(EntryBB, IP, dl, TII.get(PPC::MFVRSAVE), InVRSAVE);
238   BuildMI(EntryBB, IP, dl, TII.get(PPC::UPDATE_VRSAVE),
239           UpdatedVRSAVE).addReg(InVRSAVE);
240   BuildMI(EntryBB, IP, dl, TII.get(PPC::MTVRSAVE)).addReg(UpdatedVRSAVE);
241
242   // Find all return blocks, outputting a restore in each epilog.
243   for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
244     if (!BB->empty() && BB->back().isReturn()) {
245       IP = BB->end(); --IP;
246
247       // Skip over all terminator instructions, which are part of the return
248       // sequence.
249       MachineBasicBlock::iterator I2 = IP;
250       while (I2 != BB->begin() && (--I2)->isTerminator())
251         IP = I2;
252
253       // Emit: MTVRSAVE InVRSave
254       BuildMI(*BB, IP, dl, TII.get(PPC::MTVRSAVE)).addReg(InVRSAVE);
255     }
256   }
257 }
258
259
260 /// getGlobalBaseReg - Output the instructions required to put the
261 /// base address to use for accessing globals into a register.
262 ///
263 SDNode *PPCDAGToDAGISel::getGlobalBaseReg() {
264   if (!GlobalBaseReg) {
265     const TargetInstrInfo &TII = *TM.getInstrInfo();
266     // Insert the set of GlobalBaseReg into the first MBB of the function
267     MachineBasicBlock &FirstMBB = MF->front();
268     MachineBasicBlock::iterator MBBI = FirstMBB.begin();
269     DebugLoc dl;
270
271     if (PPCLowering.getPointerTy() == MVT::i32) {
272       GlobalBaseReg = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
273       BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MovePCtoLR));
274       BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MFLR), GlobalBaseReg);
275     } else {
276       GlobalBaseReg = RegInfo->createVirtualRegister(&PPC::G8RCRegClass);
277       BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MovePCtoLR8));
278       BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MFLR8), GlobalBaseReg);
279     }
280   }
281   return CurDAG->getRegister(GlobalBaseReg,
282                              PPCLowering.getPointerTy()).getNode();
283 }
284
285 /// isIntS16Immediate - This method tests to see if the node is either a 32-bit
286 /// or 64-bit immediate, and if the value can be accurately represented as a
287 /// sign extension from a 16-bit value.  If so, this returns true and the
288 /// immediate.
289 static bool isIntS16Immediate(SDNode *N, short &Imm) {
290   if (N->getOpcode() != ISD::Constant)
291     return false;
292
293   Imm = (short)cast<ConstantSDNode>(N)->getZExtValue();
294   if (N->getValueType(0) == MVT::i32)
295     return Imm == (int32_t)cast<ConstantSDNode>(N)->getZExtValue();
296   else
297     return Imm == (int64_t)cast<ConstantSDNode>(N)->getZExtValue();
298 }
299
300 static bool isIntS16Immediate(SDValue Op, short &Imm) {
301   return isIntS16Immediate(Op.getNode(), Imm);
302 }
303
304
305 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
306 /// operand. If so Imm will receive the 32-bit value.
307 static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
308   if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
309     Imm = cast<ConstantSDNode>(N)->getZExtValue();
310     return true;
311   }
312   return false;
313 }
314
315 /// isInt64Immediate - This method tests to see if the node is a 64-bit constant
316 /// operand.  If so Imm will receive the 64-bit value.
317 static bool isInt64Immediate(SDNode *N, uint64_t &Imm) {
318   if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i64) {
319     Imm = cast<ConstantSDNode>(N)->getZExtValue();
320     return true;
321   }
322   return false;
323 }
324
325 // isInt32Immediate - This method tests to see if a constant operand.
326 // If so Imm will receive the 32 bit value.
327 static bool isInt32Immediate(SDValue N, unsigned &Imm) {
328   return isInt32Immediate(N.getNode(), Imm);
329 }
330
331
332 // isOpcWithIntImmediate - This method tests to see if the node is a specific
333 // opcode and that it has a immediate integer right operand.
334 // If so Imm will receive the 32 bit value.
335 static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
336   return N->getOpcode() == Opc
337          && isInt32Immediate(N->getOperand(1).getNode(), Imm);
338 }
339
340 bool PPCDAGToDAGISel::isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) {
341   if (!Val)
342     return false;
343
344   if (isShiftedMask_32(Val)) {
345     // look for the first non-zero bit
346     MB = countLeadingZeros(Val);
347     // look for the first zero bit after the run of ones
348     ME = countLeadingZeros((Val - 1) ^ Val);
349     return true;
350   } else {
351     Val = ~Val; // invert mask
352     if (isShiftedMask_32(Val)) {
353       // effectively look for the first zero bit
354       ME = countLeadingZeros(Val) - 1;
355       // effectively look for the first one bit after the run of zeros
356       MB = countLeadingZeros((Val - 1) ^ Val) + 1;
357       return true;
358     }
359   }
360   // no run present
361   return false;
362 }
363
364 bool PPCDAGToDAGISel::isRotateAndMask(SDNode *N, unsigned Mask,
365                                       bool isShiftMask, unsigned &SH,
366                                       unsigned &MB, unsigned &ME) {
367   // Don't even go down this path for i64, since different logic will be
368   // necessary for rldicl/rldicr/rldimi.
369   if (N->getValueType(0) != MVT::i32)
370     return false;
371
372   unsigned Shift  = 32;
373   unsigned Indeterminant = ~0;  // bit mask marking indeterminant results
374   unsigned Opcode = N->getOpcode();
375   if (N->getNumOperands() != 2 ||
376       !isInt32Immediate(N->getOperand(1).getNode(), Shift) || (Shift > 31))
377     return false;
378
379   if (Opcode == ISD::SHL) {
380     // apply shift left to mask if it comes first
381     if (isShiftMask) Mask = Mask << Shift;
382     // determine which bits are made indeterminant by shift
383     Indeterminant = ~(0xFFFFFFFFu << Shift);
384   } else if (Opcode == ISD::SRL) {
385     // apply shift right to mask if it comes first
386     if (isShiftMask) Mask = Mask >> Shift;
387     // determine which bits are made indeterminant by shift
388     Indeterminant = ~(0xFFFFFFFFu >> Shift);
389     // adjust for the left rotate
390     Shift = 32 - Shift;
391   } else if (Opcode == ISD::ROTL) {
392     Indeterminant = 0;
393   } else {
394     return false;
395   }
396
397   // if the mask doesn't intersect any Indeterminant bits
398   if (Mask && !(Mask & Indeterminant)) {
399     SH = Shift & 31;
400     // make sure the mask is still a mask (wrap arounds may not be)
401     return isRunOfOnes(Mask, MB, ME);
402   }
403   return false;
404 }
405
406 /// SelectBitfieldInsert - turn an or of two masked values into
407 /// the rotate left word immediate then mask insert (rlwimi) instruction.
408 SDNode *PPCDAGToDAGISel::SelectBitfieldInsert(SDNode *N) {
409   SDValue Op0 = N->getOperand(0);
410   SDValue Op1 = N->getOperand(1);
411   SDLoc dl(N);
412
413   APInt LKZ, LKO, RKZ, RKO;
414   CurDAG->ComputeMaskedBits(Op0, LKZ, LKO);
415   CurDAG->ComputeMaskedBits(Op1, RKZ, RKO);
416
417   unsigned TargetMask = LKZ.getZExtValue();
418   unsigned InsertMask = RKZ.getZExtValue();
419
420   if ((TargetMask | InsertMask) == 0xFFFFFFFF) {
421     unsigned Op0Opc = Op0.getOpcode();
422     unsigned Op1Opc = Op1.getOpcode();
423     unsigned Value, SH = 0;
424     TargetMask = ~TargetMask;
425     InsertMask = ~InsertMask;
426
427     // If the LHS has a foldable shift and the RHS does not, then swap it to the
428     // RHS so that we can fold the shift into the insert.
429     if (Op0Opc == ISD::AND && Op1Opc == ISD::AND) {
430       if (Op0.getOperand(0).getOpcode() == ISD::SHL ||
431           Op0.getOperand(0).getOpcode() == ISD::SRL) {
432         if (Op1.getOperand(0).getOpcode() != ISD::SHL &&
433             Op1.getOperand(0).getOpcode() != ISD::SRL) {
434           std::swap(Op0, Op1);
435           std::swap(Op0Opc, Op1Opc);
436           std::swap(TargetMask, InsertMask);
437         }
438       }
439     } else if (Op0Opc == ISD::SHL || Op0Opc == ISD::SRL) {
440       if (Op1Opc == ISD::AND && Op1.getOperand(0).getOpcode() != ISD::SHL &&
441           Op1.getOperand(0).getOpcode() != ISD::SRL) {
442         std::swap(Op0, Op1);
443         std::swap(Op0Opc, Op1Opc);
444         std::swap(TargetMask, InsertMask);
445       }
446     }
447
448     unsigned MB, ME;
449     if (isRunOfOnes(InsertMask, MB, ME)) {
450       SDValue Tmp1, Tmp2;
451
452       if ((Op1Opc == ISD::SHL || Op1Opc == ISD::SRL) &&
453           isInt32Immediate(Op1.getOperand(1), Value)) {
454         Op1 = Op1.getOperand(0);
455         SH  = (Op1Opc == ISD::SHL) ? Value : 32 - Value;
456       }
457       if (Op1Opc == ISD::AND) {
458         unsigned SHOpc = Op1.getOperand(0).getOpcode();
459         if ((SHOpc == ISD::SHL || SHOpc == ISD::SRL) &&
460             isInt32Immediate(Op1.getOperand(0).getOperand(1), Value)) {
461           // Note that Value must be in range here (less than 32) because
462           // otherwise there would not be any bits set in InsertMask.
463           Op1 = Op1.getOperand(0).getOperand(0);
464           SH  = (SHOpc == ISD::SHL) ? Value : 32 - Value;
465         }
466       }
467
468       SH &= 31;
469       SDValue Ops[] = { Op0, Op1, getI32Imm(SH), getI32Imm(MB),
470                           getI32Imm(ME) };
471       return CurDAG->getMachineNode(PPC::RLWIMI, dl, MVT::i32, Ops);
472     }
473   }
474   return 0;
475 }
476
477 /// SelectCC - Select a comparison of the specified values with the specified
478 /// condition code, returning the CR# of the expression.
479 SDValue PPCDAGToDAGISel::SelectCC(SDValue LHS, SDValue RHS,
480                                     ISD::CondCode CC, SDLoc dl) {
481   // Always select the LHS.
482   unsigned Opc;
483
484   if (LHS.getValueType() == MVT::i32) {
485     unsigned Imm;
486     if (CC == ISD::SETEQ || CC == ISD::SETNE) {
487       if (isInt32Immediate(RHS, Imm)) {
488         // SETEQ/SETNE comparison with 16-bit immediate, fold it.
489         if (isUInt<16>(Imm))
490           return SDValue(CurDAG->getMachineNode(PPC::CMPLWI, dl, MVT::i32, LHS,
491                                                 getI32Imm(Imm & 0xFFFF)), 0);
492         // If this is a 16-bit signed immediate, fold it.
493         if (isInt<16>((int)Imm))
494           return SDValue(CurDAG->getMachineNode(PPC::CMPWI, dl, MVT::i32, LHS,
495                                                 getI32Imm(Imm & 0xFFFF)), 0);
496
497         // For non-equality comparisons, the default code would materialize the
498         // constant, then compare against it, like this:
499         //   lis r2, 4660
500         //   ori r2, r2, 22136
501         //   cmpw cr0, r3, r2
502         // Since we are just comparing for equality, we can emit this instead:
503         //   xoris r0,r3,0x1234
504         //   cmplwi cr0,r0,0x5678
505         //   beq cr0,L6
506         SDValue Xor(CurDAG->getMachineNode(PPC::XORIS, dl, MVT::i32, LHS,
507                                            getI32Imm(Imm >> 16)), 0);
508         return SDValue(CurDAG->getMachineNode(PPC::CMPLWI, dl, MVT::i32, Xor,
509                                               getI32Imm(Imm & 0xFFFF)), 0);
510       }
511       Opc = PPC::CMPLW;
512     } else if (ISD::isUnsignedIntSetCC(CC)) {
513       if (isInt32Immediate(RHS, Imm) && isUInt<16>(Imm))
514         return SDValue(CurDAG->getMachineNode(PPC::CMPLWI, dl, MVT::i32, LHS,
515                                               getI32Imm(Imm & 0xFFFF)), 0);
516       Opc = PPC::CMPLW;
517     } else {
518       short SImm;
519       if (isIntS16Immediate(RHS, SImm))
520         return SDValue(CurDAG->getMachineNode(PPC::CMPWI, dl, MVT::i32, LHS,
521                                               getI32Imm((int)SImm & 0xFFFF)),
522                          0);
523       Opc = PPC::CMPW;
524     }
525   } else if (LHS.getValueType() == MVT::i64) {
526     uint64_t Imm;
527     if (CC == ISD::SETEQ || CC == ISD::SETNE) {
528       if (isInt64Immediate(RHS.getNode(), Imm)) {
529         // SETEQ/SETNE comparison with 16-bit immediate, fold it.
530         if (isUInt<16>(Imm))
531           return SDValue(CurDAG->getMachineNode(PPC::CMPLDI, dl, MVT::i64, LHS,
532                                                 getI32Imm(Imm & 0xFFFF)), 0);
533         // If this is a 16-bit signed immediate, fold it.
534         if (isInt<16>(Imm))
535           return SDValue(CurDAG->getMachineNode(PPC::CMPDI, dl, MVT::i64, LHS,
536                                                 getI32Imm(Imm & 0xFFFF)), 0);
537
538         // For non-equality comparisons, the default code would materialize the
539         // constant, then compare against it, like this:
540         //   lis r2, 4660
541         //   ori r2, r2, 22136
542         //   cmpd cr0, r3, r2
543         // Since we are just comparing for equality, we can emit this instead:
544         //   xoris r0,r3,0x1234
545         //   cmpldi cr0,r0,0x5678
546         //   beq cr0,L6
547         if (isUInt<32>(Imm)) {
548           SDValue Xor(CurDAG->getMachineNode(PPC::XORIS8, dl, MVT::i64, LHS,
549                                              getI64Imm(Imm >> 16)), 0);
550           return SDValue(CurDAG->getMachineNode(PPC::CMPLDI, dl, MVT::i64, Xor,
551                                                 getI64Imm(Imm & 0xFFFF)), 0);
552         }
553       }
554       Opc = PPC::CMPLD;
555     } else if (ISD::isUnsignedIntSetCC(CC)) {
556       if (isInt64Immediate(RHS.getNode(), Imm) && isUInt<16>(Imm))
557         return SDValue(CurDAG->getMachineNode(PPC::CMPLDI, dl, MVT::i64, LHS,
558                                               getI64Imm(Imm & 0xFFFF)), 0);
559       Opc = PPC::CMPLD;
560     } else {
561       short SImm;
562       if (isIntS16Immediate(RHS, SImm))
563         return SDValue(CurDAG->getMachineNode(PPC::CMPDI, dl, MVT::i64, LHS,
564                                               getI64Imm(SImm & 0xFFFF)),
565                          0);
566       Opc = PPC::CMPD;
567     }
568   } else if (LHS.getValueType() == MVT::f32) {
569     Opc = PPC::FCMPUS;
570   } else {
571     assert(LHS.getValueType() == MVT::f64 && "Unknown vt!");
572     Opc = PPC::FCMPUD;
573   }
574   return SDValue(CurDAG->getMachineNode(Opc, dl, MVT::i32, LHS, RHS), 0);
575 }
576
577 static PPC::Predicate getPredicateForSetCC(ISD::CondCode CC) {
578   switch (CC) {
579   case ISD::SETUEQ:
580   case ISD::SETONE:
581   case ISD::SETOLE:
582   case ISD::SETOGE:
583     llvm_unreachable("Should be lowered by legalize!");
584   default: llvm_unreachable("Unknown condition!");
585   case ISD::SETOEQ:
586   case ISD::SETEQ:  return PPC::PRED_EQ;
587   case ISD::SETUNE:
588   case ISD::SETNE:  return PPC::PRED_NE;
589   case ISD::SETOLT:
590   case ISD::SETLT:  return PPC::PRED_LT;
591   case ISD::SETULE:
592   case ISD::SETLE:  return PPC::PRED_LE;
593   case ISD::SETOGT:
594   case ISD::SETGT:  return PPC::PRED_GT;
595   case ISD::SETUGE:
596   case ISD::SETGE:  return PPC::PRED_GE;
597   case ISD::SETO:   return PPC::PRED_NU;
598   case ISD::SETUO:  return PPC::PRED_UN;
599     // These two are invalid for floating point.  Assume we have int.
600   case ISD::SETULT: return PPC::PRED_LT;
601   case ISD::SETUGT: return PPC::PRED_GT;
602   }
603 }
604
605 /// getCRIdxForSetCC - Return the index of the condition register field
606 /// associated with the SetCC condition, and whether or not the field is
607 /// treated as inverted.  That is, lt = 0; ge = 0 inverted.
608 static unsigned getCRIdxForSetCC(ISD::CondCode CC, bool &Invert) {
609   Invert = false;
610   switch (CC) {
611   default: llvm_unreachable("Unknown condition!");
612   case ISD::SETOLT:
613   case ISD::SETLT:  return 0;                  // Bit #0 = SETOLT
614   case ISD::SETOGT:
615   case ISD::SETGT:  return 1;                  // Bit #1 = SETOGT
616   case ISD::SETOEQ:
617   case ISD::SETEQ:  return 2;                  // Bit #2 = SETOEQ
618   case ISD::SETUO:  return 3;                  // Bit #3 = SETUO
619   case ISD::SETUGE:
620   case ISD::SETGE:  Invert = true; return 0;   // !Bit #0 = SETUGE
621   case ISD::SETULE:
622   case ISD::SETLE:  Invert = true; return 1;   // !Bit #1 = SETULE
623   case ISD::SETUNE:
624   case ISD::SETNE:  Invert = true; return 2;   // !Bit #2 = SETUNE
625   case ISD::SETO:   Invert = true; return 3;   // !Bit #3 = SETO
626   case ISD::SETUEQ:
627   case ISD::SETOGE:
628   case ISD::SETOLE:
629   case ISD::SETONE:
630     llvm_unreachable("Invalid branch code: should be expanded by legalize");
631   // These are invalid for floating point.  Assume integer.
632   case ISD::SETULT: return 0;
633   case ISD::SETUGT: return 1;
634   }
635 }
636
637 // getVCmpInst: return the vector compare instruction for the specified
638 // vector type and condition code. Since this is for altivec specific code,
639 // only support the altivec types (v16i8, v8i16, v4i32, and v4f32).
640 static unsigned int getVCmpInst(MVT::SimpleValueType VecVT, ISD::CondCode CC) {
641   switch (CC) {
642     case ISD::SETEQ:
643     case ISD::SETUEQ:
644     case ISD::SETNE:
645     case ISD::SETUNE:
646       if (VecVT == MVT::v16i8)
647         return PPC::VCMPEQUB;
648       else if (VecVT == MVT::v8i16)
649         return PPC::VCMPEQUH;
650       else if (VecVT == MVT::v4i32)
651         return PPC::VCMPEQUW;
652       // v4f32 != v4f32 could be translate to unordered not equal
653       else if (VecVT == MVT::v4f32)
654         return PPC::VCMPEQFP;
655       break;
656     case ISD::SETLT:
657     case ISD::SETGT:
658     case ISD::SETLE:
659     case ISD::SETGE:
660       if (VecVT == MVT::v16i8)
661         return PPC::VCMPGTSB;
662       else if (VecVT == MVT::v8i16)
663         return PPC::VCMPGTSH;
664       else if (VecVT == MVT::v4i32)
665         return PPC::VCMPGTSW;
666       else if (VecVT == MVT::v4f32)
667         return PPC::VCMPGTFP;
668       break;
669     case ISD::SETULT:
670     case ISD::SETUGT:
671     case ISD::SETUGE:
672     case ISD::SETULE:
673       if (VecVT == MVT::v16i8)
674         return PPC::VCMPGTUB;
675       else if (VecVT == MVT::v8i16)
676         return PPC::VCMPGTUH;
677       else if (VecVT == MVT::v4i32)
678         return PPC::VCMPGTUW;
679       break;
680     case ISD::SETOEQ:
681       if (VecVT == MVT::v4f32)
682         return PPC::VCMPEQFP;
683       break;
684     case ISD::SETOLT:
685     case ISD::SETOGT:
686     case ISD::SETOLE:
687       if (VecVT == MVT::v4f32)
688         return PPC::VCMPGTFP;
689       break;
690     case ISD::SETOGE:
691       if (VecVT == MVT::v4f32)
692         return PPC::VCMPGEFP;
693       break;
694     default:
695       break;
696   }
697   llvm_unreachable("Invalid integer vector compare condition");
698 }
699
700 // getVCmpEQInst: return the equal compare instruction for the specified vector
701 // type. Since this is for altivec specific code, only support the altivec
702 // types (v16i8, v8i16, v4i32, and v4f32).
703 static unsigned int getVCmpEQInst(MVT::SimpleValueType VecVT) {
704   switch (VecVT) {
705     case MVT::v16i8:
706       return PPC::VCMPEQUB;
707     case MVT::v8i16:
708       return PPC::VCMPEQUH;
709     case MVT::v4i32:
710       return PPC::VCMPEQUW;
711     case MVT::v4f32:
712       return PPC::VCMPEQFP;
713     default:
714       llvm_unreachable("Invalid integer vector compare condition");
715   }
716 }
717
718
719 SDNode *PPCDAGToDAGISel::SelectSETCC(SDNode *N) {
720   SDLoc dl(N);
721   unsigned Imm;
722   ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
723   EVT PtrVT = CurDAG->getTargetLoweringInfo().getPointerTy();
724   bool isPPC64 = (PtrVT == MVT::i64);
725
726   if (!PPCSubTarget.useCRBits() &&
727       isInt32Immediate(N->getOperand(1), Imm)) {
728     // We can codegen setcc op, imm very efficiently compared to a brcond.
729     // Check for those cases here.
730     // setcc op, 0
731     if (Imm == 0) {
732       SDValue Op = N->getOperand(0);
733       switch (CC) {
734       default: break;
735       case ISD::SETEQ: {
736         Op = SDValue(CurDAG->getMachineNode(PPC::CNTLZW, dl, MVT::i32, Op), 0);
737         SDValue Ops[] = { Op, getI32Imm(27), getI32Imm(5), getI32Imm(31) };
738         return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
739       }
740       case ISD::SETNE: {
741         if (isPPC64) break;
742         SDValue AD =
743           SDValue(CurDAG->getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
744                                          Op, getI32Imm(~0U)), 0);
745         return CurDAG->SelectNodeTo(N, PPC::SUBFE, MVT::i32, AD, Op,
746                                     AD.getValue(1));
747       }
748       case ISD::SETLT: {
749         SDValue Ops[] = { Op, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
750         return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
751       }
752       case ISD::SETGT: {
753         SDValue T =
754           SDValue(CurDAG->getMachineNode(PPC::NEG, dl, MVT::i32, Op), 0);
755         T = SDValue(CurDAG->getMachineNode(PPC::ANDC, dl, MVT::i32, T, Op), 0);
756         SDValue Ops[] = { T, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
757         return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
758       }
759       }
760     } else if (Imm == ~0U) {        // setcc op, -1
761       SDValue Op = N->getOperand(0);
762       switch (CC) {
763       default: break;
764       case ISD::SETEQ:
765         if (isPPC64) break;
766         Op = SDValue(CurDAG->getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
767                                             Op, getI32Imm(1)), 0);
768         return CurDAG->SelectNodeTo(N, PPC::ADDZE, MVT::i32,
769                               SDValue(CurDAG->getMachineNode(PPC::LI, dl,
770                                                              MVT::i32,
771                                                              getI32Imm(0)), 0),
772                                       Op.getValue(1));
773       case ISD::SETNE: {
774         if (isPPC64) break;
775         Op = SDValue(CurDAG->getMachineNode(PPC::NOR, dl, MVT::i32, Op, Op), 0);
776         SDNode *AD = CurDAG->getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
777                                             Op, getI32Imm(~0U));
778         return CurDAG->SelectNodeTo(N, PPC::SUBFE, MVT::i32, SDValue(AD, 0),
779                                     Op, SDValue(AD, 1));
780       }
781       case ISD::SETLT: {
782         SDValue AD = SDValue(CurDAG->getMachineNode(PPC::ADDI, dl, MVT::i32, Op,
783                                                     getI32Imm(1)), 0);
784         SDValue AN = SDValue(CurDAG->getMachineNode(PPC::AND, dl, MVT::i32, AD,
785                                                     Op), 0);
786         SDValue Ops[] = { AN, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
787         return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
788       }
789       case ISD::SETGT: {
790         SDValue Ops[] = { Op, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
791         Op = SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl, MVT::i32, Ops),
792                      0);
793         return CurDAG->SelectNodeTo(N, PPC::XORI, MVT::i32, Op,
794                                     getI32Imm(1));
795       }
796       }
797     }
798   }
799
800   SDValue LHS = N->getOperand(0);
801   SDValue RHS = N->getOperand(1);
802
803   // Altivec Vector compare instructions do not set any CR register by default and
804   // vector compare operations return the same type as the operands.
805   if (LHS.getValueType().isVector()) {
806     EVT VecVT = LHS.getValueType();
807     MVT::SimpleValueType VT = VecVT.getSimpleVT().SimpleTy;
808     unsigned int VCmpInst = getVCmpInst(VT, CC);
809
810     switch (CC) {
811       case ISD::SETEQ:
812       case ISD::SETOEQ:
813       case ISD::SETUEQ:
814         return CurDAG->SelectNodeTo(N, VCmpInst, VecVT, LHS, RHS);
815       case ISD::SETNE:
816       case ISD::SETONE:
817       case ISD::SETUNE: {
818         SDValue VCmp(CurDAG->getMachineNode(VCmpInst, dl, VecVT, LHS, RHS), 0);
819         return CurDAG->SelectNodeTo(N, PPC::VNOR, VecVT, VCmp, VCmp);
820       } 
821       case ISD::SETLT:
822       case ISD::SETOLT:
823       case ISD::SETULT:
824         return CurDAG->SelectNodeTo(N, VCmpInst, VecVT, RHS, LHS);
825       case ISD::SETGT:
826       case ISD::SETOGT:
827       case ISD::SETUGT:
828         return CurDAG->SelectNodeTo(N, VCmpInst, VecVT, LHS, RHS);
829       case ISD::SETGE:
830       case ISD::SETOGE:
831       case ISD::SETUGE: {
832         // Small optimization: Altivec provides a 'Vector Compare Greater Than
833         // or Equal To' instruction (vcmpgefp), so in this case there is no
834         // need for extra logic for the equal compare.
835         if (VecVT.getSimpleVT().isFloatingPoint()) {
836           return CurDAG->SelectNodeTo(N, VCmpInst, VecVT, LHS, RHS);
837         } else {
838           SDValue VCmpGT(CurDAG->getMachineNode(VCmpInst, dl, VecVT, LHS, RHS), 0);
839           unsigned int VCmpEQInst = getVCmpEQInst(VT);
840           SDValue VCmpEQ(CurDAG->getMachineNode(VCmpEQInst, dl, VecVT, LHS, RHS), 0);
841           return CurDAG->SelectNodeTo(N, PPC::VOR, VecVT, VCmpGT, VCmpEQ);
842         }
843       }
844       case ISD::SETLE:
845       case ISD::SETOLE:
846       case ISD::SETULE: {
847         SDValue VCmpLE(CurDAG->getMachineNode(VCmpInst, dl, VecVT, RHS, LHS), 0);
848         unsigned int VCmpEQInst = getVCmpEQInst(VT);
849         SDValue VCmpEQ(CurDAG->getMachineNode(VCmpEQInst, dl, VecVT, LHS, RHS), 0);
850         return CurDAG->SelectNodeTo(N, PPC::VOR, VecVT, VCmpLE, VCmpEQ);
851       }
852       default:
853         llvm_unreachable("Invalid vector compare type: should be expanded by legalize");
854     }
855   }
856
857   if (PPCSubTarget.useCRBits())
858     return 0;
859
860   bool Inv;
861   unsigned Idx = getCRIdxForSetCC(CC, Inv);
862   SDValue CCReg = SelectCC(LHS, RHS, CC, dl);
863   SDValue IntCR;
864
865   // Force the ccreg into CR7.
866   SDValue CR7Reg = CurDAG->getRegister(PPC::CR7, MVT::i32);
867
868   SDValue InFlag(0, 0);  // Null incoming flag value.
869   CCReg = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, CR7Reg, CCReg,
870                                InFlag).getValue(1);
871
872   IntCR = SDValue(CurDAG->getMachineNode(PPC::MFOCRF, dl, MVT::i32, CR7Reg,
873                                          CCReg), 0);
874
875   SDValue Ops[] = { IntCR, getI32Imm((32-(3-Idx)) & 31),
876                       getI32Imm(31), getI32Imm(31) };
877   if (!Inv)
878     return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
879
880   // Get the specified bit.
881   SDValue Tmp =
882     SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl, MVT::i32, Ops), 0);
883   return CurDAG->SelectNodeTo(N, PPC::XORI, MVT::i32, Tmp, getI32Imm(1));
884 }
885
886
887 // Select - Convert the specified operand from a target-independent to a
888 // target-specific node if it hasn't already been changed.
889 SDNode *PPCDAGToDAGISel::Select(SDNode *N) {
890   SDLoc dl(N);
891   if (N->isMachineOpcode()) {
892     N->setNodeId(-1);
893     return NULL;   // Already selected.
894   }
895
896   switch (N->getOpcode()) {
897   default: break;
898
899   case ISD::Constant: {
900     if (N->getValueType(0) == MVT::i64) {
901       // Get 64 bit value.
902       int64_t Imm = cast<ConstantSDNode>(N)->getZExtValue();
903       // Assume no remaining bits.
904       unsigned Remainder = 0;
905       // Assume no shift required.
906       unsigned Shift = 0;
907
908       // If it can't be represented as a 32 bit value.
909       if (!isInt<32>(Imm)) {
910         Shift = countTrailingZeros<uint64_t>(Imm);
911         int64_t ImmSh = static_cast<uint64_t>(Imm) >> Shift;
912
913         // If the shifted value fits 32 bits.
914         if (isInt<32>(ImmSh)) {
915           // Go with the shifted value.
916           Imm = ImmSh;
917         } else {
918           // Still stuck with a 64 bit value.
919           Remainder = Imm;
920           Shift = 32;
921           Imm >>= 32;
922         }
923       }
924
925       // Intermediate operand.
926       SDNode *Result;
927
928       // Handle first 32 bits.
929       unsigned Lo = Imm & 0xFFFF;
930       unsigned Hi = (Imm >> 16) & 0xFFFF;
931
932       // Simple value.
933       if (isInt<16>(Imm)) {
934        // Just the Lo bits.
935         Result = CurDAG->getMachineNode(PPC::LI8, dl, MVT::i64, getI32Imm(Lo));
936       } else if (Lo) {
937         // Handle the Hi bits.
938         unsigned OpC = Hi ? PPC::LIS8 : PPC::LI8;
939         Result = CurDAG->getMachineNode(OpC, dl, MVT::i64, getI32Imm(Hi));
940         // And Lo bits.
941         Result = CurDAG->getMachineNode(PPC::ORI8, dl, MVT::i64,
942                                         SDValue(Result, 0), getI32Imm(Lo));
943       } else {
944        // Just the Hi bits.
945         Result = CurDAG->getMachineNode(PPC::LIS8, dl, MVT::i64, getI32Imm(Hi));
946       }
947
948       // If no shift, we're done.
949       if (!Shift) return Result;
950
951       // Shift for next step if the upper 32-bits were not zero.
952       if (Imm) {
953         Result = CurDAG->getMachineNode(PPC::RLDICR, dl, MVT::i64,
954                                         SDValue(Result, 0),
955                                         getI32Imm(Shift),
956                                         getI32Imm(63 - Shift));
957       }
958
959       // Add in the last bits as required.
960       if ((Hi = (Remainder >> 16) & 0xFFFF)) {
961         Result = CurDAG->getMachineNode(PPC::ORIS8, dl, MVT::i64,
962                                         SDValue(Result, 0), getI32Imm(Hi));
963       }
964       if ((Lo = Remainder & 0xFFFF)) {
965         Result = CurDAG->getMachineNode(PPC::ORI8, dl, MVT::i64,
966                                         SDValue(Result, 0), getI32Imm(Lo));
967       }
968
969       return Result;
970     }
971     break;
972   }
973
974   case ISD::SETCC: {
975     SDNode *SN = SelectSETCC(N);
976     if (SN)
977       return SN;
978     break;
979   }
980   case PPCISD::GlobalBaseReg:
981     return getGlobalBaseReg();
982
983   case ISD::FrameIndex: {
984     int FI = cast<FrameIndexSDNode>(N)->getIndex();
985     SDValue TFI = CurDAG->getTargetFrameIndex(FI, N->getValueType(0));
986     unsigned Opc = N->getValueType(0) == MVT::i32 ? PPC::ADDI : PPC::ADDI8;
987     if (N->hasOneUse())
988       return CurDAG->SelectNodeTo(N, Opc, N->getValueType(0), TFI,
989                                   getSmallIPtrImm(0));
990     return CurDAG->getMachineNode(Opc, dl, N->getValueType(0), TFI,
991                                   getSmallIPtrImm(0));
992   }
993
994   case PPCISD::MFOCRF: {
995     SDValue InFlag = N->getOperand(1);
996     return CurDAG->getMachineNode(PPC::MFOCRF, dl, MVT::i32,
997                                   N->getOperand(0), InFlag);
998   }
999
1000   case ISD::SDIV: {
1001     // FIXME: since this depends on the setting of the carry flag from the srawi
1002     //        we should really be making notes about that for the scheduler.
1003     // FIXME: It sure would be nice if we could cheaply recognize the
1004     //        srl/add/sra pattern the dag combiner will generate for this as
1005     //        sra/addze rather than having to handle sdiv ourselves.  oh well.
1006     unsigned Imm;
1007     if (isInt32Immediate(N->getOperand(1), Imm)) {
1008       SDValue N0 = N->getOperand(0);
1009       if ((signed)Imm > 0 && isPowerOf2_32(Imm)) {
1010         SDNode *Op =
1011           CurDAG->getMachineNode(PPC::SRAWI, dl, MVT::i32, MVT::Glue,
1012                                  N0, getI32Imm(Log2_32(Imm)));
1013         return CurDAG->SelectNodeTo(N, PPC::ADDZE, MVT::i32,
1014                                     SDValue(Op, 0), SDValue(Op, 1));
1015       } else if ((signed)Imm < 0 && isPowerOf2_32(-Imm)) {
1016         SDNode *Op =
1017           CurDAG->getMachineNode(PPC::SRAWI, dl, MVT::i32, MVT::Glue,
1018                                  N0, getI32Imm(Log2_32(-Imm)));
1019         SDValue PT =
1020           SDValue(CurDAG->getMachineNode(PPC::ADDZE, dl, MVT::i32,
1021                                          SDValue(Op, 0), SDValue(Op, 1)),
1022                     0);
1023         return CurDAG->SelectNodeTo(N, PPC::NEG, MVT::i32, PT);
1024       }
1025     }
1026
1027     // Other cases are autogenerated.
1028     break;
1029   }
1030
1031   case ISD::LOAD: {
1032     // Handle preincrement loads.
1033     LoadSDNode *LD = cast<LoadSDNode>(N);
1034     EVT LoadedVT = LD->getMemoryVT();
1035
1036     // Normal loads are handled by code generated from the .td file.
1037     if (LD->getAddressingMode() != ISD::PRE_INC)
1038       break;
1039
1040     SDValue Offset = LD->getOffset();
1041     if (Offset.getOpcode() == ISD::TargetConstant ||
1042         Offset.getOpcode() == ISD::TargetGlobalAddress) {
1043
1044       unsigned Opcode;
1045       bool isSExt = LD->getExtensionType() == ISD::SEXTLOAD;
1046       if (LD->getValueType(0) != MVT::i64) {
1047         // Handle PPC32 integer and normal FP loads.
1048         assert((!isSExt || LoadedVT == MVT::i16) && "Invalid sext update load");
1049         switch (LoadedVT.getSimpleVT().SimpleTy) {
1050           default: llvm_unreachable("Invalid PPC load type!");
1051           case MVT::f64: Opcode = PPC::LFDU; break;
1052           case MVT::f32: Opcode = PPC::LFSU; break;
1053           case MVT::i32: Opcode = PPC::LWZU; break;
1054           case MVT::i16: Opcode = isSExt ? PPC::LHAU : PPC::LHZU; break;
1055           case MVT::i1:
1056           case MVT::i8:  Opcode = PPC::LBZU; break;
1057         }
1058       } else {
1059         assert(LD->getValueType(0) == MVT::i64 && "Unknown load result type!");
1060         assert((!isSExt || LoadedVT == MVT::i16) && "Invalid sext update load");
1061         switch (LoadedVT.getSimpleVT().SimpleTy) {
1062           default: llvm_unreachable("Invalid PPC load type!");
1063           case MVT::i64: Opcode = PPC::LDU; break;
1064           case MVT::i32: Opcode = PPC::LWZU8; break;
1065           case MVT::i16: Opcode = isSExt ? PPC::LHAU8 : PPC::LHZU8; break;
1066           case MVT::i1:
1067           case MVT::i8:  Opcode = PPC::LBZU8; break;
1068         }
1069       }
1070
1071       SDValue Chain = LD->getChain();
1072       SDValue Base = LD->getBasePtr();
1073       SDValue Ops[] = { Offset, Base, Chain };
1074       return CurDAG->getMachineNode(Opcode, dl, LD->getValueType(0),
1075                                     PPCLowering.getPointerTy(),
1076                                     MVT::Other, Ops);
1077     } else {
1078       unsigned Opcode;
1079       bool isSExt = LD->getExtensionType() == ISD::SEXTLOAD;
1080       if (LD->getValueType(0) != MVT::i64) {
1081         // Handle PPC32 integer and normal FP loads.
1082         assert((!isSExt || LoadedVT == MVT::i16) && "Invalid sext update load");
1083         switch (LoadedVT.getSimpleVT().SimpleTy) {
1084           default: llvm_unreachable("Invalid PPC load type!");
1085           case MVT::f64: Opcode = PPC::LFDUX; break;
1086           case MVT::f32: Opcode = PPC::LFSUX; break;
1087           case MVT::i32: Opcode = PPC::LWZUX; break;
1088           case MVT::i16: Opcode = isSExt ? PPC::LHAUX : PPC::LHZUX; break;
1089           case MVT::i1:
1090           case MVT::i8:  Opcode = PPC::LBZUX; break;
1091         }
1092       } else {
1093         assert(LD->getValueType(0) == MVT::i64 && "Unknown load result type!");
1094         assert((!isSExt || LoadedVT == MVT::i16 || LoadedVT == MVT::i32) &&
1095                "Invalid sext update load");
1096         switch (LoadedVT.getSimpleVT().SimpleTy) {
1097           default: llvm_unreachable("Invalid PPC load type!");
1098           case MVT::i64: Opcode = PPC::LDUX; break;
1099           case MVT::i32: Opcode = isSExt ? PPC::LWAUX  : PPC::LWZUX8; break;
1100           case MVT::i16: Opcode = isSExt ? PPC::LHAUX8 : PPC::LHZUX8; break;
1101           case MVT::i1:
1102           case MVT::i8:  Opcode = PPC::LBZUX8; break;
1103         }
1104       }
1105
1106       SDValue Chain = LD->getChain();
1107       SDValue Base = LD->getBasePtr();
1108       SDValue Ops[] = { Base, Offset, Chain };
1109       return CurDAG->getMachineNode(Opcode, dl, LD->getValueType(0),
1110                                     PPCLowering.getPointerTy(),
1111                                     MVT::Other, Ops);
1112     }
1113   }
1114
1115   case ISD::AND: {
1116     unsigned Imm, Imm2, SH, MB, ME;
1117     uint64_t Imm64;
1118
1119     // If this is an and of a value rotated between 0 and 31 bits and then and'd
1120     // with a mask, emit rlwinm
1121     if (isInt32Immediate(N->getOperand(1), Imm) &&
1122         isRotateAndMask(N->getOperand(0).getNode(), Imm, false, SH, MB, ME)) {
1123       SDValue Val = N->getOperand(0).getOperand(0);
1124       SDValue Ops[] = { Val, getI32Imm(SH), getI32Imm(MB), getI32Imm(ME) };
1125       return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
1126     }
1127     // If this is just a masked value where the input is not handled above, and
1128     // is not a rotate-left (handled by a pattern in the .td file), emit rlwinm
1129     if (isInt32Immediate(N->getOperand(1), Imm) &&
1130         isRunOfOnes(Imm, MB, ME) &&
1131         N->getOperand(0).getOpcode() != ISD::ROTL) {
1132       SDValue Val = N->getOperand(0);
1133       SDValue Ops[] = { Val, getI32Imm(0), getI32Imm(MB), getI32Imm(ME) };
1134       return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
1135     }
1136     // If this is a 64-bit zero-extension mask, emit rldicl.
1137     if (isInt64Immediate(N->getOperand(1).getNode(), Imm64) &&
1138         isMask_64(Imm64)) {
1139       SDValue Val = N->getOperand(0);
1140       MB = 64 - CountTrailingOnes_64(Imm64);
1141       SH = 0;
1142
1143       // If the operand is a logical right shift, we can fold it into this
1144       // instruction: rldicl(rldicl(x, 64-n, n), 0, mb) -> rldicl(x, 64-n, mb)
1145       // for n <= mb. The right shift is really a left rotate followed by a
1146       // mask, and this mask is a more-restrictive sub-mask of the mask implied
1147       // by the shift.
1148       if (Val.getOpcode() == ISD::SRL &&
1149           isInt32Immediate(Val.getOperand(1).getNode(), Imm) && Imm <= MB) {
1150         assert(Imm < 64 && "Illegal shift amount");
1151         Val = Val.getOperand(0);
1152         SH = 64 - Imm;
1153       }
1154
1155       SDValue Ops[] = { Val, getI32Imm(SH), getI32Imm(MB) };
1156       return CurDAG->SelectNodeTo(N, PPC::RLDICL, MVT::i64, Ops, 3);
1157     }
1158     // AND X, 0 -> 0, not "rlwinm 32".
1159     if (isInt32Immediate(N->getOperand(1), Imm) && (Imm == 0)) {
1160       ReplaceUses(SDValue(N, 0), N->getOperand(1));
1161       return NULL;
1162     }
1163     // ISD::OR doesn't get all the bitfield insertion fun.
1164     // (and (or x, c1), c2) where isRunOfOnes(~(c1^c2)) is a bitfield insert
1165     if (isInt32Immediate(N->getOperand(1), Imm) &&
1166         N->getOperand(0).getOpcode() == ISD::OR &&
1167         isInt32Immediate(N->getOperand(0).getOperand(1), Imm2)) {
1168       unsigned MB, ME;
1169       Imm = ~(Imm^Imm2);
1170       if (isRunOfOnes(Imm, MB, ME)) {
1171         SDValue Ops[] = { N->getOperand(0).getOperand(0),
1172                             N->getOperand(0).getOperand(1),
1173                             getI32Imm(0), getI32Imm(MB),getI32Imm(ME) };
1174         return CurDAG->getMachineNode(PPC::RLWIMI, dl, MVT::i32, Ops);
1175       }
1176     }
1177
1178     // Other cases are autogenerated.
1179     break;
1180   }
1181   case ISD::OR:
1182     if (N->getValueType(0) == MVT::i32)
1183       if (SDNode *I = SelectBitfieldInsert(N))
1184         return I;
1185
1186     // Other cases are autogenerated.
1187     break;
1188   case ISD::SHL: {
1189     unsigned Imm, SH, MB, ME;
1190     if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::AND, Imm) &&
1191         isRotateAndMask(N, Imm, true, SH, MB, ME)) {
1192       SDValue Ops[] = { N->getOperand(0).getOperand(0),
1193                           getI32Imm(SH), getI32Imm(MB), getI32Imm(ME) };
1194       return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
1195     }
1196
1197     // Other cases are autogenerated.
1198     break;
1199   }
1200   case ISD::SRL: {
1201     unsigned Imm, SH, MB, ME;
1202     if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::AND, Imm) &&
1203         isRotateAndMask(N, Imm, true, SH, MB, ME)) {
1204       SDValue Ops[] = { N->getOperand(0).getOperand(0),
1205                           getI32Imm(SH), getI32Imm(MB), getI32Imm(ME) };
1206       return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
1207     }
1208
1209     // Other cases are autogenerated.
1210     break;
1211   }
1212   // FIXME: Remove this once the ANDI glue bug is fixed:
1213   case PPCISD::ANDIo_1_EQ_BIT:
1214   case PPCISD::ANDIo_1_GT_BIT: {
1215     if (!ANDIGlueBug)
1216       break;
1217
1218     EVT InVT = N->getOperand(0).getValueType();
1219     assert((InVT == MVT::i64 || InVT == MVT::i32) &&
1220            "Invalid input type for ANDIo_1_EQ_BIT");
1221
1222     unsigned Opcode = (InVT == MVT::i64) ? PPC::ANDIo8 : PPC::ANDIo;
1223     SDValue AndI(CurDAG->getMachineNode(Opcode, dl, InVT, MVT::Glue,
1224                                         N->getOperand(0),
1225                                         CurDAG->getTargetConstant(1, InVT)), 0);
1226     SDValue CR0Reg = CurDAG->getRegister(PPC::CR0, MVT::i32);
1227     SDValue SRIdxVal =
1228       CurDAG->getTargetConstant(N->getOpcode() == PPCISD::ANDIo_1_EQ_BIT ?
1229                                 PPC::sub_eq : PPC::sub_gt, MVT::i32);
1230
1231     return CurDAG->SelectNodeTo(N, TargetOpcode::EXTRACT_SUBREG, MVT::i1,
1232                                 CR0Reg, SRIdxVal,
1233                                 SDValue(AndI.getNode(), 1) /* glue */);
1234   }
1235   case ISD::SELECT_CC: {
1236     ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get();
1237     EVT PtrVT = CurDAG->getTargetLoweringInfo().getPointerTy();
1238     bool isPPC64 = (PtrVT == MVT::i64);
1239
1240     // If this is a select of i1 operands, we'll pattern match it.
1241     if (PPCSubTarget.useCRBits() &&
1242         N->getOperand(0).getValueType() == MVT::i1)
1243       break;
1244
1245     // Handle the setcc cases here.  select_cc lhs, 0, 1, 0, cc
1246     if (!isPPC64)
1247       if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N->getOperand(1)))
1248         if (ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N->getOperand(2)))
1249           if (ConstantSDNode *N3C = dyn_cast<ConstantSDNode>(N->getOperand(3)))
1250             if (N1C->isNullValue() && N3C->isNullValue() &&
1251                 N2C->getZExtValue() == 1ULL && CC == ISD::SETNE &&
1252                 // FIXME: Implement this optzn for PPC64.
1253                 N->getValueType(0) == MVT::i32) {
1254               SDNode *Tmp =
1255                 CurDAG->getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
1256                                        N->getOperand(0), getI32Imm(~0U));
1257               return CurDAG->SelectNodeTo(N, PPC::SUBFE, MVT::i32,
1258                                           SDValue(Tmp, 0), N->getOperand(0),
1259                                           SDValue(Tmp, 1));
1260             }
1261
1262     SDValue CCReg = SelectCC(N->getOperand(0), N->getOperand(1), CC, dl);
1263
1264     if (N->getValueType(0) == MVT::i1) {
1265       // An i1 select is: (c & t) | (!c & f).
1266       bool Inv;
1267       unsigned Idx = getCRIdxForSetCC(CC, Inv);
1268
1269       unsigned SRI;
1270       switch (Idx) {
1271       default: llvm_unreachable("Invalid CC index");
1272       case 0: SRI = PPC::sub_lt; break;
1273       case 1: SRI = PPC::sub_gt; break;
1274       case 2: SRI = PPC::sub_eq; break;
1275       case 3: SRI = PPC::sub_un; break;
1276       }
1277
1278       SDValue CCBit = CurDAG->getTargetExtractSubreg(SRI, dl, MVT::i1, CCReg);
1279
1280       SDValue NotCCBit(CurDAG->getMachineNode(PPC::CRNOR, dl, MVT::i1,
1281                                               CCBit, CCBit), 0);
1282       SDValue C =    Inv ? NotCCBit : CCBit,
1283               NotC = Inv ? CCBit    : NotCCBit;
1284
1285       SDValue CAndT(CurDAG->getMachineNode(PPC::CRAND, dl, MVT::i1,
1286                                            C, N->getOperand(2)), 0);
1287       SDValue NotCAndF(CurDAG->getMachineNode(PPC::CRAND, dl, MVT::i1,
1288                                               NotC, N->getOperand(3)), 0);
1289
1290       return CurDAG->SelectNodeTo(N, PPC::CROR, MVT::i1, CAndT, NotCAndF);
1291     }
1292
1293     unsigned BROpc = getPredicateForSetCC(CC);
1294
1295     unsigned SelectCCOp;
1296     if (N->getValueType(0) == MVT::i32)
1297       SelectCCOp = PPC::SELECT_CC_I4;
1298     else if (N->getValueType(0) == MVT::i64)
1299       SelectCCOp = PPC::SELECT_CC_I8;
1300     else if (N->getValueType(0) == MVT::f32)
1301       SelectCCOp = PPC::SELECT_CC_F4;
1302     else if (N->getValueType(0) == MVT::f64)
1303       SelectCCOp = PPC::SELECT_CC_F8;
1304     else
1305       SelectCCOp = PPC::SELECT_CC_VRRC;
1306
1307     SDValue Ops[] = { CCReg, N->getOperand(2), N->getOperand(3),
1308                         getI32Imm(BROpc) };
1309     return CurDAG->SelectNodeTo(N, SelectCCOp, N->getValueType(0), Ops, 4);
1310   }
1311   case PPCISD::BDNZ:
1312   case PPCISD::BDZ: {
1313     bool IsPPC64 = PPCSubTarget.isPPC64();
1314     SDValue Ops[] = { N->getOperand(1), N->getOperand(0) };
1315     return CurDAG->SelectNodeTo(N, N->getOpcode() == PPCISD::BDNZ ?
1316                                    (IsPPC64 ? PPC::BDNZ8 : PPC::BDNZ) :
1317                                    (IsPPC64 ? PPC::BDZ8 : PPC::BDZ),
1318                                 MVT::Other, Ops, 2);
1319   }
1320   case PPCISD::COND_BRANCH: {
1321     // Op #0 is the Chain.
1322     // Op #1 is the PPC::PRED_* number.
1323     // Op #2 is the CR#
1324     // Op #3 is the Dest MBB
1325     // Op #4 is the Flag.
1326     // Prevent PPC::PRED_* from being selected into LI.
1327     SDValue Pred =
1328       getI32Imm(cast<ConstantSDNode>(N->getOperand(1))->getZExtValue());
1329     SDValue Ops[] = { Pred, N->getOperand(2), N->getOperand(3),
1330       N->getOperand(0), N->getOperand(4) };
1331     return CurDAG->SelectNodeTo(N, PPC::BCC, MVT::Other, Ops, 5);
1332   }
1333   case ISD::BR_CC: {
1334     ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(1))->get();
1335     unsigned PCC = getPredicateForSetCC(CC);
1336
1337     if (N->getOperand(2).getValueType() == MVT::i1) {
1338       unsigned Opc;
1339       bool Swap;
1340       switch (PCC) {
1341       default: llvm_unreachable("Unexpected Boolean-operand predicate");
1342       case PPC::PRED_LT: Opc = PPC::CRANDC; Swap = true;  break;
1343       case PPC::PRED_LE: Opc = PPC::CRORC;  Swap = true;  break;
1344       case PPC::PRED_EQ: Opc = PPC::CREQV;  Swap = false; break;
1345       case PPC::PRED_GE: Opc = PPC::CRORC;  Swap = false; break;
1346       case PPC::PRED_GT: Opc = PPC::CRANDC; Swap = false; break;
1347       case PPC::PRED_NE: Opc = PPC::CRXOR;  Swap = false; break;
1348       }
1349
1350       SDValue BitComp(CurDAG->getMachineNode(Opc, dl, MVT::i1,
1351                                              N->getOperand(Swap ? 3 : 2),
1352                                              N->getOperand(Swap ? 2 : 3)), 0);
1353       return CurDAG->SelectNodeTo(N, PPC::BC, MVT::Other,
1354                                   BitComp, N->getOperand(4), N->getOperand(0));
1355     }
1356
1357     SDValue CondCode = SelectCC(N->getOperand(2), N->getOperand(3), CC, dl);
1358     SDValue Ops[] = { getI32Imm(PCC), CondCode,
1359                         N->getOperand(4), N->getOperand(0) };
1360     return CurDAG->SelectNodeTo(N, PPC::BCC, MVT::Other, Ops, 4);
1361   }
1362   case ISD::BRIND: {
1363     // FIXME: Should custom lower this.
1364     SDValue Chain = N->getOperand(0);
1365     SDValue Target = N->getOperand(1);
1366     unsigned Opc = Target.getValueType() == MVT::i32 ? PPC::MTCTR : PPC::MTCTR8;
1367     unsigned Reg = Target.getValueType() == MVT::i32 ? PPC::BCTR : PPC::BCTR8;
1368     Chain = SDValue(CurDAG->getMachineNode(Opc, dl, MVT::Glue, Target,
1369                                            Chain), 0);
1370     return CurDAG->SelectNodeTo(N, Reg, MVT::Other, Chain);
1371   }
1372   case PPCISD::TOC_ENTRY: {
1373     assert (PPCSubTarget.isPPC64() && "Only supported for 64-bit ABI");
1374
1375     // For medium and large code model, we generate two instructions as
1376     // described below.  Otherwise we allow SelectCodeCommon to handle this,
1377     // selecting one of LDtoc, LDtocJTI, and LDtocCPT.
1378     CodeModel::Model CModel = TM.getCodeModel();
1379     if (CModel != CodeModel::Medium && CModel != CodeModel::Large)
1380       break;
1381
1382     // The first source operand is a TargetGlobalAddress or a
1383     // TargetJumpTable.  If it is an externally defined symbol, a symbol
1384     // with common linkage, a function address, or a jump table address,
1385     // or if we are generating code for large code model, we generate:
1386     //   LDtocL(<ga:@sym>, ADDIStocHA(%X2, <ga:@sym>))
1387     // Otherwise we generate:
1388     //   ADDItocL(ADDIStocHA(%X2, <ga:@sym>), <ga:@sym>)
1389     SDValue GA = N->getOperand(0);
1390     SDValue TOCbase = N->getOperand(1);
1391     SDNode *Tmp = CurDAG->getMachineNode(PPC::ADDIStocHA, dl, MVT::i64,
1392                                         TOCbase, GA);
1393
1394     if (isa<JumpTableSDNode>(GA) || CModel == CodeModel::Large)
1395       return CurDAG->getMachineNode(PPC::LDtocL, dl, MVT::i64, GA,
1396                                     SDValue(Tmp, 0));
1397
1398     if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(GA)) {
1399       const GlobalValue *GValue = G->getGlobal();
1400       const GlobalAlias *GAlias = dyn_cast<GlobalAlias>(GValue);
1401       const GlobalValue *RealGValue = GAlias ?
1402         GAlias->resolveAliasedGlobal(false) : GValue;
1403       const GlobalVariable *GVar = dyn_cast<GlobalVariable>(RealGValue);
1404       assert((GVar || isa<Function>(RealGValue)) &&
1405              "Unexpected global value subclass!");
1406
1407       // An external variable is one without an initializer.  For these,
1408       // for variables with common linkage, and for Functions, generate
1409       // the LDtocL form.
1410       if (!GVar || !GVar->hasInitializer() || RealGValue->hasCommonLinkage() ||
1411           RealGValue->hasAvailableExternallyLinkage())
1412         return CurDAG->getMachineNode(PPC::LDtocL, dl, MVT::i64, GA,
1413                                       SDValue(Tmp, 0));
1414     }
1415
1416     return CurDAG->getMachineNode(PPC::ADDItocL, dl, MVT::i64,
1417                                   SDValue(Tmp, 0), GA);
1418   }
1419   case PPCISD::VADD_SPLAT: {
1420     // This expands into one of three sequences, depending on whether
1421     // the first operand is odd or even, positive or negative.
1422     assert(isa<ConstantSDNode>(N->getOperand(0)) &&
1423            isa<ConstantSDNode>(N->getOperand(1)) &&
1424            "Invalid operand on VADD_SPLAT!");
1425
1426     int Elt     = N->getConstantOperandVal(0);
1427     int EltSize = N->getConstantOperandVal(1);
1428     unsigned Opc1, Opc2, Opc3;
1429     EVT VT;
1430
1431     if (EltSize == 1) {
1432       Opc1 = PPC::VSPLTISB;
1433       Opc2 = PPC::VADDUBM;
1434       Opc3 = PPC::VSUBUBM;
1435       VT = MVT::v16i8;
1436     } else if (EltSize == 2) {
1437       Opc1 = PPC::VSPLTISH;
1438       Opc2 = PPC::VADDUHM;
1439       Opc3 = PPC::VSUBUHM;
1440       VT = MVT::v8i16;
1441     } else {
1442       assert(EltSize == 4 && "Invalid element size on VADD_SPLAT!");
1443       Opc1 = PPC::VSPLTISW;
1444       Opc2 = PPC::VADDUWM;
1445       Opc3 = PPC::VSUBUWM;
1446       VT = MVT::v4i32;
1447     }
1448
1449     if ((Elt & 1) == 0) {
1450       // Elt is even, in the range [-32,-18] + [16,30].
1451       //
1452       // Convert: VADD_SPLAT elt, size
1453       // Into:    tmp = VSPLTIS[BHW] elt
1454       //          VADDU[BHW]M tmp, tmp
1455       // Where:   [BHW] = B for size = 1, H for size = 2, W for size = 4
1456       SDValue EltVal = getI32Imm(Elt >> 1);
1457       SDNode *Tmp = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1458       SDValue TmpVal = SDValue(Tmp, 0);
1459       return CurDAG->getMachineNode(Opc2, dl, VT, TmpVal, TmpVal);
1460
1461     } else if (Elt > 0) {
1462       // Elt is odd and positive, in the range [17,31].
1463       //
1464       // Convert: VADD_SPLAT elt, size
1465       // Into:    tmp1 = VSPLTIS[BHW] elt-16
1466       //          tmp2 = VSPLTIS[BHW] -16
1467       //          VSUBU[BHW]M tmp1, tmp2
1468       SDValue EltVal = getI32Imm(Elt - 16);
1469       SDNode *Tmp1 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1470       EltVal = getI32Imm(-16);
1471       SDNode *Tmp2 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1472       return CurDAG->getMachineNode(Opc3, dl, VT, SDValue(Tmp1, 0),
1473                                     SDValue(Tmp2, 0));
1474
1475     } else {
1476       // Elt is odd and negative, in the range [-31,-17].
1477       //
1478       // Convert: VADD_SPLAT elt, size
1479       // Into:    tmp1 = VSPLTIS[BHW] elt+16
1480       //          tmp2 = VSPLTIS[BHW] -16
1481       //          VADDU[BHW]M tmp1, tmp2
1482       SDValue EltVal = getI32Imm(Elt + 16);
1483       SDNode *Tmp1 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1484       EltVal = getI32Imm(-16);
1485       SDNode *Tmp2 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1486       return CurDAG->getMachineNode(Opc2, dl, VT, SDValue(Tmp1, 0),
1487                                     SDValue(Tmp2, 0));
1488     }
1489   }
1490   }
1491
1492   return SelectCode(N);
1493 }
1494
1495 /// PostprocessISelDAG - Perform some late peephole optimizations
1496 /// on the DAG representation.
1497 void PPCDAGToDAGISel::PostprocessISelDAG() {
1498
1499   // Skip peepholes at -O0.
1500   if (TM.getOptLevel() == CodeGenOpt::None)
1501     return;
1502
1503   PeepholePPC64();
1504   PeepholdCROps();
1505 }
1506
1507 void PPCDAGToDAGISel::PeepholdCROps() {
1508   bool IsModified;
1509   do {
1510     IsModified = false;
1511     for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
1512          E = CurDAG->allnodes_end(); I != E; ++I) {
1513       MachineSDNode *MachineNode = dyn_cast<MachineSDNode>(I);
1514       if (!MachineNode || MachineNode->use_empty())
1515         continue;
1516       SDNode *ResNode = MachineNode;
1517
1518       bool Op1Set   = false, Op1Unset = false,
1519            Op1Not   = false,
1520            Op2Set   = false, Op2Unset = false,
1521            Op2Not   = false;
1522
1523       unsigned Opcode = MachineNode->getMachineOpcode();
1524       switch (Opcode) {
1525       default: break;
1526       case PPC::CRAND:
1527       case PPC::CRNAND:
1528       case PPC::CROR:
1529       case PPC::CRXOR:
1530       case PPC::CRNOR:
1531       case PPC::CREQV:
1532       case PPC::CRANDC:
1533       case PPC::CRORC: {
1534         SDValue Op = MachineNode->getOperand(1);
1535         if (Op.isMachineOpcode()) {
1536           if (Op.getMachineOpcode() == PPC::CRSET)
1537             Op2Set = true;
1538           else if (Op.getMachineOpcode() == PPC::CRUNSET)
1539             Op2Unset = true;
1540           else if (Op.getMachineOpcode() == PPC::CRNOR &&
1541                    Op.getOperand(0) == Op.getOperand(1))
1542             Op2Not = true;
1543         }
1544         }  // fallthrough
1545       case PPC::BC:
1546       case PPC::BCn:
1547       case PPC::SELECT_I4:
1548       case PPC::SELECT_I8:
1549       case PPC::SELECT_F4:
1550       case PPC::SELECT_F8:
1551       case PPC::SELECT_VRRC: {
1552         SDValue Op = MachineNode->getOperand(0);
1553         if (Op.isMachineOpcode()) {
1554           if (Op.getMachineOpcode() == PPC::CRSET)
1555             Op1Set = true;
1556           else if (Op.getMachineOpcode() == PPC::CRUNSET)
1557             Op1Unset = true;
1558           else if (Op.getMachineOpcode() == PPC::CRNOR &&
1559                    Op.getOperand(0) == Op.getOperand(1))
1560             Op1Not = true;
1561         }
1562         }
1563         break;
1564       }
1565
1566       switch (Opcode) {
1567       default: break;
1568       case PPC::CRAND:
1569         if (MachineNode->getOperand(0) == MachineNode->getOperand(1))
1570           // x & x = x
1571           ResNode = MachineNode->getOperand(0).getNode();
1572         else if (Op1Set)
1573           // 1 & y = y
1574           ResNode = MachineNode->getOperand(1).getNode();
1575         else if (Op2Set)
1576           // x & 1 = x
1577           ResNode = MachineNode->getOperand(0).getNode();
1578         else if (Op1Unset || Op2Unset)
1579           // x & 0 = 0 & y = 0
1580           ResNode = CurDAG->getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
1581                                            MVT::i1);
1582         else if (Op1Not)
1583           // ~x & y = andc(y, x)
1584           ResNode = CurDAG->getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
1585                                            MVT::i1, MachineNode->getOperand(1),
1586                                            MachineNode->getOperand(0).
1587                                              getOperand(0));
1588         else if (Op2Not)
1589           // x & ~y = andc(x, y)
1590           ResNode = CurDAG->getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
1591                                            MVT::i1, MachineNode->getOperand(0),
1592                                            MachineNode->getOperand(1).
1593                                              getOperand(0));
1594         break;
1595       case PPC::CRNAND:
1596         if (MachineNode->getOperand(0) == MachineNode->getOperand(1))
1597           // nand(x, x) -> nor(x, x)
1598           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1599                                            MVT::i1, MachineNode->getOperand(0),
1600                                            MachineNode->getOperand(0));
1601         else if (Op1Set)
1602           // nand(1, y) -> nor(y, y)
1603           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1604                                            MVT::i1, MachineNode->getOperand(1),
1605                                            MachineNode->getOperand(1));
1606         else if (Op2Set)
1607           // nand(x, 1) -> nor(x, x)
1608           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1609                                            MVT::i1, MachineNode->getOperand(0),
1610                                            MachineNode->getOperand(0));
1611         else if (Op1Unset || Op2Unset)
1612           // nand(x, 0) = nand(0, y) = 1
1613           ResNode = CurDAG->getMachineNode(PPC::CRSET, SDLoc(MachineNode),
1614                                            MVT::i1);
1615         else if (Op1Not)
1616           // nand(~x, y) = ~(~x & y) = x | ~y = orc(x, y)
1617           ResNode = CurDAG->getMachineNode(PPC::CRORC, SDLoc(MachineNode),
1618                                            MVT::i1, MachineNode->getOperand(0).
1619                                                       getOperand(0),
1620                                            MachineNode->getOperand(1));
1621         else if (Op2Not)
1622           // nand(x, ~y) = ~x | y = orc(y, x)
1623           ResNode = CurDAG->getMachineNode(PPC::CRORC, SDLoc(MachineNode),
1624                                            MVT::i1, MachineNode->getOperand(1).
1625                                                       getOperand(0),
1626                                            MachineNode->getOperand(0));
1627         break;
1628       case PPC::CROR:
1629         if (MachineNode->getOperand(0) == MachineNode->getOperand(1))
1630           // x | x = x
1631           ResNode = MachineNode->getOperand(0).getNode();
1632         else if (Op1Set || Op2Set)
1633           // x | 1 = 1 | y = 1
1634           ResNode = CurDAG->getMachineNode(PPC::CRSET, SDLoc(MachineNode),
1635                                            MVT::i1);
1636         else if (Op1Unset)
1637           // 0 | y = y
1638           ResNode = MachineNode->getOperand(1).getNode();
1639         else if (Op2Unset)
1640           // x | 0 = x
1641           ResNode = MachineNode->getOperand(0).getNode();
1642         else if (Op1Not)
1643           // ~x | y = orc(y, x)
1644           ResNode = CurDAG->getMachineNode(PPC::CRORC, SDLoc(MachineNode),
1645                                            MVT::i1, MachineNode->getOperand(1),
1646                                            MachineNode->getOperand(0).
1647                                              getOperand(0));
1648         else if (Op2Not)
1649           // x | ~y = orc(x, y)
1650           ResNode = CurDAG->getMachineNode(PPC::CRORC, SDLoc(MachineNode),
1651                                            MVT::i1, MachineNode->getOperand(0),
1652                                            MachineNode->getOperand(1).
1653                                              getOperand(0));
1654         break;
1655       case PPC::CRXOR:
1656         if (MachineNode->getOperand(0) == MachineNode->getOperand(1))
1657           // xor(x, x) = 0
1658           ResNode = CurDAG->getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
1659                                            MVT::i1);
1660         else if (Op1Set)
1661           // xor(1, y) -> nor(y, y)
1662           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1663                                            MVT::i1, MachineNode->getOperand(1),
1664                                            MachineNode->getOperand(1));
1665         else if (Op2Set)
1666           // xor(x, 1) -> nor(x, x)
1667           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1668                                            MVT::i1, MachineNode->getOperand(0),
1669                                            MachineNode->getOperand(0));
1670         else if (Op1Unset)
1671           // xor(0, y) = y
1672           ResNode = MachineNode->getOperand(1).getNode();
1673         else if (Op2Unset)
1674           // xor(x, 0) = x
1675           ResNode = MachineNode->getOperand(0).getNode();
1676         else if (Op1Not)
1677           // xor(~x, y) = eqv(x, y)
1678           ResNode = CurDAG->getMachineNode(PPC::CREQV, SDLoc(MachineNode),
1679                                            MVT::i1, MachineNode->getOperand(0).
1680                                                       getOperand(0),
1681                                            MachineNode->getOperand(1));
1682         else if (Op2Not)
1683           // xor(x, ~y) = eqv(x, y)
1684           ResNode = CurDAG->getMachineNode(PPC::CREQV, SDLoc(MachineNode),
1685                                            MVT::i1, MachineNode->getOperand(0),
1686                                            MachineNode->getOperand(1).
1687                                              getOperand(0));
1688         break;
1689       case PPC::CRNOR:
1690         if (Op1Set || Op2Set)
1691           // nor(1, y) -> 0
1692           ResNode = CurDAG->getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
1693                                            MVT::i1);
1694         else if (Op1Unset)
1695           // nor(0, y) = ~y -> nor(y, y)
1696           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1697                                            MVT::i1, MachineNode->getOperand(1),
1698                                            MachineNode->getOperand(1));
1699         else if (Op2Unset)
1700           // nor(x, 0) = ~x
1701           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1702                                            MVT::i1, MachineNode->getOperand(0),
1703                                            MachineNode->getOperand(0));
1704         else if (Op1Not)
1705           // nor(~x, y) = andc(x, y)
1706           ResNode = CurDAG->getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
1707                                            MVT::i1, MachineNode->getOperand(0).
1708                                                       getOperand(0),
1709                                            MachineNode->getOperand(1));
1710         else if (Op2Not)
1711           // nor(x, ~y) = andc(y, x)
1712           ResNode = CurDAG->getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
1713                                            MVT::i1, MachineNode->getOperand(1).
1714                                                       getOperand(0),
1715                                            MachineNode->getOperand(0));
1716         break;
1717       case PPC::CREQV:
1718         if (MachineNode->getOperand(0) == MachineNode->getOperand(1))
1719           // eqv(x, x) = 1
1720           ResNode = CurDAG->getMachineNode(PPC::CRSET, SDLoc(MachineNode),
1721                                            MVT::i1);
1722         else if (Op1Set)
1723           // eqv(1, y) = y
1724           ResNode = MachineNode->getOperand(1).getNode();
1725         else if (Op2Set)
1726           // eqv(x, 1) = x
1727           ResNode = MachineNode->getOperand(0).getNode();
1728         else if (Op1Unset)
1729           // eqv(0, y) = ~y -> nor(y, y)
1730           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1731                                            MVT::i1, MachineNode->getOperand(1),
1732                                            MachineNode->getOperand(1));
1733         else if (Op2Unset)
1734           // eqv(x, 0) = ~x
1735           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1736                                            MVT::i1, MachineNode->getOperand(0),
1737                                            MachineNode->getOperand(0));
1738         else if (Op1Not)
1739           // eqv(~x, y) = xor(x, y)
1740           ResNode = CurDAG->getMachineNode(PPC::CRXOR, SDLoc(MachineNode),
1741                                            MVT::i1, MachineNode->getOperand(0).
1742                                                       getOperand(0),
1743                                            MachineNode->getOperand(1));
1744         else if (Op2Not)
1745           // eqv(x, ~y) = xor(x, y)
1746           ResNode = CurDAG->getMachineNode(PPC::CRXOR, SDLoc(MachineNode),
1747                                            MVT::i1, MachineNode->getOperand(0),
1748                                            MachineNode->getOperand(1).
1749                                              getOperand(0));
1750         break;
1751       case PPC::CRANDC:
1752         if (MachineNode->getOperand(0) == MachineNode->getOperand(1))
1753           // andc(x, x) = 0
1754           ResNode = CurDAG->getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
1755                                            MVT::i1);
1756         else if (Op1Set)
1757           // andc(1, y) = ~y
1758           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1759                                            MVT::i1, MachineNode->getOperand(1),
1760                                            MachineNode->getOperand(1));
1761         else if (Op1Unset || Op2Set)
1762           // andc(0, y) = andc(x, 1) = 0
1763           ResNode = CurDAG->getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
1764                                            MVT::i1);
1765         else if (Op2Unset)
1766           // andc(x, 0) = x
1767           ResNode = MachineNode->getOperand(0).getNode();
1768         else if (Op1Not)
1769           // andc(~x, y) = ~(x | y) = nor(x, y)
1770           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1771                                            MVT::i1, MachineNode->getOperand(0).
1772                                                       getOperand(0),
1773                                            MachineNode->getOperand(1));
1774         else if (Op2Not)
1775           // andc(x, ~y) = x & y
1776           ResNode = CurDAG->getMachineNode(PPC::CRAND, SDLoc(MachineNode),
1777                                            MVT::i1, MachineNode->getOperand(0),
1778                                            MachineNode->getOperand(1).
1779                                              getOperand(0));
1780         break;
1781       case PPC::CRORC:
1782         if (MachineNode->getOperand(0) == MachineNode->getOperand(1))
1783           // orc(x, x) = 1
1784           ResNode = CurDAG->getMachineNode(PPC::CRSET, SDLoc(MachineNode),
1785                                            MVT::i1);
1786         else if (Op1Set || Op2Unset)
1787           // orc(1, y) = orc(x, 0) = 1
1788           ResNode = CurDAG->getMachineNode(PPC::CRSET, SDLoc(MachineNode),
1789                                            MVT::i1);
1790         else if (Op2Set)
1791           // orc(x, 1) = x
1792           ResNode = MachineNode->getOperand(0).getNode();
1793         else if (Op1Unset)
1794           // orc(0, y) = ~y
1795           ResNode = CurDAG->getMachineNode(PPC::CRNOR, SDLoc(MachineNode),
1796                                            MVT::i1, MachineNode->getOperand(1),
1797                                            MachineNode->getOperand(1));
1798         else if (Op1Not)
1799           // orc(~x, y) = ~(x & y) = nand(x, y)
1800           ResNode = CurDAG->getMachineNode(PPC::CRNAND, SDLoc(MachineNode),
1801                                            MVT::i1, MachineNode->getOperand(0).
1802                                                       getOperand(0),
1803                                            MachineNode->getOperand(1));
1804         else if (Op2Not)
1805           // orc(x, ~y) = x | y
1806           ResNode = CurDAG->getMachineNode(PPC::CROR, SDLoc(MachineNode),
1807                                            MVT::i1, MachineNode->getOperand(0),
1808                                            MachineNode->getOperand(1).
1809                                              getOperand(0));
1810         break;
1811       case PPC::SELECT_I4:
1812       case PPC::SELECT_I8:
1813       case PPC::SELECT_F4:
1814       case PPC::SELECT_F8:
1815       case PPC::SELECT_VRRC:
1816         if (Op1Set)
1817           ResNode = MachineNode->getOperand(1).getNode();
1818         else if (Op1Unset)
1819           ResNode = MachineNode->getOperand(2).getNode();
1820         else if (Op1Not)
1821           ResNode = CurDAG->getMachineNode(MachineNode->getMachineOpcode(),
1822                                            SDLoc(MachineNode),
1823                                            MachineNode->getValueType(0),
1824                                            MachineNode->getOperand(0).
1825                                              getOperand(0),
1826                                            MachineNode->getOperand(2),
1827                                            MachineNode->getOperand(1));
1828         break;
1829       case PPC::BC:
1830       case PPC::BCn:
1831         if (Op1Not)
1832           ResNode = CurDAG->getMachineNode(Opcode == PPC::BC ? PPC::BCn :
1833                                                                PPC::BC,
1834                                            SDLoc(MachineNode),
1835                                            MVT::Other,
1836                                            MachineNode->getOperand(0).
1837                                              getOperand(0),
1838                                            MachineNode->getOperand(1),
1839                                            MachineNode->getOperand(2));
1840         // FIXME: Handle Op1Set, Op1Unset here too.
1841         break;
1842       }
1843
1844       if (ResNode != MachineNode) {
1845         DEBUG(dbgs() << "CR Peephole replacing:\nOld:    ");
1846         DEBUG(MachineNode->dump(CurDAG));
1847         DEBUG(dbgs() << "\nNew: ");
1848         DEBUG(ResNode->dump(CurDAG));
1849         DEBUG(dbgs() << "\n");
1850
1851         ReplaceUses(MachineNode, ResNode);
1852         IsModified = true;
1853       }
1854     }
1855     if (IsModified)
1856       CurDAG->RemoveDeadNodes();
1857   } while (IsModified);
1858 }
1859
1860 void PPCDAGToDAGISel::PeepholePPC64() {
1861   // These optimizations are currently supported only for 64-bit SVR4.
1862   if (PPCSubTarget.isDarwin() || !PPCSubTarget.isPPC64())
1863     return;
1864
1865   SelectionDAG::allnodes_iterator Position(CurDAG->getRoot().getNode());
1866   ++Position;
1867
1868   while (Position != CurDAG->allnodes_begin()) {
1869     SDNode *N = --Position;
1870     // Skip dead nodes and any non-machine opcodes.
1871     if (N->use_empty() || !N->isMachineOpcode())
1872       continue;
1873
1874     unsigned FirstOp;
1875     unsigned StorageOpcode = N->getMachineOpcode();
1876
1877     switch (StorageOpcode) {
1878     default: continue;
1879
1880     case PPC::LBZ:
1881     case PPC::LBZ8:
1882     case PPC::LD:
1883     case PPC::LFD:
1884     case PPC::LFS:
1885     case PPC::LHA:
1886     case PPC::LHA8:
1887     case PPC::LHZ:
1888     case PPC::LHZ8:
1889     case PPC::LWA:
1890     case PPC::LWZ:
1891     case PPC::LWZ8:
1892       FirstOp = 0;
1893       break;
1894
1895     case PPC::STB:
1896     case PPC::STB8:
1897     case PPC::STD:
1898     case PPC::STFD:
1899     case PPC::STFS:
1900     case PPC::STH:
1901     case PPC::STH8:
1902     case PPC::STW:
1903     case PPC::STW8:
1904       FirstOp = 1;
1905       break;
1906     }
1907
1908     // If this is a load or store with a zero offset, we may be able to
1909     // fold an add-immediate into the memory operation.
1910     if (!isa<ConstantSDNode>(N->getOperand(FirstOp)) ||
1911         N->getConstantOperandVal(FirstOp) != 0)
1912       continue;
1913
1914     SDValue Base = N->getOperand(FirstOp + 1);
1915     if (!Base.isMachineOpcode())
1916       continue;
1917
1918     unsigned Flags = 0;
1919     bool ReplaceFlags = true;
1920
1921     // When the feeding operation is an add-immediate of some sort,
1922     // determine whether we need to add relocation information to the
1923     // target flags on the immediate operand when we fold it into the
1924     // load instruction.
1925     //
1926     // For something like ADDItocL, the relocation information is
1927     // inferred from the opcode; when we process it in the AsmPrinter,
1928     // we add the necessary relocation there.  A load, though, can receive
1929     // relocation from various flavors of ADDIxxx, so we need to carry
1930     // the relocation information in the target flags.
1931     switch (Base.getMachineOpcode()) {
1932     default: continue;
1933
1934     case PPC::ADDI8:
1935     case PPC::ADDI:
1936       // In some cases (such as TLS) the relocation information
1937       // is already in place on the operand, so copying the operand
1938       // is sufficient.
1939       ReplaceFlags = false;
1940       // For these cases, the immediate may not be divisible by 4, in
1941       // which case the fold is illegal for DS-form instructions.  (The
1942       // other cases provide aligned addresses and are always safe.)
1943       if ((StorageOpcode == PPC::LWA ||
1944            StorageOpcode == PPC::LD  ||
1945            StorageOpcode == PPC::STD) &&
1946           (!isa<ConstantSDNode>(Base.getOperand(1)) ||
1947            Base.getConstantOperandVal(1) % 4 != 0))
1948         continue;
1949       break;
1950     case PPC::ADDIdtprelL:
1951       Flags = PPCII::MO_DTPREL_LO;
1952       break;
1953     case PPC::ADDItlsldL:
1954       Flags = PPCII::MO_TLSLD_LO;
1955       break;
1956     case PPC::ADDItocL:
1957       Flags = PPCII::MO_TOC_LO;
1958       break;
1959     }
1960
1961     // We found an opportunity.  Reverse the operands from the add
1962     // immediate and substitute them into the load or store.  If
1963     // needed, update the target flags for the immediate operand to
1964     // reflect the necessary relocation information.
1965     DEBUG(dbgs() << "Folding add-immediate into mem-op:\nBase:    ");
1966     DEBUG(Base->dump(CurDAG));
1967     DEBUG(dbgs() << "\nN: ");
1968     DEBUG(N->dump(CurDAG));
1969     DEBUG(dbgs() << "\n");
1970
1971     SDValue ImmOpnd = Base.getOperand(1);
1972
1973     // If the relocation information isn't already present on the
1974     // immediate operand, add it now.
1975     if (ReplaceFlags) {
1976       if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(ImmOpnd)) {
1977         SDLoc dl(GA);
1978         const GlobalValue *GV = GA->getGlobal();
1979         // We can't perform this optimization for data whose alignment
1980         // is insufficient for the instruction encoding.
1981         if (GV->getAlignment() < 4 &&
1982             (StorageOpcode == PPC::LD || StorageOpcode == PPC::STD ||
1983              StorageOpcode == PPC::LWA)) {
1984           DEBUG(dbgs() << "Rejected this candidate for alignment.\n\n");
1985           continue;
1986         }
1987         ImmOpnd = CurDAG->getTargetGlobalAddress(GV, dl, MVT::i64, 0, Flags);
1988       } else if (ConstantPoolSDNode *CP =
1989                  dyn_cast<ConstantPoolSDNode>(ImmOpnd)) {
1990         const Constant *C = CP->getConstVal();
1991         ImmOpnd = CurDAG->getTargetConstantPool(C, MVT::i64,
1992                                                 CP->getAlignment(),
1993                                                 0, Flags);
1994       }
1995     }
1996
1997     if (FirstOp == 1) // Store
1998       (void)CurDAG->UpdateNodeOperands(N, N->getOperand(0), ImmOpnd,
1999                                        Base.getOperand(0), N->getOperand(3));
2000     else // Load
2001       (void)CurDAG->UpdateNodeOperands(N, ImmOpnd, Base.getOperand(0),
2002                                        N->getOperand(2));
2003
2004     // The add-immediate may now be dead, in which case remove it.
2005     if (Base.getNode()->use_empty())
2006       CurDAG->RemoveDeadNode(Base.getNode());
2007   }
2008 }
2009
2010
2011 /// createPPCISelDag - This pass converts a legalized DAG into a
2012 /// PowerPC-specific DAG, ready for instruction scheduling.
2013 ///
2014 FunctionPass *llvm::createPPCISelDag(PPCTargetMachine &TM) {
2015   return new PPCDAGToDAGISel(TM);
2016 }
2017
2018 static void initializePassOnce(PassRegistry &Registry) {
2019   const char *Name = "PowerPC DAG->DAG Pattern Instruction Selection";
2020   PassInfo *PI = new PassInfo(Name, "ppc-codegen", &SelectionDAGISel::ID, 0,
2021                               false, false);
2022   Registry.registerPass(*PI, true);
2023 }
2024
2025 void llvm::initializePPCDAGToDAGISelPass(PassRegistry &Registry) {
2026   CALL_ONCE_INITIALIZATION(initializePassOnce);
2027 }
2028