[llvm-commits] [llvm] r58994 - in /llvm/trunk: lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp lib/CodeGen/SelectionDAG/LegalizeTypes.h test/CodeGen/Mips/2008-11-10-xint_to_fp.ll

Bruno Cardoso Lopes bruno.cardoso at gmail.com
Mon Nov 10 09:47:30 PST 2008


Hi Duncan,

Thanks for fixing this! :)

On Mon, Nov 10, 2008 at 3:36 PM, Duncan Sands <baldrick at free.fr> wrote:
> Author: baldrick
> Date: Mon Nov 10 11:36:26 2008
> New Revision: 58994
>
> URL: http://llvm.org/viewvc/llvm-project?rev=58994&view=rev
> Log:
> Fix PR2667: add soft float support for sint_to_fp/uint_to_fp
> where the argument is an apint, or smaller than the minimum
> size for which there is a libcall (i32).
>
> Added:
>    llvm/trunk/test/CodeGen/Mips/2008-11-10-xint_to_fp.ll
> Modified:
>    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
>    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp?rev=58994&r1=58993&r2=58994&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp Mon Nov 10 11:36:26 2008
> @@ -72,8 +72,8 @@
>     case ISD::LOAD:        R = SoftenFloatRes_LOAD(N); break;
>     case ISD::SELECT:      R = SoftenFloatRes_SELECT(N); break;
>     case ISD::SELECT_CC:   R = SoftenFloatRes_SELECT_CC(N); break;
> -    case ISD::SINT_TO_FP:  R = SoftenFloatRes_SINT_TO_FP(N); break;
> -    case ISD::UINT_TO_FP:  R = SoftenFloatRes_UINT_TO_FP(N); break;
> +    case ISD::SINT_TO_FP:
> +    case ISD::UINT_TO_FP:  R = SoftenFloatRes_XINT_TO_FP(N); break;
>   }
>
>   // If R is null, the sub-method took care of registering the result.
> @@ -213,6 +213,8 @@
>  }
>
>  SDValue DAGTypeLegalizer::SoftenFloatRes_FPOWI(SDNode *N) {
> +  assert(N->getOperand(1).getValueType() == MVT::i32 &&
> +         "Unsupported power type!");
>   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
>   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)), N->getOperand(1) };
>   return MakeLibCall(GetFPLibCall(N->getValueType(0),
> @@ -278,19 +280,28 @@
>                      N->getOperand(1), LHS, RHS, N->getOperand(4));
>  }
>
> -SDValue DAGTypeLegalizer::SoftenFloatRes_SINT_TO_FP(SDNode *N) {
> -  SDValue Op = N->getOperand(0);
> +SDValue DAGTypeLegalizer::SoftenFloatRes_XINT_TO_FP(SDNode *N) {
> +  bool Signed = N->getOpcode() == ISD::SINT_TO_FP;
> +  MVT SVT = N->getOperand(0).getValueType();
>   MVT RVT = N->getValueType(0);
> -  RTLIB::Libcall LC = RTLIB::getSINTTOFP(Op.getValueType(), RVT);
> -  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SINT_TO_FP!");
> -  return MakeLibCall(LC, TLI.getTypeToTransformTo(RVT), &Op, 1, false);
> -}
> +  MVT NVT = MVT();
>
> -SDValue DAGTypeLegalizer::SoftenFloatRes_UINT_TO_FP(SDNode *N) {
> -  SDValue Op = N->getOperand(0);
> -  MVT RVT = N->getValueType(0);
> -  RTLIB::Libcall LC = RTLIB::getUINTTOFP(Op.getValueType(), RVT);
> -  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported UINT_TO_FP!");
> +  // If the input is not legal, eg: i1 -> fp, then it needs to be promoted to
> +  // a larger type, eg: i8 -> fp.  Even if it is legal, no libcall may exactly
> +  // match.  Look for an appropriate libcall.
> +  RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
> +  for (unsigned t = MVT::FIRST_INTEGER_VALUETYPE;
> +       t <= MVT::LAST_INTEGER_VALUETYPE && LC == RTLIB::UNKNOWN_LIBCALL; ++t) {
> +    NVT = (MVT::SimpleValueType)t;
> +    // The source needs to big enough to hold the operand.
> +    if (NVT.bitsGE(SVT))
> +      LC = Signed ? RTLIB::getSINTTOFP(NVT, RVT):RTLIB::getUINTTOFP (NVT, RVT);
> +  }
> +  assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XINT_TO_FP!");
> +
> +  // Sign/zero extend the argument if the libcall takes a larger type.
> +  SDValue Op = DAG.getNode(Signed ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND,
> +                           NVT, N->getOperand(0));
>   return MakeLibCall(LC, TLI.getTypeToTransformTo(RVT), &Op, 1, false);
>  }
>
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h?rev=58994&r1=58993&r2=58994&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h Mon Nov 10 11:36:26 2008
> @@ -360,8 +360,7 @@
>   SDValue SoftenFloatRes_LOAD(SDNode *N);
>   SDValue SoftenFloatRes_SELECT(SDNode *N);
>   SDValue SoftenFloatRes_SELECT_CC(SDNode *N);
> -  SDValue SoftenFloatRes_SINT_TO_FP(SDNode *N);
> -  SDValue SoftenFloatRes_UINT_TO_FP(SDNode *N);
> +  SDValue SoftenFloatRes_XINT_TO_FP(SDNode *N);
>
>   // Operand Float to Integer Conversion.
>   bool SoftenFloatOperand(SDNode *N, unsigned OpNo);
>
> Added: llvm/trunk/test/CodeGen/Mips/2008-11-10-xint_to_fp.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/2008-11-10-xint_to_fp.ll?rev=58994&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/CodeGen/Mips/2008-11-10-xint_to_fp.ll (added)
> +++ llvm/trunk/test/CodeGen/Mips/2008-11-10-xint_to_fp.ll Mon Nov 10 11:36:26 2008
> @@ -0,0 +1,55 @@
> +; RUN: llvm-as < %s | llc
> +; PR2667
> +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
> +target triple = "psp"
> +       %struct._Bigint = type { %struct._Bigint*, i32, i32, i32, i32, [1 x i32] }
> +       %struct.__FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*, i8*, i32)*, i32 (i8*, i8*, i32)*, i32 (i8*, i32, i32)*, i32 (i8*)*, %struct.__sbuf, i8*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i32, %struct._reent*, i32 }
> +       %struct.__sbuf = type { i8*, i32 }
> +       %struct._atexit = type { %struct._atexit*, i32, [32 x void ()*], %struct._on_exit_args }
> +       %struct._glue = type { %struct._glue*, i32, %struct.__FILE* }
> +       %struct._on_exit_args = type { [32 x i8*], [32 x i8*], i32, i32 }
> +       %struct._reent = type { i32, %struct.__FILE*, %struct.__FILE*, %struct.__FILE*, i32, [25 x i8], i32, i8*, i32, void (%struct._reent*)*, %struct._Bigint*, i32, %struct._Bigint*, %struct._Bigint**, i32, i8*, { { [30 x i8*], [30 x i32] } }, %struct._atexit*, %struct._atexit, void (i32)**, %struct._glue, [3 x %struct.__FILE] }
> + at _impure_ptr = external global %struct._reent*         ; <%struct._reent**> [#uses=1]
> +
> +define double @_erand48_r(%struct._reent* %r, i16* %xseed) nounwind {
> +entry:
> +       tail call void @__dorand48( %struct._reent* %r, i16* %xseed ) nounwind
> +       load i16* %xseed, align 2               ; <i16>:0 [#uses=1]
> +       uitofp i16 %0 to double         ; <double>:1 [#uses=1]
> +       tail call double @ldexp( double %1, i32 -48 ) nounwind          ; <double>:2 [#uses=1]
> +       getelementptr i16* %xseed, i32 1                ; <i16*>:3 [#uses=1]
> +       load i16* %3, align 2           ; <i16>:4 [#uses=1]
> +       uitofp i16 %4 to double         ; <double>:5 [#uses=1]
> +       tail call double @ldexp( double %5, i32 -32 ) nounwind          ; <double>:6 [#uses=1]
> +       add double %2, %6               ; <double>:7 [#uses=1]
> +       getelementptr i16* %xseed, i32 2                ; <i16*>:8 [#uses=1]
> +       load i16* %8, align 2           ; <i16>:9 [#uses=1]
> +       uitofp i16 %9 to double         ; <double>:10 [#uses=1]
> +       tail call double @ldexp( double %10, i32 -16 ) nounwind         ; <double>:11 [#uses=1]
> +       add double %7, %11              ; <double>:12 [#uses=1]
> +       ret double %12
> +}
> +
> +declare void @__dorand48(%struct._reent*, i16*)
> +
> +declare double @ldexp(double, i32)
> +
> +define double @erand48(i16* %xseed) nounwind {
> +entry:
> +       load %struct._reent** @_impure_ptr, align 4             ; <%struct._reent*>:0 [#uses=1]
> +       tail call void @__dorand48( %struct._reent* %0, i16* %xseed ) nounwind
> +       load i16* %xseed, align 2               ; <i16>:1 [#uses=1]
> +       uitofp i16 %1 to double         ; <double>:2 [#uses=1]
> +       tail call double @ldexp( double %2, i32 -48 ) nounwind          ; <double>:3 [#uses=1]
> +       getelementptr i16* %xseed, i32 1                ; <i16*>:4 [#uses=1]
> +       load i16* %4, align 2           ; <i16>:5 [#uses=1]
> +       uitofp i16 %5 to double         ; <double>:6 [#uses=1]
> +       tail call double @ldexp( double %6, i32 -32 ) nounwind          ; <double>:7 [#uses=1]
> +       add double %3, %7               ; <double>:8 [#uses=1]
> +       getelementptr i16* %xseed, i32 2                ; <i16*>:9 [#uses=1]
> +       load i16* %9, align 2           ; <i16>:10 [#uses=1]
> +       uitofp i16 %10 to double                ; <double>:11 [#uses=1]
> +       tail call double @ldexp( double %11, i32 -16 ) nounwind         ; <double>:12 [#uses=1]
> +       add double %8, %12              ; <double>:13 [#uses=1]
> +       ret double %13
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



-- 
Bruno Cardoso Lopes
http://www.brunocardoso.cc
"When faced with untenable alternatives, you
 should consider your imperative."



More information about the llvm-commits mailing list