Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -199,23 +199,29 @@ setOperationAction(ISD::SINT_TO_FP , MVT::i32 , Promote); } - // In 32-bit mode these are custom lowered. In 64-bit mode F32 and F64 - // are Legal, f80 is custom lowered. - setOperationAction(ISD::FP_TO_SINT , MVT::i64 , Custom); - setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom); - // Promote i1/i8 FP_TO_SINT to larger FP_TO_SINTS's, as X86 doesn't have // this operation. setOperationAction(ISD::FP_TO_SINT , MVT::i1 , Promote); setOperationAction(ISD::FP_TO_SINT , MVT::i8 , Promote); - if (X86ScalarSSEf32) { - setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Promote); - // f32 and f64 cases are Legal, f80 case is not - setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom); + if (!Subtarget->useSoftFloat()) { + // In 32-bit mode these are custom lowered. In 64-bit mode F32 and F64 + // are Legal, f80 is custom lowered. + setOperationAction(ISD::FP_TO_SINT , MVT::i64 , Custom); + setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom); + + if (X86ScalarSSEf32) { + setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Promote); + // f32 and f64 cases are Legal, f80 case is not + setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom); + } else { + setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Custom); + setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom); + } } else { - setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Custom); - setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom); + setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Promote); + setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Expand); + setOperationAction(ISD::FP_TO_SINT , MVT::i64 , Expand); } // Handle FP_TO_UINT by promoting the destination to a larger signed Index: test/CodeGen/X86/soft-sitofp.ll =================================================================== --- test/CodeGen/X86/soft-sitofp.ll +++ test/CodeGen/X86/soft-sitofp.ll @@ -12,4 +12,124 @@ ret double %conv } +; CHECK-LABEL: ll_to_f: +; CHECK: calll __floatdisf +define float @ll_to_f(i64 %n) #0 { +entry: + %conv = sitofp i64 %n to float + ret float %conv +} + +; CHECK-LABEL: l_to_d: +; CHECK: calll __floatsidf +define double @l_to_d(i32 %n) #0 { +entry: + %conv = sitofp i32 %n to double + ret double %conv +} + +; CHECK-LABEL: l_to_f: +; CHECK: calll __floatsisf +define float @l_to_f(i32 %n) #0 { +entry: + %conv = sitofp i32 %n to float + ret float %conv +} + +; CHECK-LABEL: ull_to_d: +; CHECK: calll __floatundidf +define double @ull_to_d(i64 %n) #0 { +entry: + %conv = uitofp i64 %n to double + ret double %conv +} + +; CHECK-LABEL: ull_to_f: +; CHECK: calll __floatundisf +define float @ull_to_f(i64 %n) #0 { +entry: + %conv = uitofp i64 %n to float + ret float %conv +} + +; CHECK-LABEL: ul_to_d: +; CHECK: calll __floatunsidf +define double @ul_to_d(i32 %n) #0 { +entry: + %conv = uitofp i32 %n to double + ret double %conv +} + +; CHECK-LABEL: ul_to_f: +; CHECK: calll __floatunsisf +define float @ul_to_f(i32 %n) #0 { +entry: + %conv = uitofp i32 %n to float + ret float %conv +} + +; CHECK-LABEL: d_to_ll: +; CHECK: calll __fixdfdi +define i64 @d_to_ll(double %n) #0 { +entry: + %conv = fptosi double %n to i64 + ret i64 %conv +} + +; CHECK-LABEL: d_to_l: +; CHECK: calll __fixdfsi +define i32 @d_to_l(double %n) #0 { +entry: + %conv = fptosi double %n to i32 + ret i32 %conv +} + +; CHECK-LABEL: f_to_ll: +; CHECK: calll __fixsfdi +define i64 @f_to_ll(float %n) #0 { +entry: + %conv = fptosi float %n to i64 + ret i64 %conv +} + +; CHECK-LABEL: f_to_l: +; CHECK: calll __fixsfsi +define i32 @f_to_l(float %n) #0 { +entry: + %conv = fptosi float %n to i32 + ret i32 %conv +} + +; CHECK-LABEL: d_to_ull: +; CHECK: calll __fixunsdfdi +define i64 @d_to_ull(double %n) #0 { +entry: + %conv = fptoui double %n to i64 + ret i64 %conv +} + +; CHECK-LABEL: d_to_ul: +; CHECK: calll __fixunsdfsi +define i32 @d_to_ul(double %n) #0 { +entry: + %conv = fptoui double %n to i32 + ret i32 %conv +} + +; CHECK-LABEL: f_to_ull: +; CHECK: calll __fixunssfdi +define i64 @f_to_ull(float %n) #0 { +entry: + %conv = fptoui float %n to i64 + ret i64 %conv +} + +; CHECK-LABEL: f_to_ul: +; CHECK: calll __fixunssfsi +define i32 @f_to_ul(float %n) #0 { +entry: + %conv = fptoui float %n to i32 + ret i32 %conv +} + attributes #0 = { nounwind "use-soft-float"="true" }