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