diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -446,6 +446,20 @@ } else if (Opts.LongDoubleSize == 128) { LongDoubleWidth = LongDoubleAlign = 128; LongDoubleFormat = &llvm::APFloat::IEEEquad(); + } else if (Opts.LongDoubleSize == 80) { + LongDoubleFormat = &llvm::APFloat::x87DoubleExtended(); + if (getTriple().isWindowsMSVCEnvironment()) { + LongDoubleWidth = 128; + LongDoubleAlign = 128; + } else { // Linux + if (getTriple().getArch() == llvm::Triple::x86) { + LongDoubleWidth = 96; + LongDoubleAlign = 32; + } else { + LongDoubleWidth = 128; + LongDoubleAlign = 128; + } + } } } diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -550,6 +550,14 @@ : WindowsX86_32TargetInfo(Triple, Opts) { LongDoubleWidth = LongDoubleAlign = 64; LongDoubleFormat = &llvm::APFloat::IEEEdouble(); + bool IsWinCOFF = + getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); + if (getTriple().isWindowsMSVCEnvironment()) + resetDataLayout(IsWinCOFF ? "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:" + "64-i64:64-f80:128-n8:16:32-a:0:32-S32" + : "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:" + "64-i64:64-f80:128-n8:16:32-a:0:32-S32", + IsWinCOFF ? "_" : ""); } void getTargetDefines(const LangOptions &Opts, diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3454,6 +3454,8 @@ GenerateArg(Args, OPT_mlong_double_128, SA); else if (Opts.LongDoubleSize == 64) GenerateArg(Args, OPT_mlong_double_64, SA); + else if (Opts.LongDoubleSize == 80) + GenerateArg(Args, OPT_mlong_double_80, SA); // Not generating '-mrtd', it's just an alias for '-fdefault-calling-conv='. @@ -3837,9 +3839,16 @@ Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; if (!Opts.NoBuiltin) getAllNoBuiltinFuncValues(Args, Opts.NoBuiltinFuncs); - Opts.LongDoubleSize = Args.hasArg(OPT_mlong_double_128) - ? 128 - : Args.hasArg(OPT_mlong_double_64) ? 64 : 0; + if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) { + if (A->getOption().matches(options::OPT_mlong_double_64)) + Opts.LongDoubleSize = 64; + else if (A->getOption().matches(options::OPT_mlong_double_80)) + Opts.LongDoubleSize = 80; + else if (A->getOption().matches(options::OPT_mlong_double_128)) + Opts.LongDoubleSize = 128; + else + Opts.LongDoubleSize = 0; + } if (Opts.FastRelaxedMath) Opts.setDefaultFPContractMode(LangOptions::FPM_Fast); llvm::sort(Opts.ModuleFeatures); diff --git a/clang/test/CodeGen/X86/long-double-config-size.c b/clang/test/CodeGen/X86/long-double-config-size.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/X86/long-double-config-size.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-64 -o - | FileCheck %s --check-prefix=SIZE64 +// RUN: %clang_cc1 -triple i386-windows-msvc %s -emit-llvm -mlong-double-80 -o - | FileCheck %s --check-prefix=SIZE80 +// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-80 -o - | FileCheck %s --check-prefix=SIZE80 +// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -mlong-double-128 -o - | FileCheck %s --check-prefix=SIZE128 +// RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck %s --check-prefix=SIZE64 + +long double global; +// SIZE64: @global = dso_local global double 0 +// SIZE80: @global = dso_local global x86_fp80 0xK{{0+}}, align 16 +// SIZE128: @global = dso_local global fp128 0 + +long double func(long double param) { + // SIZE64: define dso_local double @func(double %param) + // SIZE80: define dso_local x86_fp80 @func(x86_fp80 %param) + // SIZE128: define dso_local fp128 @func(fp128 %param) + long double local = param; + // SIZE64: alloca double + // SIZE80: alloca x86_fp80, align 16 + // SIZE128: alloca fp128 + local = param; + return local + param; +} diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c --- a/clang/test/CodeGen/target-data.c +++ b/clang/test/CodeGen/target-data.c @@ -8,7 +8,7 @@ // RUN: %clang_cc1 -triple i686-unknown-win32 -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=I686-WIN32 %s -// I686-WIN32: target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:32-n8:16:32-a:0:32-S32" +// I686-WIN32: target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32-a:0:32-S32" // RUN: %clang_cc1 -triple i686-unknown-cygwin -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=I686-CYGWIN %s diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp --- a/llvm/lib/Target/X86/X86TargetMachine.cpp +++ b/llvm/lib/Target/X86/X86TargetMachine.cpp @@ -127,7 +127,7 @@ // Some ABIs align long double to 128 bits, others to 32. if (TT.isOSNaCl() || TT.isOSIAMCU()) ; // No f80 - else if (TT.isArch64Bit() || TT.isOSDarwin()) + else if (TT.isArch64Bit() || TT.isOSDarwin() || TT.isWindowsMSVCEnvironment()) Ret += "-f80:128"; else Ret += "-f80:32"; diff --git a/llvm/test/CodeGen/X86/long-double-abi-align.ll b/llvm/test/CodeGen/X86/long-double-abi-align.ll --- a/llvm/test/CodeGen/X86/long-double-abi-align.ll +++ b/llvm/test/CodeGen/X86/long-double-abi-align.ll @@ -11,7 +11,7 @@ ; MSVC-NEXT: movl %esp, %ebp ; MSVC-NEXT: andl $-16, %esp ; MSVC-NEXT: subl $32, %esp -; MSVC-NEXT: fldt 12(%ebp) +; MSVC-NEXT: fldt 24(%ebp) ; MSVC-NEXT: fstpt (%esp) ; MSVC-NEXT: leal 8(%ebp), %eax ; MSVC-NEXT: pushl %eax @@ -21,7 +21,7 @@ ; MSVC-NEXT: pushl %eax ; MSVC-NEXT: calll _escape ; MSVC-NEXT: addl $4, %esp -; MSVC-NEXT: leal 24(%ebp), %eax +; MSVC-NEXT: leal 40(%ebp), %eax ; MSVC-NEXT: pushl %eax ; MSVC-NEXT: calll _escape ; MSVC-NEXT: addl $4, %esp diff --git a/llvm/test/CodeGen/X86/scalar-fp-to-i32.ll b/llvm/test/CodeGen/X86/scalar-fp-to-i32.ll --- a/llvm/test/CodeGen/X86/scalar-fp-to-i32.ll +++ b/llvm/test/CodeGen/X86/scalar-fp-to-i32.ll @@ -344,8 +344,8 @@ ; X86-AVX512-WIN: # %bb.0: ; X86-AVX512-WIN-NEXT: pushl %ebp ; X86-AVX512-WIN-NEXT: movl %esp, %ebp -; X86-AVX512-WIN-NEXT: andl $-8, %esp -; X86-AVX512-WIN-NEXT: subl $8, %esp +; X86-AVX512-WIN-NEXT: andl $-16, %esp +; X86-AVX512-WIN-NEXT: subl $16, %esp ; X86-AVX512-WIN-NEXT: fldt 8(%ebp) ; X86-AVX512-WIN-NEXT: fisttpll (%esp) ; X86-AVX512-WIN-NEXT: movl (%esp), %eax @@ -382,8 +382,8 @@ ; X86-SSE3-WIN: # %bb.0: ; X86-SSE3-WIN-NEXT: pushl %ebp ; X86-SSE3-WIN-NEXT: movl %esp, %ebp -; X86-SSE3-WIN-NEXT: andl $-8, %esp -; X86-SSE3-WIN-NEXT: subl $8, %esp +; X86-SSE3-WIN-NEXT: andl $-16, %esp +; X86-SSE3-WIN-NEXT: subl $16, %esp ; X86-SSE3-WIN-NEXT: fldt 8(%ebp) ; X86-SSE3-WIN-NEXT: fisttpll (%esp) ; X86-SSE3-WIN-NEXT: movl (%esp), %eax @@ -420,8 +420,8 @@ ; X86-SSE2-WIN: # %bb.0: ; X86-SSE2-WIN-NEXT: pushl %ebp ; X86-SSE2-WIN-NEXT: movl %esp, %ebp -; X86-SSE2-WIN-NEXT: andl $-8, %esp -; X86-SSE2-WIN-NEXT: subl $16, %esp +; X86-SSE2-WIN-NEXT: andl $-16, %esp +; X86-SSE2-WIN-NEXT: subl $32, %esp ; X86-SSE2-WIN-NEXT: fldt 8(%ebp) ; X86-SSE2-WIN-NEXT: fnstcw {{[0-9]+}}(%esp) ; X86-SSE2-WIN-NEXT: movzwl {{[0-9]+}}(%esp), %eax @@ -482,8 +482,8 @@ ; X86-SSE1-WIN: # %bb.0: ; X86-SSE1-WIN-NEXT: pushl %ebp ; X86-SSE1-WIN-NEXT: movl %esp, %ebp -; X86-SSE1-WIN-NEXT: andl $-8, %esp -; X86-SSE1-WIN-NEXT: subl $16, %esp +; X86-SSE1-WIN-NEXT: andl $-16, %esp +; X86-SSE1-WIN-NEXT: subl $32, %esp ; X86-SSE1-WIN-NEXT: fldt 8(%ebp) ; X86-SSE1-WIN-NEXT: fnstcw {{[0-9]+}}(%esp) ; X86-SSE1-WIN-NEXT: movzwl {{[0-9]+}}(%esp), %eax @@ -516,8 +516,8 @@ ; X87-WIN: # %bb.0: ; X87-WIN-NEXT: pushl %ebp ; X87-WIN-NEXT: movl %esp, %ebp -; X87-WIN-NEXT: andl $-8, %esp -; X87-WIN-NEXT: subl $16, %esp +; X87-WIN-NEXT: andl $-16, %esp +; X87-WIN-NEXT: subl $32, %esp ; X87-WIN-NEXT: fldt 8(%ebp) ; X87-WIN-NEXT: fnstcw {{[0-9]+}}(%esp) ; X87-WIN-NEXT: movzwl {{[0-9]+}}(%esp), %eax @@ -550,14 +550,27 @@ } define i32 @x_to_s32(x86_fp80 %a) nounwind { -; X86-AVX512-LABEL: x_to_s32: -; X86-AVX512: # %bb.0: -; X86-AVX512-NEXT: pushl %eax -; X86-AVX512-NEXT: fldt {{[0-9]+}}(%esp) -; X86-AVX512-NEXT: fisttpl (%esp) -; X86-AVX512-NEXT: movl (%esp), %eax -; X86-AVX512-NEXT: popl %ecx -; X86-AVX512-NEXT: retl +; X86-AVX512-WIN-LABEL: x_to_s32: +; X86-AVX512-WIN: # %bb.0: +; X86-AVX512-WIN-NEXT: pushl %ebp +; X86-AVX512-WIN-NEXT: movl %esp, %ebp +; X86-AVX512-WIN-NEXT: andl $-16, %esp +; X86-AVX512-WIN-NEXT: subl $16, %esp +; X86-AVX512-WIN-NEXT: fldt 8(%ebp) +; X86-AVX512-WIN-NEXT: fisttpl {{[0-9]+}}(%esp) +; X86-AVX512-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-AVX512-WIN-NEXT: movl %ebp, %esp +; X86-AVX512-WIN-NEXT: popl %ebp +; X86-AVX512-WIN-NEXT: retl +; +; X86-AVX512-LIN-LABEL: x_to_s32: +; X86-AVX512-LIN: # %bb.0: +; X86-AVX512-LIN-NEXT: pushl %eax +; X86-AVX512-LIN-NEXT: fldt {{[0-9]+}}(%esp) +; X86-AVX512-LIN-NEXT: fisttpl (%esp) +; X86-AVX512-LIN-NEXT: movl (%esp), %eax +; X86-AVX512-LIN-NEXT: popl %ecx +; X86-AVX512-LIN-NEXT: retl ; ; X64-AVX512-WIN-LABEL: x_to_s32: ; X64-AVX512-WIN: # %bb.0: @@ -575,14 +588,27 @@ ; X64-AVX512-LIN-NEXT: movl -{{[0-9]+}}(%rsp), %eax ; X64-AVX512-LIN-NEXT: retq ; -; X86-SSE3-LABEL: x_to_s32: -; X86-SSE3: # %bb.0: -; X86-SSE3-NEXT: pushl %eax -; X86-SSE3-NEXT: fldt {{[0-9]+}}(%esp) -; X86-SSE3-NEXT: fisttpl (%esp) -; X86-SSE3-NEXT: movl (%esp), %eax -; X86-SSE3-NEXT: popl %ecx -; X86-SSE3-NEXT: retl +; X86-SSE3-WIN-LABEL: x_to_s32: +; X86-SSE3-WIN: # %bb.0: +; X86-SSE3-WIN-NEXT: pushl %ebp +; X86-SSE3-WIN-NEXT: movl %esp, %ebp +; X86-SSE3-WIN-NEXT: andl $-16, %esp +; X86-SSE3-WIN-NEXT: subl $16, %esp +; X86-SSE3-WIN-NEXT: fldt 8(%ebp) +; X86-SSE3-WIN-NEXT: fisttpl {{[0-9]+}}(%esp) +; X86-SSE3-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-SSE3-WIN-NEXT: movl %ebp, %esp +; X86-SSE3-WIN-NEXT: popl %ebp +; X86-SSE3-WIN-NEXT: retl +; +; X86-SSE3-LIN-LABEL: x_to_s32: +; X86-SSE3-LIN: # %bb.0: +; X86-SSE3-LIN-NEXT: pushl %eax +; X86-SSE3-LIN-NEXT: fldt {{[0-9]+}}(%esp) +; X86-SSE3-LIN-NEXT: fisttpl (%esp) +; X86-SSE3-LIN-NEXT: movl (%esp), %eax +; X86-SSE3-LIN-NEXT: popl %ecx +; X86-SSE3-LIN-NEXT: retl ; ; X64-SSE3-WIN-LABEL: x_to_s32: ; X64-SSE3-WIN: # %bb.0: @@ -600,20 +626,39 @@ ; X64-SSE3-LIN-NEXT: movl -{{[0-9]+}}(%rsp), %eax ; X64-SSE3-LIN-NEXT: retq ; -; X86-SSE2-LABEL: x_to_s32: -; X86-SSE2: # %bb.0: -; X86-SSE2-NEXT: subl $8, %esp -; X86-SSE2-NEXT: fldt {{[0-9]+}}(%esp) -; X86-SSE2-NEXT: fnstcw (%esp) -; X86-SSE2-NEXT: movzwl (%esp), %eax -; X86-SSE2-NEXT: orl $3072, %eax # imm = 0xC00 -; X86-SSE2-NEXT: movw %ax, {{[0-9]+}}(%esp) -; X86-SSE2-NEXT: fldcw {{[0-9]+}}(%esp) -; X86-SSE2-NEXT: fistpl {{[0-9]+}}(%esp) -; X86-SSE2-NEXT: fldcw (%esp) -; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax -; X86-SSE2-NEXT: addl $8, %esp -; X86-SSE2-NEXT: retl +; X86-SSE2-WIN-LABEL: x_to_s32: +; X86-SSE2-WIN: # %bb.0: +; X86-SSE2-WIN-NEXT: pushl %ebp +; X86-SSE2-WIN-NEXT: movl %esp, %ebp +; X86-SSE2-WIN-NEXT: andl $-16, %esp +; X86-SSE2-WIN-NEXT: subl $16, %esp +; X86-SSE2-WIN-NEXT: fldt 8(%ebp) +; X86-SSE2-WIN-NEXT: fnstcw (%esp) +; X86-SSE2-WIN-NEXT: movzwl (%esp), %eax +; X86-SSE2-WIN-NEXT: orl $3072, %eax # imm = 0xC00 +; X86-SSE2-WIN-NEXT: movw %ax, {{[0-9]+}}(%esp) +; X86-SSE2-WIN-NEXT: fldcw {{[0-9]+}}(%esp) +; X86-SSE2-WIN-NEXT: fistpl {{[0-9]+}}(%esp) +; X86-SSE2-WIN-NEXT: fldcw (%esp) +; X86-SSE2-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-SSE2-WIN-NEXT: movl %ebp, %esp +; X86-SSE2-WIN-NEXT: popl %ebp +; X86-SSE2-WIN-NEXT: retl +; +; X86-SSE2-LIN-LABEL: x_to_s32: +; X86-SSE2-LIN: # %bb.0: +; X86-SSE2-LIN-NEXT: subl $8, %esp +; X86-SSE2-LIN-NEXT: fldt {{[0-9]+}}(%esp) +; X86-SSE2-LIN-NEXT: fnstcw (%esp) +; X86-SSE2-LIN-NEXT: movzwl (%esp), %eax +; X86-SSE2-LIN-NEXT: orl $3072, %eax # imm = 0xC00 +; X86-SSE2-LIN-NEXT: movw %ax, {{[0-9]+}}(%esp) +; X86-SSE2-LIN-NEXT: fldcw {{[0-9]+}}(%esp) +; X86-SSE2-LIN-NEXT: fistpl {{[0-9]+}}(%esp) +; X86-SSE2-LIN-NEXT: fldcw (%esp) +; X86-SSE2-LIN-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-SSE2-LIN-NEXT: addl $8, %esp +; X86-SSE2-LIN-NEXT: retl ; ; X64-SSE2-WIN-LABEL: x_to_s32: ; X64-SSE2-WIN: # %bb.0: @@ -643,35 +688,73 @@ ; X64-SSE2-LIN-NEXT: movl -{{[0-9]+}}(%rsp), %eax ; X64-SSE2-LIN-NEXT: retq ; -; X86-SSE1-LABEL: x_to_s32: -; X86-SSE1: # %bb.0: -; X86-SSE1-NEXT: subl $8, %esp -; X86-SSE1-NEXT: fldt {{[0-9]+}}(%esp) -; X86-SSE1-NEXT: fnstcw (%esp) -; X86-SSE1-NEXT: movzwl (%esp), %eax -; X86-SSE1-NEXT: orl $3072, %eax # imm = 0xC00 -; X86-SSE1-NEXT: movw %ax, {{[0-9]+}}(%esp) -; X86-SSE1-NEXT: fldcw {{[0-9]+}}(%esp) -; X86-SSE1-NEXT: fistpl {{[0-9]+}}(%esp) -; X86-SSE1-NEXT: fldcw (%esp) -; X86-SSE1-NEXT: movl {{[0-9]+}}(%esp), %eax -; X86-SSE1-NEXT: addl $8, %esp -; X86-SSE1-NEXT: retl +; X86-SSE1-WIN-LABEL: x_to_s32: +; X86-SSE1-WIN: # %bb.0: +; X86-SSE1-WIN-NEXT: pushl %ebp +; X86-SSE1-WIN-NEXT: movl %esp, %ebp +; X86-SSE1-WIN-NEXT: andl $-16, %esp +; X86-SSE1-WIN-NEXT: subl $16, %esp +; X86-SSE1-WIN-NEXT: fldt 8(%ebp) +; X86-SSE1-WIN-NEXT: fnstcw (%esp) +; X86-SSE1-WIN-NEXT: movzwl (%esp), %eax +; X86-SSE1-WIN-NEXT: orl $3072, %eax # imm = 0xC00 +; X86-SSE1-WIN-NEXT: movw %ax, {{[0-9]+}}(%esp) +; X86-SSE1-WIN-NEXT: fldcw {{[0-9]+}}(%esp) +; X86-SSE1-WIN-NEXT: fistpl {{[0-9]+}}(%esp) +; X86-SSE1-WIN-NEXT: fldcw (%esp) +; X86-SSE1-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-SSE1-WIN-NEXT: movl %ebp, %esp +; X86-SSE1-WIN-NEXT: popl %ebp +; X86-SSE1-WIN-NEXT: retl ; -; X87-LABEL: x_to_s32: -; X87: # %bb.0: -; X87-NEXT: subl $8, %esp -; X87-NEXT: fldt {{[0-9]+}}(%esp) -; X87-NEXT: fnstcw (%esp) -; X87-NEXT: movzwl (%esp), %eax -; X87-NEXT: orl $3072, %eax # imm = 0xC00 -; X87-NEXT: movw %ax, {{[0-9]+}}(%esp) -; X87-NEXT: fldcw {{[0-9]+}}(%esp) -; X87-NEXT: fistpl {{[0-9]+}}(%esp) -; X87-NEXT: fldcw (%esp) -; X87-NEXT: movl {{[0-9]+}}(%esp), %eax -; X87-NEXT: addl $8, %esp -; X87-NEXT: retl +; X86-SSE1-LIN-LABEL: x_to_s32: +; X86-SSE1-LIN: # %bb.0: +; X86-SSE1-LIN-NEXT: subl $8, %esp +; X86-SSE1-LIN-NEXT: fldt {{[0-9]+}}(%esp) +; X86-SSE1-LIN-NEXT: fnstcw (%esp) +; X86-SSE1-LIN-NEXT: movzwl (%esp), %eax +; X86-SSE1-LIN-NEXT: orl $3072, %eax # imm = 0xC00 +; X86-SSE1-LIN-NEXT: movw %ax, {{[0-9]+}}(%esp) +; X86-SSE1-LIN-NEXT: fldcw {{[0-9]+}}(%esp) +; X86-SSE1-LIN-NEXT: fistpl {{[0-9]+}}(%esp) +; X86-SSE1-LIN-NEXT: fldcw (%esp) +; X86-SSE1-LIN-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-SSE1-LIN-NEXT: addl $8, %esp +; X86-SSE1-LIN-NEXT: retl +; +; X87-WIN-LABEL: x_to_s32: +; X87-WIN: # %bb.0: +; X87-WIN-NEXT: pushl %ebp +; X87-WIN-NEXT: movl %esp, %ebp +; X87-WIN-NEXT: andl $-16, %esp +; X87-WIN-NEXT: subl $16, %esp +; X87-WIN-NEXT: fldt 8(%ebp) +; X87-WIN-NEXT: fnstcw (%esp) +; X87-WIN-NEXT: movzwl (%esp), %eax +; X87-WIN-NEXT: orl $3072, %eax # imm = 0xC00 +; X87-WIN-NEXT: movw %ax, {{[0-9]+}}(%esp) +; X87-WIN-NEXT: fldcw {{[0-9]+}}(%esp) +; X87-WIN-NEXT: fistpl {{[0-9]+}}(%esp) +; X87-WIN-NEXT: fldcw (%esp) +; X87-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax +; X87-WIN-NEXT: movl %ebp, %esp +; X87-WIN-NEXT: popl %ebp +; X87-WIN-NEXT: retl +; +; X87-LIN-LABEL: x_to_s32: +; X87-LIN: # %bb.0: +; X87-LIN-NEXT: subl $8, %esp +; X87-LIN-NEXT: fldt {{[0-9]+}}(%esp) +; X87-LIN-NEXT: fnstcw (%esp) +; X87-LIN-NEXT: movzwl (%esp), %eax +; X87-LIN-NEXT: orl $3072, %eax # imm = 0xC00 +; X87-LIN-NEXT: movw %ax, {{[0-9]+}}(%esp) +; X87-LIN-NEXT: fldcw {{[0-9]+}}(%esp) +; X87-LIN-NEXT: fistpl {{[0-9]+}}(%esp) +; X87-LIN-NEXT: fldcw (%esp) +; X87-LIN-NEXT: movl {{[0-9]+}}(%esp), %eax +; X87-LIN-NEXT: addl $8, %esp +; X87-LIN-NEXT: retl %r = fptosi x86_fp80 %a to i32 ret i32 %r } diff --git a/llvm/test/CodeGen/X86/scalar-fp-to-i64.ll b/llvm/test/CodeGen/X86/scalar-fp-to-i64.ll --- a/llvm/test/CodeGen/X86/scalar-fp-to-i64.ll +++ b/llvm/test/CodeGen/X86/scalar-fp-to-i64.ll @@ -909,8 +909,8 @@ ; X86-AVX512-WIN: # %bb.0: ; X86-AVX512-WIN-NEXT: pushl %ebp ; X86-AVX512-WIN-NEXT: movl %esp, %ebp -; X86-AVX512-WIN-NEXT: andl $-8, %esp -; X86-AVX512-WIN-NEXT: subl $8, %esp +; X86-AVX512-WIN-NEXT: andl $-16, %esp +; X86-AVX512-WIN-NEXT: subl $16, %esp ; X86-AVX512-WIN-NEXT: fldt 8(%ebp) ; X86-AVX512-WIN-NEXT: flds __real@5f000000 ; X86-AVX512-WIN-NEXT: xorl %edx, %edx @@ -985,8 +985,8 @@ ; X86-SSE3-WIN: # %bb.0: ; X86-SSE3-WIN-NEXT: pushl %ebp ; X86-SSE3-WIN-NEXT: movl %esp, %ebp -; X86-SSE3-WIN-NEXT: andl $-8, %esp -; X86-SSE3-WIN-NEXT: subl $8, %esp +; X86-SSE3-WIN-NEXT: andl $-16, %esp +; X86-SSE3-WIN-NEXT: subl $16, %esp ; X86-SSE3-WIN-NEXT: fldt 8(%ebp) ; X86-SSE3-WIN-NEXT: flds __real@5f000000 ; X86-SSE3-WIN-NEXT: xorl %edx, %edx @@ -1061,8 +1061,8 @@ ; X86-SSE2-WIN: # %bb.0: ; X86-SSE2-WIN-NEXT: pushl %ebp ; X86-SSE2-WIN-NEXT: movl %esp, %ebp -; X86-SSE2-WIN-NEXT: andl $-8, %esp -; X86-SSE2-WIN-NEXT: subl $16, %esp +; X86-SSE2-WIN-NEXT: andl $-16, %esp +; X86-SSE2-WIN-NEXT: subl $32, %esp ; X86-SSE2-WIN-NEXT: fldt 8(%ebp) ; X86-SSE2-WIN-NEXT: flds __real@5f000000 ; X86-SSE2-WIN-NEXT: xorl %edx, %edx @@ -1161,8 +1161,8 @@ ; X87-WIN: # %bb.0: ; X87-WIN-NEXT: pushl %ebp ; X87-WIN-NEXT: movl %esp, %ebp -; X87-WIN-NEXT: andl $-8, %esp -; X87-WIN-NEXT: subl $16, %esp +; X87-WIN-NEXT: andl $-16, %esp +; X87-WIN-NEXT: subl $32, %esp ; X87-WIN-NEXT: fldt 8(%ebp) ; X87-WIN-NEXT: flds __real@5f000000 ; X87-WIN-NEXT: fucom %st(1) @@ -1235,8 +1235,8 @@ ; X86-AVX512-WIN: # %bb.0: ; X86-AVX512-WIN-NEXT: pushl %ebp ; X86-AVX512-WIN-NEXT: movl %esp, %ebp -; X86-AVX512-WIN-NEXT: andl $-8, %esp -; X86-AVX512-WIN-NEXT: subl $8, %esp +; X86-AVX512-WIN-NEXT: andl $-16, %esp +; X86-AVX512-WIN-NEXT: subl $16, %esp ; X86-AVX512-WIN-NEXT: fldt 8(%ebp) ; X86-AVX512-WIN-NEXT: fisttpll (%esp) ; X86-AVX512-WIN-NEXT: movl (%esp), %eax @@ -1275,8 +1275,8 @@ ; X86-SSE3-WIN: # %bb.0: ; X86-SSE3-WIN-NEXT: pushl %ebp ; X86-SSE3-WIN-NEXT: movl %esp, %ebp -; X86-SSE3-WIN-NEXT: andl $-8, %esp -; X86-SSE3-WIN-NEXT: subl $8, %esp +; X86-SSE3-WIN-NEXT: andl $-16, %esp +; X86-SSE3-WIN-NEXT: subl $16, %esp ; X86-SSE3-WIN-NEXT: fldt 8(%ebp) ; X86-SSE3-WIN-NEXT: fisttpll (%esp) ; X86-SSE3-WIN-NEXT: movl (%esp), %eax @@ -1315,8 +1315,8 @@ ; X86-SSE2-WIN: # %bb.0: ; X86-SSE2-WIN-NEXT: pushl %ebp ; X86-SSE2-WIN-NEXT: movl %esp, %ebp -; X86-SSE2-WIN-NEXT: andl $-8, %esp -; X86-SSE2-WIN-NEXT: subl $16, %esp +; X86-SSE2-WIN-NEXT: andl $-16, %esp +; X86-SSE2-WIN-NEXT: subl $32, %esp ; X86-SSE2-WIN-NEXT: fldt 8(%ebp) ; X86-SSE2-WIN-NEXT: fnstcw {{[0-9]+}}(%esp) ; X86-SSE2-WIN-NEXT: movzwl {{[0-9]+}}(%esp), %eax @@ -1379,8 +1379,8 @@ ; X87-WIN: # %bb.0: ; X87-WIN-NEXT: pushl %ebp ; X87-WIN-NEXT: movl %esp, %ebp -; X87-WIN-NEXT: andl $-8, %esp -; X87-WIN-NEXT: subl $16, %esp +; X87-WIN-NEXT: andl $-16, %esp +; X87-WIN-NEXT: subl $32, %esp ; X87-WIN-NEXT: fldt 8(%ebp) ; X87-WIN-NEXT: fnstcw {{[0-9]+}}(%esp) ; X87-WIN-NEXT: movzwl {{[0-9]+}}(%esp), %eax