b1edae8691cf1759434beb12a808757b5dedb40d
[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::FSUB:       ExpandFloatRes_FSUB(N, Lo, Hi); break;
535   case ISD::LOAD:       ExpandFloatRes_LOAD(N, Lo, Hi); break;
536   case ISD::SINT_TO_FP:
537   case ISD::UINT_TO_FP: ExpandFloatRes_XINT_TO_FP(N, Lo, Hi); break;
538   }
539
540   // If Lo/Hi is null, the sub-method took care of registering results etc.
541   if (Lo.Val)
542     SetExpandedFloat(SDOperand(N, ResNo), Lo, Hi);
543 }
544
545 void DAGTypeLegalizer::ExpandFloatRes_ConstantFP(SDNode *N, SDOperand &Lo,
546                                                  SDOperand &Hi) {
547   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
548   assert(NVT.getSizeInBits() == integerPartWidth &&
549          "Do not know how to expand this float constant!");
550   APInt C = cast<ConstantFPSDNode>(N)->getValueAPF().convertToAPInt();
551   Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
552                                        &C.getRawData()[1])), NVT);
553   Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
554                                        &C.getRawData()[0])), NVT);
555 }
556
557 void DAGTypeLegalizer::ExpandFloatRes_FADD(SDNode *N, SDOperand &Lo,
558                                            SDOperand &Hi) {
559   SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) };
560   SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
561                                             RTLIB::ADD_F32,
562                                             RTLIB::ADD_F64,
563                                             RTLIB::ADD_F80,
564                                             RTLIB::ADD_PPCF128),
565                                N->getValueType(0), Ops, 2,
566                                false);
567   assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
568   Lo = Call.getOperand(0); Hi = Call.getOperand(1);
569 }
570
571 void DAGTypeLegalizer::ExpandFloatRes_FABS(SDNode *N, SDOperand &Lo,
572                                            SDOperand &Hi) {
573   assert(N->getValueType(0) == MVT::ppcf128 &&
574          "Logic only correct for ppcf128!");
575   SDOperand Tmp;
576   GetExpandedFloat(N->getOperand(0), Lo, Tmp);
577   Hi = DAG.getNode(ISD::FABS, Tmp.getValueType(), Tmp);
578   // Lo = Hi==fabs(Hi) ? Lo : -Lo;
579   Lo = DAG.getNode(ISD::SELECT_CC, Lo.getValueType(), Tmp, Hi, Lo,
580                    DAG.getNode(ISD::FNEG, Lo.getValueType(), Lo),
581                    DAG.getCondCode(ISD::SETEQ));
582 }
583
584 void DAGTypeLegalizer::ExpandFloatRes_FDIV(SDNode *N, SDOperand &Lo,
585                                            SDOperand &Hi) {
586   SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) };
587   SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
588                                             RTLIB::DIV_F32,
589                                             RTLIB::DIV_F64,
590                                             RTLIB::DIV_F80,
591                                             RTLIB::DIV_PPCF128),
592                                N->getValueType(0), Ops, 2,
593                                false);
594   assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
595   Lo = Call.getOperand(0); Hi = Call.getOperand(1);
596 }
597
598 void DAGTypeLegalizer::ExpandFloatRes_FMUL(SDNode *N, SDOperand &Lo,
599                                            SDOperand &Hi) {
600   SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) };
601   SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
602                                             RTLIB::MUL_F32,
603                                             RTLIB::MUL_F64,
604                                             RTLIB::MUL_F80,
605                                             RTLIB::MUL_PPCF128),
606                                N->getValueType(0), Ops, 2,
607                                false);
608   assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
609   Lo = Call.getOperand(0); Hi = Call.getOperand(1);
610 }
611
612 void DAGTypeLegalizer::ExpandFloatRes_FSUB(SDNode *N, SDOperand &Lo,
613                                            SDOperand &Hi) {
614   SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) };
615   SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
616                                             RTLIB::SUB_F32,
617                                             RTLIB::SUB_F64,
618                                             RTLIB::SUB_F80,
619                                             RTLIB::SUB_PPCF128),
620                                N->getValueType(0), Ops, 2,
621                                false);
622   assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
623   Lo = Call.getOperand(0); Hi = Call.getOperand(1);
624 }
625
626 void DAGTypeLegalizer::ExpandFloatRes_LOAD(SDNode *N, SDOperand &Lo,
627                                            SDOperand &Hi) {
628   if (ISD::isNormalLoad(N)) {
629     ExpandRes_NormalLoad(N, Lo, Hi);
630     return;
631   }
632
633   assert(ISD::isUNINDEXEDLoad(N) && "Indexed load during type legalization!");
634   LoadSDNode *LD = cast<LoadSDNode>(N);
635   SDOperand Chain = LD->getChain();
636   SDOperand Ptr = LD->getBasePtr();
637
638   MVT NVT = TLI.getTypeToTransformTo(LD->getValueType(0));
639   assert(NVT.isByteSized() && "Expanded type not byte sized!");
640   assert(LD->getMemoryVT().bitsLE(NVT) && "Float type not round?");
641
642   Lo = DAG.getExtLoad(LD->getExtensionType(), NVT, Chain, Ptr,
643                       LD->getSrcValue(), LD->getSrcValueOffset(),
644                       LD->getMemoryVT(),
645                       LD->isVolatile(), LD->getAlignment());
646
647   // Remember the chain.
648   Chain = Lo.getValue(1);
649
650   // The high part is undefined.
651   Hi = DAG.getNode(ISD::UNDEF, NVT);
652
653   // Modified the chain - switch anything that used the old chain to use the
654   // new one.
655   ReplaceValueWith(SDOperand(LD, 1), Chain);
656 }
657
658 void DAGTypeLegalizer::ExpandFloatRes_XINT_TO_FP(SDNode *N, SDOperand &Lo,
659                                                  SDOperand &Hi) {
660   assert(N->getValueType(0) == MVT::ppcf128 && "Unsupported XINT_TO_FP!");
661   MVT VT = N->getValueType(0);
662   MVT NVT = TLI.getTypeToTransformTo(VT);
663   SDOperand Src = N->getOperand(0);
664   MVT SrcVT = Src.getValueType();
665
666   // First do an SINT_TO_FP, whether the original was signed or unsigned.
667   if (SrcVT.bitsLE(MVT::i32)) {
668     // The integer can be represented exactly in an f64.
669     Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Src);
670     Lo = DAG.getConstantFP(APFloat(APInt(NVT.getSizeInBits(), 0)), NVT);
671     Hi = DAG.getNode(ISD::SINT_TO_FP, NVT, Src);
672   } else {
673     RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
674     if (SrcVT.bitsLE(MVT::i64)) {
675       Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Src);
676       LC = RTLIB::SINTTOFP_I64_PPCF128;
677     } else if (SrcVT.bitsLE(MVT::i128)) {
678       Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i128, Src);
679       LC = RTLIB::SINTTOFP_I128_PPCF128;
680     }
681     assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XINT_TO_FP!");
682
683     Hi = MakeLibCall(LC, VT, &Src, 1, true);
684     assert(Hi.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!");
685     Lo = Hi.getOperand(0); Hi = Hi.getOperand(1);
686   }
687
688   if (N->getOpcode() == ISD::SINT_TO_FP)
689     return;
690
691   // Unsigned - fix up the SINT_TO_FP value just calculated.
692   Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi);
693   SrcVT = Src.getValueType();
694
695   // x>=0 ? (ppcf128)(iN)x : (ppcf128)(iN)x + 2^N; N=32,64,128.
696   static const uint64_t TwoE32[]  = { 0x41f0000000000000LL, 0 };
697   static const uint64_t TwoE64[]  = { 0x43f0000000000000LL, 0 };
698   static const uint64_t TwoE128[] = { 0x47f0000000000000LL, 0 };
699   const uint64_t *Parts = 0;
700
701   switch (SrcVT.getSimpleVT()) {
702   default:
703     assert(false && "Unsupported UINT_TO_FP!");
704   case MVT::i32:
705     Parts = TwoE32;
706   case MVT::i64:
707     Parts = TwoE64;
708   case MVT::i128:
709     Parts = TwoE128;
710   }
711
712   Lo = DAG.getNode(ISD::FADD, VT, Hi,
713                    DAG.getConstantFP(APFloat(APInt(128, 2, Parts)),
714                                      MVT::ppcf128));
715   Lo = DAG.getNode(ISD::SELECT_CC, VT, Src, DAG.getConstant(0, SrcVT), Lo, Hi,
716                    DAG.getCondCode(ISD::SETLT));
717   Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, NVT, Lo,
718                    DAG.getConstant(1, TLI.getPointerTy()));
719   Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, NVT, Lo,
720                    DAG.getConstant(0, TLI.getPointerTy()));
721 }
722
723
724 //===----------------------------------------------------------------------===//
725 //  Float Operand Expansion
726 //===----------------------------------------------------------------------===//
727
728 /// ExpandFloatOperand - This method is called when the specified operand of the
729 /// specified node is found to need expansion.  At this point, all of the result
730 /// types of the node are known to be legal, but other operands of the node may
731 /// need promotion or expansion as well as the specified one.
732 bool DAGTypeLegalizer::ExpandFloatOperand(SDNode *N, unsigned OpNo) {
733   DEBUG(cerr << "Expand float operand: "; N->dump(&DAG); cerr << "\n");
734   SDOperand Res = SDOperand();
735
736   if (TLI.getOperationAction(N->getOpcode(), N->getOperand(OpNo).getValueType())
737       == TargetLowering::Custom)
738     Res = TLI.LowerOperation(SDOperand(N, OpNo), DAG);
739
740   if (Res.Val == 0) {
741     switch (N->getOpcode()) {
742     default:
743   #ifndef NDEBUG
744       cerr << "ExpandFloatOperand Op #" << OpNo << ": ";
745       N->dump(&DAG); cerr << "\n";
746   #endif
747       assert(0 && "Do not know how to expand this operator's operand!");
748       abort();
749
750     case ISD::BIT_CONVERT:     Res = ExpandOp_BIT_CONVERT(N); break;
751     case ISD::BUILD_VECTOR:    Res = ExpandOp_BUILD_VECTOR(N); break;
752     case ISD::EXTRACT_ELEMENT: Res = ExpandOp_EXTRACT_ELEMENT(N); break;
753
754     case ISD::BR_CC:      Res = ExpandFloatOp_BR_CC(N); break;
755     case ISD::FP_ROUND:   Res = ExpandFloatOp_FP_ROUND(N); break;
756     case ISD::FP_TO_SINT: Res = ExpandFloatOp_FP_TO_SINT(N); break;
757     case ISD::FP_TO_UINT: Res = ExpandFloatOp_FP_TO_UINT(N); break;
758     case ISD::SELECT_CC:  Res = ExpandFloatOp_SELECT_CC(N); break;
759     case ISD::SETCC:      Res = ExpandFloatOp_SETCC(N); break;
760     case ISD::STORE:      Res = ExpandFloatOp_STORE(cast<StoreSDNode>(N),
761                                                     OpNo); break;
762     }
763   }
764
765   // If the result is null, the sub-method took care of registering results etc.
766   if (!Res.Val) return false;
767   // If the result is N, the sub-method updated N in place.  Check to see if any
768   // operands are new, and if so, mark them.
769   if (Res.Val == N) {
770     // Mark N as new and remark N and its operands.  This allows us to correctly
771     // revisit N if it needs another step of expansion and allows us to visit
772     // any new operands to N.
773     ReanalyzeNode(N);
774     return true;
775   }
776
777   assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
778          "Invalid operand expansion");
779
780   ReplaceValueWith(SDOperand(N, 0), Res);
781   return false;
782 }
783
784 /// FloatExpandSetCCOperands - Expand the operands of a comparison.  This code
785 /// is shared among BR_CC, SELECT_CC, and SETCC handlers.
786 void DAGTypeLegalizer::FloatExpandSetCCOperands(SDOperand &NewLHS,
787                                                 SDOperand &NewRHS,
788                                                 ISD::CondCode &CCCode) {
789   SDOperand LHSLo, LHSHi, RHSLo, RHSHi;
790   GetExpandedFloat(NewLHS, LHSLo, LHSHi);
791   GetExpandedFloat(NewRHS, RHSLo, RHSHi);
792
793   MVT VT = NewLHS.getValueType();
794   assert(VT == MVT::ppcf128 && "Unsupported setcc type!");
795
796   // FIXME:  This generated code sucks.  We want to generate
797   //         FCMP crN, hi1, hi2
798   //         BNE crN, L:
799   //         FCMP crN, lo1, lo2
800   // The following can be improved, but not that much.
801   SDOperand Tmp1, Tmp2, Tmp3;
802   Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETEQ);
803   Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, CCCode);
804   Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2);
805   Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETNE);
806   Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, CCCode);
807   Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2);
808   NewLHS = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3);
809   NewRHS = SDOperand();   // LHS is the result, not a compare.
810 }
811
812 SDOperand DAGTypeLegalizer::ExpandFloatOp_BR_CC(SDNode *N) {
813   SDOperand NewLHS = N->getOperand(2), NewRHS = N->getOperand(3);
814   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get();
815   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode);
816
817   // If ExpandSetCCOperands returned a scalar, we need to compare the result
818   // against zero to select between true and false values.
819   if (NewRHS.Val == 0) {
820     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
821     CCCode = ISD::SETNE;
822   }
823
824   // Update N to have the operands specified.
825   return DAG.UpdateNodeOperands(SDOperand(N, 0), N->getOperand(0),
826                                 DAG.getCondCode(CCCode), NewLHS, NewRHS,
827                                 N->getOperand(4));
828 }
829
830 SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_ROUND(SDNode *N) {
831   assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
832          "Logic only correct for ppcf128!");
833   SDOperand Lo, Hi;
834   GetExpandedFloat(N->getOperand(0), Lo, Hi);
835   // Round it the rest of the way (e.g. to f32) if needed.
836   return DAG.getNode(ISD::FP_ROUND, N->getValueType(0), Hi, N->getOperand(1));
837 }
838
839 SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_TO_SINT(SDNode *N) {
840   MVT RVT = N->getValueType(0);
841   RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
842   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
843   return MakeLibCall(LC, RVT, &N->getOperand(0), 1, false);
844 }
845
846 SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_TO_UINT(SDNode *N) {
847   MVT RVT = N->getValueType(0);
848   RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
849   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
850   return MakeLibCall(LC, N->getValueType(0), &N->getOperand(0), 1, false);
851 }
852
853 SDOperand DAGTypeLegalizer::ExpandFloatOp_SELECT_CC(SDNode *N) {
854   SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
855   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get();
856   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode);
857
858   // If ExpandSetCCOperands returned a scalar, we need to compare the result
859   // against zero to select between true and false values.
860   if (NewRHS.Val == 0) {
861     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
862     CCCode = ISD::SETNE;
863   }
864
865   // Update N to have the operands specified.
866   return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS,
867                                 N->getOperand(2), N->getOperand(3),
868                                 DAG.getCondCode(CCCode));
869 }
870
871 SDOperand DAGTypeLegalizer::ExpandFloatOp_SETCC(SDNode *N) {
872   SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
873   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get();
874   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode);
875
876   // If ExpandSetCCOperands returned a scalar, use it.
877   if (NewRHS.Val == 0) {
878     assert(NewLHS.getValueType() == N->getValueType(0) &&
879            "Unexpected setcc expansion!");
880     return NewLHS;
881   }
882
883   // Otherwise, update N to have the operands specified.
884   return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS,
885                                 DAG.getCondCode(CCCode));
886 }
887
888 SDOperand DAGTypeLegalizer::ExpandFloatOp_STORE(SDNode *N, unsigned OpNo) {
889   if (ISD::isNormalStore(N))
890     return ExpandOp_NormalStore(N, OpNo);
891
892   assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!");
893   assert(OpNo == 1 && "Can only expand the stored value so far");
894   StoreSDNode *ST = cast<StoreSDNode>(N);
895
896   SDOperand Chain = ST->getChain();
897   SDOperand Ptr = ST->getBasePtr();
898
899   MVT NVT = TLI.getTypeToTransformTo(ST->getValue().getValueType());
900   assert(NVT.isByteSized() && "Expanded type not byte sized!");
901   assert(ST->getMemoryVT().bitsLE(NVT) && "Float type not round?");
902
903   SDOperand Lo, Hi;
904   GetExpandedOp(ST->getValue(), Lo, Hi);
905
906   return DAG.getTruncStore(Chain, Lo, Ptr,
907                            ST->getSrcValue(), ST->getSrcValueOffset(),
908                            ST->getMemoryVT(),
909                            ST->isVolatile(), ST->getAlignment());
910 }