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