Move a few containers out of ScheduleDAGInstrs::BuildSchedGraph
[oota-llvm.git] / lib / Target / IA64 / IA64ISelDAGToDAG.cpp
1 //===---- IA64ISelDAGToDAG.cpp - IA64 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 IA64,
11 // converting a legalized dag to an IA64 dag.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #define DEBUG_TYPE "ia64-codegen"
16 #include "IA64.h"
17 #include "IA64TargetMachine.h"
18 #include "IA64ISelLowering.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/SelectionDAG.h"
22 #include "llvm/CodeGen/SelectionDAGISel.h"
23 #include "llvm/Target/TargetOptions.h"
24 #include "llvm/Constants.h"
25 #include "llvm/GlobalValue.h"
26 #include "llvm/Intrinsics.h"
27 #include "llvm/Support/Compiler.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/MathExtras.h"
30 using namespace llvm;
31
32 namespace {
33   //===--------------------------------------------------------------------===//
34   /// IA64DAGToDAGISel - IA64 specific code to select IA64 machine
35   /// instructions for SelectionDAG operations.
36   ///
37   class IA64DAGToDAGISel : public SelectionDAGISel {
38     unsigned GlobalBaseReg;
39   public:
40     explicit IA64DAGToDAGISel(IA64TargetMachine &TM)
41       : SelectionDAGISel(TM) {}
42     
43     virtual bool runOnFunction(Function &Fn) {
44       // Make sure we re-emit a set of the global base reg if necessary
45       GlobalBaseReg = 0;
46       return SelectionDAGISel::runOnFunction(Fn);
47     }
48  
49     /// getI64Imm - Return a target constant with the specified value, of type
50     /// i64.
51     inline SDValue getI64Imm(uint64_t Imm) {
52       return CurDAG->getTargetConstant(Imm, MVT::i64);
53     }
54
55     /// getGlobalBaseReg - insert code into the entry mbb to materialize the PIC
56     /// base register.  Return the virtual register that holds this value.
57     // SDValue getGlobalBaseReg(); TODO: hmm
58     
59     // Select - Convert the specified operand from a target-independent to a
60     // target-specific node if it hasn't already been changed.
61     SDNode *Select(SDValue N);
62     
63     SDNode *SelectIntImmediateExpr(SDValue LHS, SDValue RHS,
64                                    unsigned OCHi, unsigned OCLo,
65                                    bool IsArithmetic = false,
66                                    bool Negate = false);
67     SDNode *SelectBitfieldInsert(SDNode *N);
68
69     /// SelectCC - Select a comparison of the specified values with the
70     /// specified condition code, returning the CR# of the expression.
71     SDValue SelectCC(SDValue LHS, SDValue RHS, ISD::CondCode CC);
72
73     /// SelectAddr - Given the specified address, return the two operands for a
74     /// load/store instruction, and return true if it should be an indexed [r+r]
75     /// operation.
76     bool SelectAddr(SDValue Addr, SDValue &Op1, SDValue &Op2);
77
78     /// InstructionSelect - This callback is invoked by
79     /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
80     virtual void InstructionSelect();
81     
82     virtual const char *getPassName() const {
83       return "IA64 (Itanium) DAG->DAG Instruction Selector";
84     } 
85
86 // Include the pieces autogenerated from the target description.
87 #include "IA64GenDAGISel.inc"
88     
89 private:
90     SDNode *SelectDIV(SDValue Op);
91   };
92 }
93
94 /// InstructionSelect - This callback is invoked by
95 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
96 void IA64DAGToDAGISel::InstructionSelect() {
97   DEBUG(BB->dump());
98
99   // Select target instructions for the DAG.
100   SelectRoot(*CurDAG);
101   CurDAG->RemoveDeadNodes();
102 }
103
104 SDNode *IA64DAGToDAGISel::SelectDIV(SDValue Op) {
105   SDNode *N = Op.getNode();
106   SDValue Chain = N->getOperand(0);
107   SDValue Tmp1 = N->getOperand(0);
108   SDValue Tmp2 = N->getOperand(1);
109
110   bool isFP=false;
111
112   if(Tmp1.getValueType().isFloatingPoint())
113     isFP=true;
114     
115   bool isModulus=false; // is it a division or a modulus?
116   bool isSigned=false;
117
118   switch(N->getOpcode()) {
119     case ISD::FDIV:
120     case ISD::SDIV:  isModulus=false; isSigned=true;  break;
121     case ISD::UDIV:  isModulus=false; isSigned=false; break;
122     case ISD::FREM:
123     case ISD::SREM:  isModulus=true;  isSigned=true;  break;
124     case ISD::UREM:  isModulus=true;  isSigned=false; break;
125   }
126
127   // TODO: check for integer divides by powers of 2 (or other simple patterns?)
128
129     SDValue TmpPR, TmpPR2;
130     SDValue TmpF1, TmpF2, TmpF3, TmpF4, TmpF5, TmpF6, TmpF7, TmpF8;
131     SDValue TmpF9, TmpF10,TmpF11,TmpF12,TmpF13,TmpF14,TmpF15;
132     SDNode *Result;
133
134     // we'll need copies of F0 and F1
135     SDValue F0 = CurDAG->getRegister(IA64::F0, MVT::f64);
136     SDValue F1 = CurDAG->getRegister(IA64::F1, MVT::f64);
137     
138     // OK, emit some code:
139
140     if(!isFP) {
141       // first, load the inputs into FP regs.
142       TmpF1 =
143         SDValue(CurDAG->getTargetNode(IA64::SETFSIG, MVT::f64, Tmp1), 0);
144       Chain = TmpF1.getValue(1);
145       TmpF2 =
146         SDValue(CurDAG->getTargetNode(IA64::SETFSIG, MVT::f64, Tmp2), 0);
147       Chain = TmpF2.getValue(1);
148       
149       // next, convert the inputs to FP
150       if(isSigned) {
151         TmpF3 =
152           SDValue(CurDAG->getTargetNode(IA64::FCVTXF, MVT::f64, TmpF1), 0);
153         Chain = TmpF3.getValue(1);
154         TmpF4 =
155           SDValue(CurDAG->getTargetNode(IA64::FCVTXF, MVT::f64, TmpF2), 0);
156         Chain = TmpF4.getValue(1);
157       } else { // is unsigned
158         TmpF3 =
159           SDValue(CurDAG->getTargetNode(IA64::FCVTXUFS1, MVT::f64, TmpF1), 0);
160         Chain = TmpF3.getValue(1);
161         TmpF4 =
162           SDValue(CurDAG->getTargetNode(IA64::FCVTXUFS1, MVT::f64, TmpF2), 0);
163         Chain = TmpF4.getValue(1);
164       }
165
166     } else { // this is an FP divide/remainder, so we 'leak' some temp
167              // regs and assign TmpF3=Tmp1, TmpF4=Tmp2
168       TmpF3=Tmp1;
169       TmpF4=Tmp2;
170     }
171
172     // we start by computing an approximate reciprocal (good to 9 bits?)
173     // note, this instruction writes _both_ TmpF5 (answer) and TmpPR (predicate)
174     if(isFP)
175       TmpF5 = SDValue(CurDAG->getTargetNode(IA64::FRCPAS0, MVT::f64, MVT::i1,
176                                               TmpF3, TmpF4), 0);
177     else
178       TmpF5 = SDValue(CurDAG->getTargetNode(IA64::FRCPAS1, MVT::f64, MVT::i1,
179                                               TmpF3, TmpF4), 0);
180                                   
181     TmpPR = TmpF5.getValue(1);
182     Chain = TmpF5.getValue(2);
183
184     SDValue minusB;
185     if(isModulus) { // for remainders, it'll be handy to have
186                              // copies of -input_b
187       minusB = SDValue(CurDAG->getTargetNode(IA64::SUB, MVT::i64,
188                   CurDAG->getRegister(IA64::r0, MVT::i64), Tmp2), 0);
189       Chain = minusB.getValue(1);
190     }
191     
192     SDValue TmpE0, TmpY1, TmpE1, TmpY2;
193
194     SDValue OpsE0[] = { TmpF4, TmpF5, F1, TmpPR };
195     TmpE0 = SDValue(CurDAG->getTargetNode(IA64::CFNMAS1, MVT::f64,
196                                             OpsE0, 4), 0);
197     Chain = TmpE0.getValue(1);
198     SDValue OpsY1[] = { TmpF5, TmpE0, TmpF5, TmpPR };
199     TmpY1 = SDValue(CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
200                                             OpsY1, 4), 0);
201     Chain = TmpY1.getValue(1);
202     SDValue OpsE1[] = { TmpE0, TmpE0, F0, TmpPR };
203     TmpE1 = SDValue(CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
204                                             OpsE1, 4), 0);
205     Chain = TmpE1.getValue(1);
206     SDValue OpsY2[] = { TmpY1, TmpE1, TmpY1, TmpPR };
207     TmpY2 = SDValue(CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
208                                             OpsY2, 4), 0);
209     Chain = TmpY2.getValue(1);
210     
211     if(isFP) { // if this is an FP divide, we finish up here and exit early
212       if(isModulus)
213         assert(0 && "Sorry, try another FORTRAN compiler.");
214  
215       SDValue TmpE2, TmpY3, TmpQ0, TmpR0;
216
217       SDValue OpsE2[] = { TmpE1, TmpE1, F0, TmpPR };
218       TmpE2 = SDValue(CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
219                                               OpsE2, 4), 0);
220       Chain = TmpE2.getValue(1);
221       SDValue OpsY3[] = { TmpY2, TmpE2, TmpY2, TmpPR };
222       TmpY3 = SDValue(CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
223                                               OpsY3, 4), 0);
224       Chain = TmpY3.getValue(1);
225       SDValue OpsQ0[] = { Tmp1, TmpY3, F0, TmpPR };
226       TmpQ0 =
227         SDValue(CurDAG->getTargetNode(IA64::CFMADS1, MVT::f64, // double prec!
228                                         OpsQ0, 4), 0);
229       Chain = TmpQ0.getValue(1);
230       SDValue OpsR0[] = { Tmp2, TmpQ0, Tmp1, TmpPR };
231       TmpR0 =
232         SDValue(CurDAG->getTargetNode(IA64::CFNMADS1, MVT::f64, // double prec!
233                                         OpsR0, 4), 0);
234       Chain = TmpR0.getValue(1);
235
236 // we want Result to have the same target register as the frcpa, so
237 // we two-address hack it. See the comment "for this to work..." on
238 // page 48 of Intel application note #245415
239       SDValue Ops[] = { TmpF5, TmpY3, TmpR0, TmpQ0, TmpPR };
240       Result = CurDAG->getTargetNode(IA64::TCFMADS0, MVT::f64, // d.p. s0 rndg!
241                                      Ops, 5);
242       Chain = SDValue(Result, 1);
243       return Result; // XXX: early exit!
244     } else { // this is *not* an FP divide, so there's a bit left to do:
245     
246       SDValue TmpQ2, TmpR2, TmpQ3, TmpQ;
247
248       SDValue OpsQ2[] = { TmpF3, TmpY2, F0, TmpPR };
249       TmpQ2 = SDValue(CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
250                                               OpsQ2, 4), 0);
251       Chain = TmpQ2.getValue(1);
252       SDValue OpsR2[] = { TmpF4, TmpQ2, TmpF3, TmpPR };
253       TmpR2 = SDValue(CurDAG->getTargetNode(IA64::CFNMAS1, MVT::f64,
254                                               OpsR2, 4), 0);
255       Chain = TmpR2.getValue(1);
256       
257 // we want TmpQ3 to have the same target register as the frcpa? maybe we
258 // should two-address hack it. See the comment "for this to work..." on page
259 // 48 of Intel application note #245415
260       SDValue OpsQ3[] = { TmpF5, TmpR2, TmpY2, TmpQ2, TmpPR };
261       TmpQ3 = SDValue(CurDAG->getTargetNode(IA64::TCFMAS1, MVT::f64,
262                                          OpsQ3, 5), 0);
263       Chain = TmpQ3.getValue(1);
264
265       // STORY: without these two-address instructions (TCFMAS1 and TCFMADS0)
266       // the FPSWA won't be able to help out in the case of large/tiny
267       // arguments. Other fun bugs may also appear, e.g. 0/x = x, not 0.
268       
269       if(isSigned)
270         TmpQ = SDValue(CurDAG->getTargetNode(IA64::FCVTFXTRUNCS1,
271                                                MVT::f64, TmpQ3), 0);
272       else
273         TmpQ = SDValue(CurDAG->getTargetNode(IA64::FCVTFXUTRUNCS1,
274                                                MVT::f64, TmpQ3), 0);
275       
276       Chain = TmpQ.getValue(1);
277
278       if(isModulus) {
279         SDValue FPminusB =
280           SDValue(CurDAG->getTargetNode(IA64::SETFSIG, MVT::f64, minusB), 0);
281         Chain = FPminusB.getValue(1);
282         SDValue Remainder =
283           SDValue(CurDAG->getTargetNode(IA64::XMAL, MVT::f64,
284                                           TmpQ, FPminusB, TmpF1), 0);
285         Chain = Remainder.getValue(1);
286         Result = CurDAG->getTargetNode(IA64::GETFSIG, MVT::i64, Remainder);
287         Chain = SDValue(Result, 1);
288       } else { // just an integer divide
289         Result = CurDAG->getTargetNode(IA64::GETFSIG, MVT::i64, TmpQ);
290         Chain = SDValue(Result, 1);
291       }
292
293       return Result;
294     } // wasn't an FP divide
295 }
296
297 // Select - Convert the specified operand from a target-independent to a
298 // target-specific node if it hasn't already been changed.
299 SDNode *IA64DAGToDAGISel::Select(SDValue Op) {
300   SDNode *N = Op.getNode();
301   if (N->isMachineOpcode())
302     return NULL;   // Already selected.
303
304   switch (N->getOpcode()) {
305   default: break;
306
307   case IA64ISD::BRCALL: { // XXX: this is also a hack!
308     SDValue Chain = N->getOperand(0);
309     SDValue InFlag;  // Null incoming flag value.
310
311     if(N->getNumOperands()==3) { // we have an incoming chain, callee and flag
312       InFlag = N->getOperand(2);
313     }
314
315     unsigned CallOpcode;
316     SDValue CallOperand;
317     
318     // if we can call directly, do so
319     if (GlobalAddressSDNode *GASD =
320       dyn_cast<GlobalAddressSDNode>(N->getOperand(1))) {
321       CallOpcode = IA64::BRCALL_IPREL_GA;
322       CallOperand = CurDAG->getTargetGlobalAddress(GASD->getGlobal(), MVT::i64);
323     } else if (isa<ExternalSymbolSDNode>(N->getOperand(1))) {
324       // FIXME: we currently NEED this case for correctness, to avoid
325       // "non-pic code with imm reloc.n against dynamic symbol" errors
326     CallOpcode = IA64::BRCALL_IPREL_ES;
327     CallOperand = N->getOperand(1);
328   } else {
329     // otherwise we need to load the function descriptor,
330     // load the branch target (function)'s entry point and GP,
331     // branch (call) then restore the GP
332     SDValue FnDescriptor = N->getOperand(1);
333    
334     // load the branch target's entry point [mem] and 
335     // GP value [mem+8]
336     SDValue targetEntryPoint=
337       SDValue(CurDAG->getTargetNode(IA64::LD8, MVT::i64, MVT::Other,
338                                       FnDescriptor, CurDAG->getEntryNode()), 0);
339     Chain = targetEntryPoint.getValue(1);
340     SDValue targetGPAddr=
341       SDValue(CurDAG->getTargetNode(IA64::ADDS, MVT::i64, 
342                                       FnDescriptor,
343                                       CurDAG->getConstant(8, MVT::i64)), 0);
344     Chain = targetGPAddr.getValue(1);
345     SDValue targetGP =
346       SDValue(CurDAG->getTargetNode(IA64::LD8, MVT::i64,MVT::Other,
347                                       targetGPAddr, CurDAG->getEntryNode()), 0);
348     Chain = targetGP.getValue(1);
349
350     Chain = CurDAG->getCopyToReg(Chain, IA64::r1, targetGP, InFlag);
351     InFlag = Chain.getValue(1);
352     Chain = CurDAG->getCopyToReg(Chain, IA64::B6,
353                                  targetEntryPoint, InFlag); // FLAG these?
354     InFlag = Chain.getValue(1);
355     
356     CallOperand = CurDAG->getRegister(IA64::B6, MVT::i64);
357     CallOpcode = IA64::BRCALL_INDIRECT;
358   }
359  
360    // Finally, once everything is setup, emit the call itself
361    if (InFlag.getNode())
362      Chain = SDValue(CurDAG->getTargetNode(CallOpcode, MVT::Other, MVT::Flag,
363                                              CallOperand, InFlag), 0);
364    else // there might be no arguments
365      Chain = SDValue(CurDAG->getTargetNode(CallOpcode, MVT::Other, MVT::Flag,
366                                              CallOperand, Chain), 0);
367    InFlag = Chain.getValue(1);
368
369    std::vector<SDValue> CallResults;
370
371    CallResults.push_back(Chain);
372    CallResults.push_back(InFlag);
373
374    for (unsigned i = 0, e = CallResults.size(); i != e; ++i)
375      ReplaceUses(Op.getValue(i), CallResults[i]);
376    return NULL;
377   }
378   
379   case IA64ISD::GETFD: {
380     SDValue Input = N->getOperand(0);
381     return CurDAG->getTargetNode(IA64::GETFD, MVT::i64, Input);
382   } 
383   
384   case ISD::FDIV:
385   case ISD::SDIV:
386   case ISD::UDIV:
387   case ISD::SREM:
388   case ISD::UREM:
389     return SelectDIV(Op);
390  
391   case ISD::TargetConstantFP: {
392     SDValue Chain = CurDAG->getEntryNode(); // this is a constant, so..
393
394     SDValue V;
395     ConstantFPSDNode* N2 = cast<ConstantFPSDNode>(N);
396     if (N2->getValueAPF().isPosZero()) {
397       V = CurDAG->getCopyFromReg(Chain, IA64::F0, MVT::f64);
398     } else if (N2->isExactlyValue(N2->getValueType(0) == MVT::f32 ? 
399                                   APFloat(+1.0f) : APFloat(+1.0))) {
400       V = CurDAG->getCopyFromReg(Chain, IA64::F1, MVT::f64);
401     } else
402       assert(0 && "Unexpected FP constant!");
403     
404     ReplaceUses(SDValue(N, 0), V);
405     return 0;
406   }
407
408   case ISD::FrameIndex: { // TODO: reduce creepyness
409     int FI = cast<FrameIndexSDNode>(N)->getIndex();
410     if (N->hasOneUse())
411       return CurDAG->SelectNodeTo(N, IA64::MOV, MVT::i64,
412                                   CurDAG->getTargetFrameIndex(FI, MVT::i64));
413     else
414       return CurDAG->getTargetNode(IA64::MOV, MVT::i64,
415                                    CurDAG->getTargetFrameIndex(FI, MVT::i64));
416   }
417
418   case ISD::ConstantPool: { // TODO: nuke the constant pool
419     // (ia64 doesn't need one)
420     ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(N);
421     Constant *C = CP->getConstVal();
422     SDValue CPI = CurDAG->getTargetConstantPool(C, MVT::i64,
423                                                   CP->getAlignment());
424     return CurDAG->getTargetNode(IA64::ADDL_GA, MVT::i64, // ?
425                                  CurDAG->getRegister(IA64::r1, MVT::i64), CPI);
426   }
427
428   case ISD::GlobalAddress: {
429     GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal();
430     SDValue GA = CurDAG->getTargetGlobalAddress(GV, MVT::i64);
431     SDValue Tmp =
432       SDValue(CurDAG->getTargetNode(IA64::ADDL_GA, MVT::i64, 
433                                       CurDAG->getRegister(IA64::r1,
434                                                           MVT::i64), GA), 0);
435     return CurDAG->getTargetNode(IA64::LD8, MVT::i64, MVT::Other, Tmp,
436                                  CurDAG->getEntryNode());
437   }
438   
439 /* XXX
440    case ISD::ExternalSymbol: {
441      SDValue EA = CurDAG->getTargetExternalSymbol(
442        cast<ExternalSymbolSDNode>(N)->getSymbol(),
443        MVT::i64);
444      SDValue Tmp = CurDAG->getTargetNode(IA64::ADDL_EA, MVT::i64, 
445                                            CurDAG->getRegister(IA64::r1,
446                                                                MVT::i64),
447                                            EA);
448      return CurDAG->getTargetNode(IA64::LD8, MVT::i64, Tmp);
449    }
450 */
451
452   case ISD::LOAD: { // FIXME: load -1, not 1, for bools?
453     LoadSDNode *LD = cast<LoadSDNode>(N);
454     SDValue Chain = LD->getChain();
455     SDValue Address = LD->getBasePtr();
456
457     MVT TypeBeingLoaded = LD->getMemoryVT();
458     unsigned Opc;
459     switch (TypeBeingLoaded.getSimpleVT()) {
460     default:
461 #ifndef NDEBUG
462       N->dump(CurDAG);
463 #endif
464       assert(0 && "Cannot load this type!");
465     case MVT::i1: { // this is a bool
466       Opc = IA64::LD1; // first we load a byte, then compare for != 0
467       if(N->getValueType(0) == MVT::i1) { // XXX: early exit!
468         return CurDAG->SelectNodeTo(N, IA64::CMPNE, MVT::i1, MVT::Other, 
469                     SDValue(CurDAG->getTargetNode(Opc, MVT::i64, Address), 0),
470                                     CurDAG->getRegister(IA64::r0, MVT::i64), 
471                                     Chain);
472       }
473       /* otherwise, we want to load a bool into something bigger: LD1
474          will do that for us, so we just fall through */
475     }
476     case MVT::i8:  Opc = IA64::LD1; break;
477     case MVT::i16: Opc = IA64::LD2; break;
478     case MVT::i32: Opc = IA64::LD4; break;
479     case MVT::i64: Opc = IA64::LD8; break;
480     
481     case MVT::f32: Opc = IA64::LDF4; break;
482     case MVT::f64: Opc = IA64::LDF8; break;
483     }
484
485     // TODO: comment this
486     return CurDAG->SelectNodeTo(N, Opc, N->getValueType(0), MVT::Other,
487                                 Address, Chain);
488   }
489   
490   case ISD::STORE: {
491     StoreSDNode *ST = cast<StoreSDNode>(N);
492     SDValue Address = ST->getBasePtr();
493     SDValue Chain = ST->getChain();
494    
495     unsigned Opc;
496     if (ISD::isNON_TRUNCStore(N)) {
497       switch (N->getOperand(1).getValueType().getSimpleVT()) {
498       default: assert(0 && "unknown type in store");
499       case MVT::i1: { // this is a bool
500         Opc = IA64::ST1; // we store either 0 or 1 as a byte 
501         // first load zero!
502         SDValue Initial = CurDAG->getCopyFromReg(Chain, IA64::r0, MVT::i64);
503         Chain = Initial.getValue(1);
504         // then load 1 into the same reg iff the predicate to store is 1
505         SDValue Tmp = ST->getValue();
506         Tmp =
507           SDValue(CurDAG->getTargetNode(IA64::TPCADDS, MVT::i64, Initial,
508                                           CurDAG->getTargetConstant(1,
509                                                                     MVT::i64),
510                                           Tmp), 0);
511         return CurDAG->SelectNodeTo(N, Opc, MVT::Other, Address, Tmp, Chain);
512       }
513       case MVT::i64: Opc = IA64::ST8;  break;
514       case MVT::f64: Opc = IA64::STF8; break;
515       }
516     } else { // Truncating store
517       switch(ST->getMemoryVT().getSimpleVT()) {
518       default: assert(0 && "unknown type in truncstore");
519       case MVT::i8:  Opc = IA64::ST1;  break;
520       case MVT::i16: Opc = IA64::ST2;  break;
521       case MVT::i32: Opc = IA64::ST4;  break;
522       case MVT::f32: Opc = IA64::STF4; break;
523       }
524     }
525     
526     SDValue N1 = N->getOperand(1);
527     SDValue N2 = N->getOperand(2);
528     return CurDAG->SelectNodeTo(N, Opc, MVT::Other, N2, N1, Chain);
529   }
530
531   case ISD::BRCOND: {
532     SDValue Chain = N->getOperand(0);
533     SDValue CC = N->getOperand(1);
534     MachineBasicBlock *Dest =
535       cast<BasicBlockSDNode>(N->getOperand(2))->getBasicBlock();
536     //FIXME - we do NOT need long branches all the time
537     return CurDAG->SelectNodeTo(N, IA64::BRLCOND_NOTCALL, MVT::Other, CC, 
538                                 CurDAG->getBasicBlock(Dest), Chain);
539   }
540
541   case ISD::CALLSEQ_START:
542   case ISD::CALLSEQ_END: {
543     int64_t Amt = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
544     unsigned Opc = N->getOpcode() == ISD::CALLSEQ_START ?
545       IA64::ADJUSTCALLSTACKDOWN : IA64::ADJUSTCALLSTACKUP;
546     SDValue N0 = N->getOperand(0);
547     return CurDAG->SelectNodeTo(N, Opc, MVT::Other, getI64Imm(Amt), N0);
548   }
549
550   case ISD::BR:
551     // FIXME: we don't need long branches all the time!
552     SDValue N0 = N->getOperand(0);
553     return CurDAG->SelectNodeTo(N, IA64::BRL_NOTCALL, MVT::Other, 
554                                 N->getOperand(1), N0);
555   }
556   
557   return SelectCode(Op);
558 }
559
560
561 /// createIA64DAGToDAGInstructionSelector - This pass converts a legalized DAG
562 /// into an IA64-specific DAG, ready for instruction scheduling.
563 ///
564 FunctionPass
565 *llvm::createIA64DAGToDAGInstructionSelector(IA64TargetMachine &TM) {
566   return new IA64DAGToDAGISel(TM);
567 }
568