[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled
Pengfei Wang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 20 08:32:51 PDT 2021
pengfei created this revision.
pengfei added reviewers: aturetsk, echristo, RKSimon, LuoYuanke, craig.topper.
Herald added subscribers: dang, hiraditya.
pengfei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.
This is aligned with GCC's behavior.
Also, alias `-mno-fp-ret-in-387` to `-mno-x87`, by which we can fix pr51498.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112143
Files:
clang/include/clang/Driver/Options.td
clang/test/Driver/x86-target-features.c
llvm/lib/Target/X86/X86CallingConv.td
llvm/test/CodeGen/X86/no-x87.ll
Index: llvm/test/CodeGen/X86/no-x87.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/no-x87.ll
@@ -0,0 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=i686-- | FileCheck %s -check-prefix=X87
+; RUN: llc < %s -mtriple=i686-- -mattr=-x87 | FileCheck %s -check-prefix=NOX87
+
+define float @foo(float %a, float %b) nounwind {
+; X87-LABEL: foo:
+; X87: # %bb.0: # %entry
+; X87-NEXT: flds {{[0-9]+}}(%esp)
+; X87-NEXT: retl
+;
+; NOX87-LABEL: foo:
+; NOX87: # %bb.0: # %entry
+; NOX87-NEXT: movl {{[0-9]+}}(%esp), %eax
+; NOX87-NEXT: retl
+entry:
+ ret float %b
+}
Index: llvm/lib/Target/X86/X86CallingConv.td
===================================================================
--- llvm/lib/Target/X86/X86CallingConv.td
+++ llvm/lib/Target/X86/X86CallingConv.td
@@ -273,6 +273,10 @@
// conv.
CCIfInReg<CCIfSubtarget<"hasSSE2()",
CCIfType<[f32, f64], CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
+ CCIfNotSubtarget<"hasX87()",
+ CCIfType<[f32], CCAssignToReg<[AX, DX, CX]>>>,
+ CCIfNotSubtarget<"hasX87()",
+ CCIfType<[f64], CCAssignToReg<[EAX, EDX, ECX]>>>,
CCIfType<[f32,f64], CCAssignToReg<[FP0, FP1]>>,
CCIfType<[f16], CCAssignToReg<[XMM0,XMM1,XMM2]>>,
CCDelegateTo<RetCC_X86Common>
Index: clang/test/Driver/x86-target-features.c
===================================================================
--- clang/test/Driver/x86-target-features.c
+++ clang/test/Driver/x86-target-features.c
@@ -2,6 +2,7 @@
// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-x87 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-X87 %s
// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -m80387 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=X87 %s
// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-80387 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-X87 %s
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-fp-ret-in-387 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-X87 %s
// X87: "-target-feature" "+x87"
// NO-X87: "-target-feature" "-x87"
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4166,6 +4166,7 @@
def mno_x87 : Flag<["-"], "mno-x87">, Group<m_x86_Features_Group>;
def m80387 : Flag<["-"], "m80387">, Alias<mx87>;
def mno_80387 : Flag<["-"], "mno-80387">, Alias<mno_x87>;
+def mno_fp_ret_in_387 : Flag<["-"], "mno-fp-ret-in-387">, Alias<mno_x87>;
def mmmx : Flag<["-"], "mmmx">, Group<m_x86_Features_Group>;
def mno_mmx : Flag<["-"], "mno-mmx">, Group<m_x86_Features_Group>;
def m3dnow : Flag<["-"], "m3dnow">, Group<m_x86_Features_Group>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112143.380969.patch
Type: text/x-patch
Size: 2822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211020/7d516f93/attachment.bin>
More information about the cfe-commits
mailing list