e50ff1c9912366e2aaf2592e30f384d09af57aca
[oota-llvm.git] / lib / CodeGen / SelectionDAG / LegalizeFloatTypes.cpp
1 //===-------- LegalizeFloatTypes.cpp - Legalization of float types --------===//
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 implements float type expansion and softening for LegalizeTypes.
11 // Softening is the act of turning a computation in an illegal floating point
12 // type into a computation in an integer type of the same size; also known as
13 // "soft float".  For example, turning f32 arithmetic into operations using i32.
14 // The resulting integer value is the same as what you would get by performing
15 // the floating point operation and bitcasting the result to the integer type.
16 // Expansion is the act of changing a computation in an illegal type to be a
17 // computation in two identical registers of a smaller type.  For example,
18 // implementing ppcf128 arithmetic in two f64 registers.
19 //
20 //===----------------------------------------------------------------------===//
21
22 #include "LegalizeTypes.h"
23 using namespace llvm;
24
25 /// GetFPLibCall - Return the right libcall for the given floating point type.
26 static RTLIB::Libcall GetFPLibCall(MVT VT,
27                                    RTLIB::Libcall Call_F32,
28                                    RTLIB::Libcall Call_F64,
29                                    RTLIB::Libcall Call_F80,
30                                    RTLIB::Libcall Call_PPCF128) {
31   return
32     VT == MVT::f32 ? Call_F32 :
33     VT == MVT::f64 ? Call_F64 :
34     VT == MVT::f80 ? Call_F80 :
35     VT == MVT::ppcf128 ? Call_PPCF128 :
36     RTLIB::UNKNOWN_LIBCALL;
37 }
38
39 //===----------------------------------------------------------------------===//
40 //  Result Float to Integer Conversion.
41 //===----------------------------------------------------------------------===//
42
43 void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
44   DEBUG(cerr << "Soften float result " << ResNo << ": "; N->dump(&DAG);
45         cerr << "\n");
46   SDOperand R = SDOperand();
47
48   switch (N->getOpcode()) {
49   default:
50 #ifndef NDEBUG
51     cerr << "SoftenFloatResult #" << ResNo << ": ";
52     N->dump(&DAG); cerr << "\n";
53 #endif
54     assert(0 && "Do not know how to soften the result of this operator!");
55     abort();
56
57     case ISD::BIT_CONVERT: R = SoftenFloatRes_BIT_CONVERT(N); break;
58     case ISD::BUILD_PAIR:  R = SoftenFloatRes_BUILD_PAIR(N); break;
59     case ISD::ConstantFP:
60       R = SoftenFloatRes_ConstantFP(cast<ConstantFPSDNode>(N));
61       break;
62     case ISD::FADD:        R = SoftenFloatRes_FADD(N); break;
63     case ISD::FCOPYSIGN:   R = SoftenFloatRes_FCOPYSIGN(N); break;
64     case ISD::FDIV:        R = SoftenFloatRes_FDIV(N); break;
65     case ISD::FMUL:        R = SoftenFloatRes_FMUL(N); break;
66     case ISD::FP_EXTEND:   R = SoftenFloatRes_FP_EXTEND(N); break;
67     case ISD::FP_ROUND:    R = SoftenFloatRes_FP_ROUND(N); break;
68     case ISD::FPOWI:       R = SoftenFloatRes_FPOWI(N); break;
69     case ISD::FSUB:        R = SoftenFloatRes_FSUB(N); break;
70     case ISD::LOAD:        R = SoftenFloatRes_LOAD(N); break;
71     case ISD::SELECT:      R = SoftenFloatRes_SELECT(N); break;
72     case ISD::SELECT_CC:   R = SoftenFloatRes_SELECT_CC(N); break;
73     case ISD::SINT_TO_FP:  R = SoftenFloatRes_SINT_TO_FP(N); break;
74     case ISD::UINT_TO_FP:  R = SoftenFloatRes_UINT_TO_FP(N); break;
75   }
76
77   // If R is null, the sub-method took care of registering the result.
78   if (R.Val)
79     SetSoftenedFloat(SDOperand(N, ResNo), R);
80 }
81
82 SDOperand DAGTypeLegalizer::SoftenFloatRes_BIT_CONVERT(SDNode *N) {
83   return BitConvertToInteger(N->getOperand(0));
84 }
85
86 SDOperand DAGTypeLegalizer::SoftenFloatRes_BUILD_PAIR(SDNode *N) {
87   // Convert the inputs to integers, and build a new pair out of them.
88   return DAG.getNode(ISD::BUILD_PAIR,
89                      TLI.getTypeToTransformTo(N->getValueType(0)),
90                      BitConvertToInteger(N->getOperand(0)),
91                      BitConvertToInteger(N->getOperand(1)));
92 }
93
94 SDOperand DAGTypeLegalizer::SoftenFloatRes_ConstantFP(ConstantFPSDNode *N) {
95   return DAG.getConstant(N->getValueAPF().convertToAPInt(),
96                          TLI.getTypeToTransformTo(N->getValueType(0)));
97 }
98
99 SDOperand DAGTypeLegalizer::SoftenFloatRes_FADD(SDNode *N) {
100   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
101   SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
102                        GetSoftenedFloat(N->getOperand(1)) };
103   return MakeLibCall(GetFPLibCall(N->getValueType(0),
104                                   RTLIB::ADD_F32,
105                                   RTLIB::ADD_F64,
106                                   RTLIB::ADD_F80,
107                                   RTLIB::ADD_PPCF128),
108                      NVT, Ops, 2, false);
109 }
110
111 SDOperand DAGTypeLegalizer::SoftenFloatRes_FCOPYSIGN(SDNode *N) {
112   SDOperand LHS = GetSoftenedFloat(N->getOperand(0));
113   SDOperand RHS = BitConvertToInteger(N->getOperand(1));
114
115   MVT LVT = LHS.getValueType();
116   MVT RVT = RHS.getValueType();
117
118   unsigned LSize = LVT.getSizeInBits();
119   unsigned RSize = RVT.getSizeInBits();
120
121   // First get the sign bit of second operand.
122   SDOperand SignBit = DAG.getNode(ISD::SHL, RVT, DAG.getConstant(1, RVT),
123                                   DAG.getConstant(RSize - 1,
124                                                   TLI.getShiftAmountTy()));
125   SignBit = DAG.getNode(ISD::AND, RVT, RHS, SignBit);
126
127   // Shift right or sign-extend it if the two operands have different types.
128   int SizeDiff = RVT.getSizeInBits() - LVT.getSizeInBits();
129   if (SizeDiff > 0) {
130     SignBit = DAG.getNode(ISD::SRL, RVT, SignBit,
131                           DAG.getConstant(SizeDiff, TLI.getShiftAmountTy()));
132     SignBit = DAG.getNode(ISD::TRUNCATE, LVT, SignBit);
133   } else if (SizeDiff < 0) {
134     SignBit = DAG.getNode(ISD::ANY_EXTEND, LVT, SignBit);
135     SignBit = DAG.getNode(ISD::SHL, LVT, SignBit,
136                           DAG.getConstant(-SizeDiff, TLI.getShiftAmountTy()));
137   }
138
139   // Clear the sign bit of the first operand.
140   SDOperand Mask = DAG.getNode(ISD::SHL, LVT, DAG.getConstant(1, LVT),
141                                DAG.getConstant(LSize - 1,
142                                                TLI.getShiftAmountTy()));
143   Mask = DAG.getNode(ISD::SUB, LVT, Mask, DAG.getConstant(1, LVT));
144   LHS = DAG.getNode(ISD::AND, LVT, LHS, Mask);
145
146   // Or the value with the sign bit.
147   return DAG.getNode(ISD::OR, LVT, LHS, SignBit);
148 }
149
150 SDOperand DAGTypeLegalizer::SoftenFloatRes_FDIV(SDNode *N) {
151   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
152   SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
153                        GetSoftenedFloat(N->getOperand(1)) };
154   return MakeLibCall(GetFPLibCall(N->getValueType(0),
155                                   RTLIB::DIV_F32,
156                                   RTLIB::DIV_F64,
157                                   RTLIB::DIV_F80,
158                                   RTLIB::DIV_PPCF128),
159                      NVT, Ops, 2, false);
160 }
161
162 SDOperand DAGTypeLegalizer::SoftenFloatRes_FMUL(SDNode *N) {
163   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
164   SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
165                        GetSoftenedFloat(N->getOperand(1)) };
166   return MakeLibCall(GetFPLibCall(N->getValueType(0),
167                                   RTLIB::MUL_F32,
168                                   RTLIB::MUL_F64,
169                                   RTLIB::MUL_F80,
170                                   RTLIB::MUL_PPCF128),
171                      NVT, Ops, 2, false);
172 }
173
174 SDOperand DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) {
175   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
176   SDOperand Op = N->getOperand(0);
177   RTLIB::Libcall LC = RTLIB::getFPEXT(Op.getValueType(), N->getValueType(0));
178   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
179   return MakeLibCall(LC, NVT, &Op, 1, false);
180 }
181
182 SDOperand DAGTypeLegalizer::SoftenFloatRes_FP_ROUND(SDNode *N) {
183   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
184   SDOperand Op = N->getOperand(0);
185   RTLIB::Libcall LC = RTLIB::getFPROUND(Op.getValueType(), N->getValueType(0));
186   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!");
187   return MakeLibCall(LC, NVT, &Op, 1, false);
188 }
189
190 SDOperand DAGTypeLegalizer::SoftenFloatRes_FPOWI(SDNode *N) {
191   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
192   SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)), N->getOperand(1) };
193   return MakeLibCall(GetFPLibCall(N->getValueType(0),
194                                   RTLIB::POWI_F32,
195                                   RTLIB::POWI_F64,
196                                   RTLIB::POWI_F80,
197                                   RTLIB::POWI_PPCF128),
198                      NVT, Ops, 2, false);
199 }
200
201 SDOperand DAGTypeLegalizer::SoftenFloatRes_FSUB(SDNode *N) {
202   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
203   SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
204                        GetSoftenedFloat(N->getOperand(1)) };
205   return MakeLibCall(GetFPLibCall(N->getValueType(0),
206                                   RTLIB::SUB_F32,
207                                   RTLIB::SUB_F64,
208                                   RTLIB::SUB_F80,
209                                   RTLIB::SUB_PPCF128),
210                      NVT, Ops, 2, false);
211 }
212
213 SDOperand DAGTypeLegalizer::SoftenFloatRes_LOAD(SDNode *N) {
214   LoadSDNode *L = cast<LoadSDNode>(N);
215   MVT VT = N->getValueType(0);
216   MVT NVT = TLI.getTypeToTransformTo(VT);
217
218   SDOperand NewL;
219   if (L->getExtensionType() == ISD::NON_EXTLOAD) {
220     NewL = DAG.getLoad(L->getAddressingMode(), L->getExtensionType(),
221                        NVT, L->getChain(), L->getBasePtr(), L->getOffset(),
222                        L->getSrcValue(), L->getSrcValueOffset(), NVT,
223                        L->isVolatile(), L->getAlignment());
224     // Legalized the chain result - switch anything that used the old chain to
225     // use the new one.
226     ReplaceValueWith(SDOperand(N, 1), NewL.getValue(1));
227     return NewL;
228   }
229
230   // Do a non-extending load followed by FP_EXTEND.
231   NewL = DAG.getLoad(L->getAddressingMode(), ISD::NON_EXTLOAD,
232                      L->getMemoryVT(), L->getChain(),
233                      L->getBasePtr(), L->getOffset(),
234                      L->getSrcValue(), L->getSrcValueOffset(),
235                      L->getMemoryVT(),
236                      L->isVolatile(), L->getAlignment());
237   // Legalized the chain result - switch anything that used the old chain to
238   // use the new one.
239   ReplaceValueWith(SDOperand(N, 1), NewL.getValue(1));
240   return BitConvertToInteger(DAG.getNode(ISD::FP_EXTEND, VT, NewL));
241 }
242
243 SDOperand DAGTypeLegalizer::SoftenFloatRes_SELECT(SDNode *N) {
244   SDOperand LHS = GetSoftenedFloat(N->getOperand(1));
245   SDOperand RHS = GetSoftenedFloat(N->getOperand(2));
246   return DAG.getNode(ISD::SELECT, LHS.getValueType(), N->getOperand(0),LHS,RHS);
247 }
248
249 SDOperand DAGTypeLegalizer::SoftenFloatRes_SELECT_CC(SDNode *N) {
250   SDOperand LHS = GetSoftenedFloat(N->getOperand(2));
251   SDOperand RHS = GetSoftenedFloat(N->getOperand(3));
252   return DAG.getNode(ISD::SELECT_CC, LHS.getValueType(), N->getOperand(0),
253                      N->getOperand(1), LHS, RHS, N->getOperand(4));
254 }
255
256 SDOperand DAGTypeLegalizer::SoftenFloatRes_SINT_TO_FP(SDNode *N) {
257   SDOperand Op = N->getOperand(0);
258   MVT RVT = N->getValueType(0);
259   RTLIB::Libcall LC = RTLIB::getSINTTOFP(Op.getValueType(), RVT);
260   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SINT_TO_FP!");
261   return MakeLibCall(LC, TLI.getTypeToTransformTo(RVT), &Op, 1, false);
262 }
263
264 SDOperand DAGTypeLegalizer::SoftenFloatRes_UINT_TO_FP(SDNode *N) {
265   SDOperand Op = N->getOperand(0);
266   MVT RVT = N->getValueType(0);
267   RTLIB::Libcall LC = RTLIB::getUINTTOFP(Op.getValueType(), RVT);
268   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported UINT_TO_FP!");
269   return MakeLibCall(LC, TLI.getTypeToTransformTo(RVT), &Op, 1, false);
270 }
271
272
273 //===----------------------------------------------------------------------===//
274 //  Operand Float to Integer Conversion..
275 //===----------------------------------------------------------------------===//
276
277 bool DAGTypeLegalizer::SoftenFloatOperand(SDNode *N, unsigned OpNo) {
278   DEBUG(cerr << "Soften float operand " << OpNo << ": "; N->dump(&DAG);
279         cerr << "\n");
280   SDOperand Res = SDOperand();
281
282   switch (N->getOpcode()) {
283   default:
284 #ifndef NDEBUG
285     cerr << "SoftenFloatOperand Op #" << OpNo << ": ";
286     N->dump(&DAG); cerr << "\n";
287 #endif
288     assert(0 && "Do not know how to soften this operator's operand!");
289     abort();
290
291   case ISD::BIT_CONVERT: Res = SoftenFloatOp_BIT_CONVERT(N); break;
292   case ISD::BR_CC:       Res = SoftenFloatOp_BR_CC(N); break;
293   case ISD::FP_TO_SINT:  Res = SoftenFloatOp_FP_TO_SINT(N); break;
294   case ISD::FP_TO_UINT:  Res = SoftenFloatOp_FP_TO_UINT(N); break;
295   case ISD::SELECT_CC:   Res = SoftenFloatOp_SELECT_CC(N); break;
296   case ISD::SETCC:       Res = SoftenFloatOp_SETCC(N); break;
297   case ISD::STORE:       Res = SoftenFloatOp_STORE(N, OpNo); break;
298   }
299
300   // If the result is null, the sub-method took care of registering results etc.
301   if (!Res.Val) return false;
302
303   // If the result is N, the sub-method updated N in place.  Check to see if any
304   // operands are new, and if so, mark them.
305   if (Res.Val == N) {
306     // Mark N as new and remark N and its operands.  This allows us to correctly
307     // revisit N if it needs another step of promotion and allows us to visit
308     // any new operands to N.
309     ReanalyzeNode(N);
310     return true;
311   }
312
313   assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
314          "Invalid operand expansion");
315
316   ReplaceValueWith(SDOperand(N, 0), Res);
317   return false;
318 }
319
320 /// SoftenSetCCOperands - Soften the operands of a comparison.  This code is
321 /// shared among BR_CC, SELECT_CC, and SETCC handlers.
322 void DAGTypeLegalizer::SoftenSetCCOperands(SDOperand &NewLHS, SDOperand &NewRHS,
323                                            ISD::CondCode &CCCode) {
324   SDOperand LHSInt = GetSoftenedFloat(NewLHS);
325   SDOperand RHSInt = GetSoftenedFloat(NewRHS);
326   MVT VT = NewLHS.getValueType();
327
328   assert((VT == MVT::f32 || VT == MVT::f64) && "Unsupported setcc type!");
329
330   // Expand into one or more soft-fp libcall(s).
331   RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL;
332   switch (CCCode) {
333   case ISD::SETEQ:
334   case ISD::SETOEQ:
335     LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64;
336     break;
337   case ISD::SETNE:
338   case ISD::SETUNE:
339     LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64;
340     break;
341   case ISD::SETGE:
342   case ISD::SETOGE:
343     LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64;
344     break;
345   case ISD::SETLT:
346   case ISD::SETOLT:
347     LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
348     break;
349   case ISD::SETLE:
350   case ISD::SETOLE:
351     LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64;
352     break;
353   case ISD::SETGT:
354   case ISD::SETOGT:
355     LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64;
356     break;
357   case ISD::SETUO:
358     LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64;
359     break;
360   case ISD::SETO:
361     LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64;
362     break;
363   default:
364     LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64;
365     switch (CCCode) {
366     case ISD::SETONE:
367       // SETONE = SETOLT | SETOGT
368       LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
369       // Fallthrough
370     case ISD::SETUGT:
371       LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64;
372       break;
373     case ISD::SETUGE:
374       LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64;
375       break;
376     case ISD::SETULT:
377       LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
378       break;
379     case ISD::SETULE:
380       LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64;
381       break;
382     case ISD::SETUEQ:
383       LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64;
384       break;
385     default: assert(false && "Do not know how to soften this setcc!");
386     }
387   }
388
389   MVT RetVT = MVT::i32; // FIXME: is this the correct return type?
390   SDOperand Ops[2] = { LHSInt, RHSInt };
391   NewLHS = MakeLibCall(LC1, RetVT, Ops, 2, false/*sign irrelevant*/);
392   NewRHS = DAG.getConstant(0, RetVT);
393   CCCode = TLI.getCmpLibcallCC(LC1);
394   if (LC2 != RTLIB::UNKNOWN_LIBCALL) {
395     SDOperand Tmp = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(NewLHS),
396                                 NewLHS, NewRHS, DAG.getCondCode(CCCode));
397     NewLHS = MakeLibCall(LC2, RetVT, Ops, 2, false/*sign irrelevant*/);
398     NewLHS = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(NewLHS), NewLHS,
399                          NewRHS, DAG.getCondCode(TLI.getCmpLibcallCC(LC2)));
400     NewLHS = DAG.getNode(ISD::OR, Tmp.getValueType(), Tmp, NewLHS);
401     NewRHS = SDOperand();
402   }
403 }
404
405 SDOperand DAGTypeLegalizer::SoftenFloatOp_BIT_CONVERT(SDNode *N) {
406   return DAG.getNode(ISD::BIT_CONVERT, N->getValueType(0),
407                      GetSoftenedFloat(N->getOperand(0)));
408 }
409
410 SDOperand DAGTypeLegalizer::SoftenFloatOp_BR_CC(SDNode *N) {
411   SDOperand NewLHS = N->getOperand(2), NewRHS = N->getOperand(3);
412   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get();
413   SoftenSetCCOperands(NewLHS, NewRHS, CCCode);
414
415   // If SoftenSetCCOperands returned a scalar, we need to compare the result
416   // against zero to select between true and false values.
417   if (NewRHS.Val == 0) {
418     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
419     CCCode = ISD::SETNE;
420   }
421
422   // Update N to have the operands specified.
423   return DAG.UpdateNodeOperands(SDOperand(N, 0), N->getOperand(0),
424                                 DAG.getCondCode(CCCode), NewLHS, NewRHS,
425                                 N->getOperand(4));
426 }
427
428 SDOperand DAGTypeLegalizer::SoftenFloatOp_FP_TO_SINT(SDNode *N) {
429   MVT RVT = N->getValueType(0);
430   RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
431   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
432   SDOperand Op = GetSoftenedFloat(N->getOperand(0));
433   return MakeLibCall(LC, RVT, &Op, 1, false);
434 }
435
436 SDOperand DAGTypeLegalizer::SoftenFloatOp_FP_TO_UINT(SDNode *N) {
437   MVT RVT = N->getValueType(0);
438   RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
439   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
440   SDOperand Op = GetSoftenedFloat(N->getOperand(0));
441   return MakeLibCall(LC, RVT, &Op, 1, false);
442 }
443
444 SDOperand DAGTypeLegalizer::SoftenFloatOp_SELECT_CC(SDNode *N) {
445   SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
446   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get();
447   SoftenSetCCOperands(NewLHS, NewRHS, CCCode);
448
449   // If SoftenSetCCOperands returned a scalar, we need to compare the result
450   // against zero to select between true and false values.
451   if (NewRHS.Val == 0) {
452     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
453     CCCode = ISD::SETNE;
454   }
455
456   // Update N to have the operands specified.
457   return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS,
458                                 N->getOperand(2), N->getOperand(3),
459                                 DAG.getCondCode(CCCode));
460 }
461
462 SDOperand DAGTypeLegalizer::SoftenFloatOp_SETCC(SDNode *N) {
463   SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
464   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get();
465   SoftenSetCCOperands(NewLHS, NewRHS, CCCode);
466
467   // If SoftenSetCCOperands returned a scalar, use it.
468   if (NewRHS.Val == 0) {
469     assert(NewLHS.getValueType() == N->getValueType(0) &&
470            "Unexpected setcc expansion!");
471     return NewLHS;
472   }
473
474   // Otherwise, update N to have the operands specified.
475   return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS,
476                                 DAG.getCondCode(CCCode));
477 }
478
479 SDOperand DAGTypeLegalizer::SoftenFloatOp_STORE(SDNode *N, unsigned OpNo) {
480   assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!");
481   assert(OpNo == 1 && "Can only soften the stored value!");
482   StoreSDNode *ST = cast<StoreSDNode>(N);
483   SDOperand Val = ST->getValue();
484
485   if (ST->isTruncatingStore())
486     // Do an FP_ROUND followed by a non-truncating store.
487     Val = BitConvertToInteger(DAG.getNode(ISD::FP_ROUND, ST->getMemoryVT(),
488                                           Val, DAG.getIntPtrConstant(0)));
489   else
490     Val = GetSoftenedFloat(Val);
491
492   return DAG.getStore(ST->getChain(), Val, ST->getBasePtr(),
493                       ST->getSrcValue(), ST->getSrcValueOffset(),
494                       ST->isVolatile(), ST->getAlignment());
495 }
496
497
498 //===----------------------------------------------------------------------===//
499 //  Float Result Expansion
500 //===----------------------------------------------------------------------===//
501
502 /// ExpandFloatResult - This method is called when the specified result of the
503 /// specified node is found to need expansion.  At this point, the node may also
504 /// have invalid operands or may have other results that need promotion, we just
505 /// know that (at least) one result needs expansion.
506 void DAGTypeLegalizer::ExpandFloatResult(SDNode *N, unsigned ResNo) {
507   DEBUG(cerr << "Expand float result: "; N->dump(&DAG); cerr << "\n");
508   SDOperand Lo, Hi;
509   Lo = Hi = SDOperand();
510
511   // See if the target wants to custom expand this node.
512   if (TLI.getOperationAction(N->getOpcode(), N->getValueType(ResNo)) ==
513       TargetLowering::Custom) {
514     // If the target wants to, allow it to lower this itself.
515     if (SDNode *P = TLI.ReplaceNodeResults(N, DAG)) {
516       // Everything that once used N now uses P.  We are guaranteed that the
517       // result value types of N and the result value types of P match.
518       ReplaceNodeWith(N, P);
519       return;
520     }
521   }
522
523   switch (N->getOpcode()) {
524   default:
525 #ifndef NDEBUG
526     cerr << "ExpandFloatResult #" << ResNo << ": ";
527     N->dump(&DAG); cerr << "\n";
528 #endif
529     assert(0 && "Do not know how to expand the result of this operator!");
530     abort();
531
532   case ISD::MERGE_VALUES: SplitRes_MERGE_VALUES(N, Lo, Hi); break;
533   case ISD::UNDEF:        SplitRes_UNDEF(N, Lo, Hi); break;
534   case ISD::SELECT:       SplitRes_SELECT(N, Lo, Hi); break;
535   case ISD::SELECT_CC:    SplitRes_SELECT_CC(N, Lo, Hi); break;
536
537   case ISD::BIT_CONVERT:        ExpandRes_BIT_CONVERT(N, Lo, Hi); break;
538   case ISD::BUILD_PAIR:         ExpandRes_BUILD_PAIR(N, Lo, Hi); break;
539   case ISD::EXTRACT_ELEMENT:    ExpandRes_EXTRACT_ELEMENT(N, Lo, Hi); break;
540   case ISD::EXTRACT_VECTOR_ELT: ExpandRes_EXTRACT_VECTOR_ELT(N, Lo, Hi); break;
541
542   case ISD::ConstantFP: ExpandFloatRes_ConstantFP(N, Lo, Hi); break;
543   case ISD::FABS:       ExpandFloatRes_FABS(N, Lo, Hi); break;
544   case ISD::FADD:       ExpandFloatRes_FADD(N, Lo, Hi); break;
545   case ISD::FDIV:       ExpandFloatRes_FDIV(N, Lo, Hi); break;
546   case ISD::FMUL:       ExpandFloatRes_FMUL(N, Lo, Hi); break;
547   case ISD::FNEG:       ExpandFloatRes_FNEG(N, Lo, Hi); break;
548   case ISD::FP_EXTEND:  ExpandFloatRes_FP_EXTEND(N, Lo, Hi); break;
549   case ISD::FSUB:       ExpandFloatRes_FSUB(N, Lo, Hi); break;
550   case ISD::LOAD:       ExpandFloatRes_LOAD(N, Lo, Hi); break;
551   case ISD::SINT_TO_FP:
552   case ISD::UINT_TO_FP: ExpandFloatRes_XINT_TO_FP(N, Lo, Hi); break;
553   }
554
555   // If Lo/Hi is null, the sub-method took care of registering results etc.
556   if (Lo.Val)
557     SetExpandedFloat(SDOperand(N, ResNo), Lo, Hi);
558 }
559
560 void DAGTypeLegalizer::ExpandFloatRes_ConstantFP(SDNode *N, SDOperand &Lo,
561                                                  SDOperand &Hi) {
562   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
563   assert(NVT.getSizeInBits() == integerPartWidth &&
564          "Do not know how to expand this float constant!");
565   APInt C = cast<ConstantFPSDNode>(N)->getValueAPF().convertToAPInt();
566   Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
567                                        &C.getRawData()[1])), NVT);
568   Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
569                                        &C.getRawData()[0])), NVT);
570 }
571
572 void DAGTypeLegalizer::ExpandFloatRes_FADD(SDNode *N, SDOperand &Lo,
573                                            SDOperand &Hi) {
574   SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) };
575   SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
576                                             RTLIB::ADD_F32,
577                                             RTLIB::ADD_F64,
578                                             RTLIB::ADD_F80,
579                                             RTLIB::ADD_PPCF128),
580                                N->getValueType(0), Ops, 2,
581                                false);
582   assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
583   Lo = Call.getOperand(0); Hi = Call.getOperand(1);
584 }
585
586 void DAGTypeLegalizer::ExpandFloatRes_FABS(SDNode *N, SDOperand &Lo,
587                                            SDOperand &Hi) {
588   assert(N->getValueType(0) == MVT::ppcf128 &&
589          "Logic only correct for ppcf128!");
590   SDOperand Tmp;
591   GetExpandedFloat(N->getOperand(0), Lo, Tmp);
592   Hi = DAG.getNode(ISD::FABS, Tmp.getValueType(), Tmp);
593   // Lo = Hi==fabs(Hi) ? Lo : -Lo;
594   Lo = DAG.getNode(ISD::SELECT_CC, Lo.getValueType(), Tmp, Hi, Lo,
595                    DAG.getNode(ISD::FNEG, Lo.getValueType(), Lo),
596                    DAG.getCondCode(ISD::SETEQ));
597 }
598
599 void DAGTypeLegalizer::ExpandFloatRes_FDIV(SDNode *N, SDOperand &Lo,
600                                            SDOperand &Hi) {
601   SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) };
602   SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
603                                             RTLIB::DIV_F32,
604                                             RTLIB::DIV_F64,
605                                             RTLIB::DIV_F80,
606                                             RTLIB::DIV_PPCF128),
607                                N->getValueType(0), Ops, 2,
608                                false);
609   assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
610   Lo = Call.getOperand(0); Hi = Call.getOperand(1);
611 }
612
613 void DAGTypeLegalizer::ExpandFloatRes_FMUL(SDNode *N, SDOperand &Lo,
614                                            SDOperand &Hi) {
615   SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) };
616   SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
617                                             RTLIB::MUL_F32,
618                                             RTLIB::MUL_F64,
619                                             RTLIB::MUL_F80,
620                                             RTLIB::MUL_PPCF128),
621                                N->getValueType(0), Ops, 2,
622                                false);
623   assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
624   Lo = Call.getOperand(0); Hi = Call.getOperand(1);
625 }
626
627 void DAGTypeLegalizer::ExpandFloatRes_FNEG(SDNode *N, SDOperand &Lo,
628                                            SDOperand &Hi) {
629   GetExpandedFloat(N->getOperand(0), Lo, Hi);
630   Lo = DAG.getNode(ISD::FNEG, Lo.getValueType(), Lo);
631   Hi = DAG.getNode(ISD::FNEG, Hi.getValueType(), Hi);
632 }
633
634 void DAGTypeLegalizer::ExpandFloatRes_FP_EXTEND(SDNode *N, SDOperand &Lo,
635                                                 SDOperand &Hi) {
636   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
637   Hi = DAG.getNode(ISD::FP_EXTEND, NVT, N->getOperand(0));
638   Lo = DAG.getConstantFP(APFloat(APInt(NVT.getSizeInBits(), 0)), NVT);
639 }
640
641 void DAGTypeLegalizer::ExpandFloatRes_FSUB(SDNode *N, SDOperand &Lo,
642                                            SDOperand &Hi) {
643   SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) };
644   SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
645                                             RTLIB::SUB_F32,
646                                             RTLIB::SUB_F64,
647                                             RTLIB::SUB_F80,
648                                             RTLIB::SUB_PPCF128),
649                                N->getValueType(0), Ops, 2,
650                                false);
651   assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
652   Lo = Call.getOperand(0); Hi = Call.getOperand(1);
653 }
654
655 void DAGTypeLegalizer::ExpandFloatRes_LOAD(SDNode *N, SDOperand &Lo,
656                                            SDOperand &Hi) {
657   if (ISD::isNormalLoad(N)) {
658     ExpandRes_NormalLoad(N, Lo, Hi);
659     return;
660   }
661
662   assert(ISD::isUNINDEXEDLoad(N) && "Indexed load during type legalization!");
663   LoadSDNode *LD = cast<LoadSDNode>(N);
664   SDOperand Chain = LD->getChain();
665   SDOperand Ptr = LD->getBasePtr();
666
667   MVT NVT = TLI.getTypeToTransformTo(LD->getValueType(0));
668   assert(NVT.isByteSized() && "Expanded type not byte sized!");
669   assert(LD->getMemoryVT().bitsLE(NVT) && "Float type not round?");
670
671   Lo = DAG.getExtLoad(LD->getExtensionType(), NVT, Chain, Ptr,
672                       LD->getSrcValue(), LD->getSrcValueOffset(),
673                       LD->getMemoryVT(),
674                       LD->isVolatile(), LD->getAlignment());
675
676   // Remember the chain.
677   Chain = Lo.getValue(1);
678
679   // The high part is undefined.
680   Hi = DAG.getNode(ISD::UNDEF, NVT);
681
682   // Modified the chain - switch anything that used the old chain to use the
683   // new one.
684   ReplaceValueWith(SDOperand(LD, 1), Chain);
685 }
686
687 void DAGTypeLegalizer::ExpandFloatRes_XINT_TO_FP(SDNode *N, SDOperand &Lo,
688                                                  SDOperand &Hi) {
689   assert(N->getValueType(0) == MVT::ppcf128 && "Unsupported XINT_TO_FP!");
690   MVT VT = N->getValueType(0);
691   MVT NVT = TLI.getTypeToTransformTo(VT);
692   SDOperand Src = N->getOperand(0);
693   MVT SrcVT = Src.getValueType();
694
695   // First do an SINT_TO_FP, whether the original was signed or unsigned.
696   if (SrcVT.bitsLE(MVT::i32)) {
697     // The integer can be represented exactly in an f64.
698     Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Src);
699     Lo = DAG.getConstantFP(APFloat(APInt(NVT.getSizeInBits(), 0)), NVT);
700     Hi = DAG.getNode(ISD::SINT_TO_FP, NVT, Src);
701   } else {
702     RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
703     if (SrcVT.bitsLE(MVT::i64)) {
704       Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Src);
705       LC = RTLIB::SINTTOFP_I64_PPCF128;
706     } else if (SrcVT.bitsLE(MVT::i128)) {
707       Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i128, Src);
708       LC = RTLIB::SINTTOFP_I128_PPCF128;
709     }
710     assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XINT_TO_FP!");
711
712     Hi = MakeLibCall(LC, VT, &Src, 1, true);
713     assert(Hi.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
714     Lo = Hi.getOperand(0); Hi = Hi.getOperand(1);
715   }
716
717   if (N->getOpcode() == ISD::SINT_TO_FP)
718     return;
719
720   // Unsigned - fix up the SINT_TO_FP value just calculated.
721   Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi);
722   SrcVT = Src.getValueType();
723
724   // x>=0 ? (ppcf128)(iN)x : (ppcf128)(iN)x + 2^N; N=32,64,128.
725   static const uint64_t TwoE32[]  = { 0x41f0000000000000LL, 0 };
726   static const uint64_t TwoE64[]  = { 0x43f0000000000000LL, 0 };
727   static const uint64_t TwoE128[] = { 0x47f0000000000000LL, 0 };
728   const uint64_t *Parts = 0;
729
730   switch (SrcVT.getSimpleVT()) {
731   default:
732     assert(false && "Unsupported UINT_TO_FP!");
733   case MVT::i32:
734     Parts = TwoE32;
735   case MVT::i64:
736     Parts = TwoE64;
737   case MVT::i128:
738     Parts = TwoE128;
739   }
740
741   Lo = DAG.getNode(ISD::FADD, VT, Hi,
742                    DAG.getConstantFP(APFloat(APInt(128, 2, Parts)),
743                                      MVT::ppcf128));
744   Lo = DAG.getNode(ISD::SELECT_CC, VT, Src, DAG.getConstant(0, SrcVT), Lo, Hi,
745                    DAG.getCondCode(ISD::SETLT));
746   Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, NVT, Lo,
747                    DAG.getConstant(1, TLI.getPointerTy()));
748   Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, NVT, Lo,
749                    DAG.getConstant(0, TLI.getPointerTy()));
750 }
751
752
753 //===----------------------------------------------------------------------===//
754 //  Float Operand Expansion
755 //===----------------------------------------------------------------------===//
756
757 /// ExpandFloatOperand - This method is called when the specified operand of the
758 /// specified node is found to need expansion.  At this point, all of the result
759 /// types of the node are known to be legal, but other operands of the node may
760 /// need promotion or expansion as well as the specified one.
761 bool DAGTypeLegalizer::ExpandFloatOperand(SDNode *N, unsigned OpNo) {
762   DEBUG(cerr << "Expand float operand: "; N->dump(&DAG); cerr << "\n");
763   SDOperand Res = SDOperand();
764
765   if (TLI.getOperationAction(N->getOpcode(), N->getOperand(OpNo).getValueType())
766       == TargetLowering::Custom)
767     Res = TLI.LowerOperation(SDOperand(N, OpNo), DAG);
768
769   if (Res.Val == 0) {
770     switch (N->getOpcode()) {
771     default:
772   #ifndef NDEBUG
773       cerr << "ExpandFloatOperand Op #" << OpNo << ": ";
774       N->dump(&DAG); cerr << "\n";
775   #endif
776       assert(0 && "Do not know how to expand this operator's operand!");
777       abort();
778
779     case ISD::BIT_CONVERT:     Res = ExpandOp_BIT_CONVERT(N); break;
780     case ISD::BUILD_VECTOR:    Res = ExpandOp_BUILD_VECTOR(N); break;
781     case ISD::EXTRACT_ELEMENT: Res = ExpandOp_EXTRACT_ELEMENT(N); break;
782
783     case ISD::BR_CC:      Res = ExpandFloatOp_BR_CC(N); break;
784     case ISD::FP_ROUND:   Res = ExpandFloatOp_FP_ROUND(N); break;
785     case ISD::FP_TO_SINT: Res = ExpandFloatOp_FP_TO_SINT(N); break;
786     case ISD::FP_TO_UINT: Res = ExpandFloatOp_FP_TO_UINT(N); break;
787     case ISD::SELECT_CC:  Res = ExpandFloatOp_SELECT_CC(N); break;
788     case ISD::SETCC:      Res = ExpandFloatOp_SETCC(N); break;
789     case ISD::STORE:      Res = ExpandFloatOp_STORE(cast<StoreSDNode>(N),
790                                                     OpNo); break;
791     }
792   }
793
794   // If the result is null, the sub-method took care of registering results etc.
795   if (!Res.Val) return false;
796   // If the result is N, the sub-method updated N in place.  Check to see if any
797   // operands are new, and if so, mark them.
798   if (Res.Val == N) {
799     // Mark N as new and remark N and its operands.  This allows us to correctly
800     // revisit N if it needs another step of expansion and allows us to visit
801     // any new operands to N.
802     ReanalyzeNode(N);
803     return true;
804   }
805
806   assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
807          "Invalid operand expansion");
808
809   ReplaceValueWith(SDOperand(N, 0), Res);
810   return false;
811 }
812
813 /// FloatExpandSetCCOperands - Expand the operands of a comparison.  This code
814 /// is shared among BR_CC, SELECT_CC, and SETCC handlers.
815 void DAGTypeLegalizer::FloatExpandSetCCOperands(SDOperand &NewLHS,
816                                                 SDOperand &NewRHS,
817                                                 ISD::CondCode &CCCode) {
818   SDOperand LHSLo, LHSHi, RHSLo, RHSHi;
819   GetExpandedFloat(NewLHS, LHSLo, LHSHi);
820   GetExpandedFloat(NewRHS, RHSLo, RHSHi);
821
822   MVT VT = NewLHS.getValueType();
823   assert(VT == MVT::ppcf128 && "Unsupported setcc type!");
824
825   // FIXME:  This generated code sucks.  We want to generate
826   //         FCMP crN, hi1, hi2
827   //         BNE crN, L:
828   //         FCMP crN, lo1, lo2
829   // The following can be improved, but not that much.
830   SDOperand Tmp1, Tmp2, Tmp3;
831   Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETEQ);
832   Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, CCCode);
833   Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2);
834   Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETNE);
835   Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, CCCode);
836   Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2);
837   NewLHS = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3);
838   NewRHS = SDOperand();   // LHS is the result, not a compare.
839 }
840
841 SDOperand DAGTypeLegalizer::ExpandFloatOp_BR_CC(SDNode *N) {
842   SDOperand NewLHS = N->getOperand(2), NewRHS = N->getOperand(3);
843   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get();
844   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode);
845
846   // If ExpandSetCCOperands returned a scalar, we need to compare the result
847   // against zero to select between true and false values.
848   if (NewRHS.Val == 0) {
849     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
850     CCCode = ISD::SETNE;
851   }
852
853   // Update N to have the operands specified.
854   return DAG.UpdateNodeOperands(SDOperand(N, 0), N->getOperand(0),
855                                 DAG.getCondCode(CCCode), NewLHS, NewRHS,
856                                 N->getOperand(4));
857 }
858
859 SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_ROUND(SDNode *N) {
860   assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
861          "Logic only correct for ppcf128!");
862   SDOperand Lo, Hi;
863   GetExpandedFloat(N->getOperand(0), Lo, Hi);
864   // Round it the rest of the way (e.g. to f32) if needed.
865   return DAG.getNode(ISD::FP_ROUND, N->getValueType(0), Hi, N->getOperand(1));
866 }
867
868 SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_TO_SINT(SDNode *N) {
869   MVT RVT = N->getValueType(0);
870   RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
871   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
872   return MakeLibCall(LC, RVT, &N->getOperand(0), 1, false);
873 }
874
875 SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_TO_UINT(SDNode *N) {
876   MVT RVT = N->getValueType(0);
877   RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
878   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
879   return MakeLibCall(LC, N->getValueType(0), &N->getOperand(0), 1, false);
880 }
881
882 SDOperand DAGTypeLegalizer::ExpandFloatOp_SELECT_CC(SDNode *N) {
883   SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
884   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get();
885   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode);
886
887   // If ExpandSetCCOperands returned a scalar, we need to compare the result
888   // against zero to select between true and false values.
889   if (NewRHS.Val == 0) {
890     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
891     CCCode = ISD::SETNE;
892   }
893
894   // Update N to have the operands specified.
895   return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS,
896                                 N->getOperand(2), N->getOperand(3),
897                                 DAG.getCondCode(CCCode));
898 }
899
900 SDOperand DAGTypeLegalizer::ExpandFloatOp_SETCC(SDNode *N) {
901   SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
902   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get();
903   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode);
904
905   // If ExpandSetCCOperands returned a scalar, use it.
906   if (NewRHS.Val == 0) {
907     assert(NewLHS.getValueType() == N->getValueType(0) &&
908            "Unexpected setcc expansion!");
909     return NewLHS;
910   }
911
912   // Otherwise, update N to have the operands specified.
913   return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS,
914                                 DAG.getCondCode(CCCode));
915 }
916
917 SDOperand DAGTypeLegalizer::ExpandFloatOp_STORE(SDNode *N, unsigned OpNo) {
918   if (ISD::isNormalStore(N))
919     return ExpandOp_NormalStore(N, OpNo);
920
921   assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!");
922   assert(OpNo == 1 && "Can only expand the stored value so far");
923   StoreSDNode *ST = cast<StoreSDNode>(N);
924
925   SDOperand Chain = ST->getChain();
926   SDOperand Ptr = ST->getBasePtr();
927
928   MVT NVT = TLI.getTypeToTransformTo(ST->getValue().getValueType());
929   assert(NVT.isByteSized() && "Expanded type not byte sized!");
930   assert(ST->getMemoryVT().bitsLE(NVT) && "Float type not round?");
931
932   SDOperand Lo, Hi;
933   GetExpandedOp(ST->getValue(), Lo, Hi);
934
935   return DAG.getTruncStore(Chain, Lo, Ptr,
936                            ST->getSrcValue(), ST->getSrcValueOffset(),
937                            ST->getMemoryVT(),
938                            ST->isVolatile(), ST->getAlignment());
939 }