[llvm-commits] SoftenFloatOp support for fp_round

Duncan Sands baldrick at free.fr
Mon Aug 4 00:24:30 PDT 2008


Hi Bruno,

+SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N) {
+  MVT VT = N->getValueType(0);
+  assert((VT == MVT::f64 || VT == MVT::f32) && 
+         "Don't know how to soften other FABS result types");

it is easy to support any width, so best to do so (see below).

+
+  MVT NVT = TLI.getTypeToTransformTo(VT);
+  SDValue Lo = GetSoftenedFloat(N->getOperand(0));
+  SDValue Mask = (VT == MVT::f64)
+      ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT)
+      : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT);
+  Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask);

What you are doing here is bitcasting 1 << 63 to a double,
then bitcasting that double back again to an integer.  Why
don't you directly generate the integer?  That way it also
works for any floating point type.  What you need to do is
create an APInt with bitwidth NVT->getSizeInBits(), and use
some APInt method to set the top bit.  Then Mask is simply
DAG.getConstant(MyAPInt, NVT).

+  return DAG.getNode(ISD::AND, NVT, Lo, Mask);
+}

+SDValue DAGTypeLegalizer::SoftenFloatOp_FP_ROUND(SDNode *N) {
+  MVT SVT = N->getOperand(0).getValueType();
+  MVT RVT = TLI.getTypeToTransformTo(N->getValueType(0));

This should be: MVT RVT = N->getValueType(0);
This type is necessarily legal (because LegalizeTypes always
legalizes return types before operands; the result is that if
you are in operand legalization then you can be sure that the
return types are all legal).  So TLI.getTypeToTransformTo is
a no-op.

+  RTLIB::Libcall LC = RTLIB::getFPROUND(SVT, RVT);
+  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND libcall");
+
+  SDValue Op = GetSoftenedFloat(N->getOperand(0));
+  return MakeLibCall(LC, RVT, &Op, 1, false);
+}

Otherwise it's ok.

Thanks!

Duncan.



More information about the llvm-commits mailing list