[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-11-17 Thread Phoebe Wang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa9fba2be35db: [X86][ABI] Do not return float/double from x87 
registers when x87 is disabled (authored by pengfei).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

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/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll

Index: llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll
@@ -0,0 +1,193 @@
+; 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-prefixes=NOX87,NOSSE-NOX87
+; RUN: llc < %s -mtriple=i686-- -mattr=-x87,-sse2 | FileCheck %s -check-prefixes=NOX87,NOSSE-NOX87
+; RUN: llc < %s -mtriple=i686-- -mattr=-x87,+sse2 | FileCheck %s -check-prefixes=NOX87,SSE-NOX87
+
+define float @f1(float %a, float %b) nounwind {
+; X87-LABEL: f1:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:flds {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f1:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:movl {{[0-9]+}}(%esp), %eax
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f1:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:movd {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; SSE-NOX87-NEXT:movd %xmm0, %eax
+; SSE-NOX87-NEXT:retl
+entry:
+  ret float %b
+}
+
+define double @f2(double %a, double %b) nounwind {
+; X87-LABEL: f2:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldl {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOX87-LABEL: f2:
+; NOX87:   # %bb.0: # %entry
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %eax
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %edx
+; NOX87-NEXT:retl
+entry:
+  ret double %b
+}
+
+define x86_fp80 @f3(x86_fp80 %a, x86_fp80 %b) nounwind {
+; X87-LABEL: f3:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldt {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOX87-LABEL: f3:
+; NOX87:   # %bb.0: # %entry
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %eax
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %edx
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; NOX87-NEXT:retl
+entry:
+  ret x86_fp80 %b
+}
+
+define float @f4(float %a, float %b) nounwind {
+; X87-LABEL: f4:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:flds {{[0-9]+}}(%esp)
+; X87-NEXT:fadds {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f4:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:calll __addsf3
+; NOSSE-NOX87-NEXT:addl $8, %esp
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f4:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; SSE-NOX87-NEXT:addss {{[0-9]+}}(%esp), %xmm0
+; SSE-NOX87-NEXT:movd %xmm0, %eax
+; SSE-NOX87-NEXT:retl
+entry:
+  %0 = fadd float %a, %b
+  ret float %0
+}
+
+define double @f5(double %a, double %b) nounwind {
+; X87-LABEL: f5:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldl {{[0-9]+}}(%esp)
+; X87-NEXT:faddl {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f5:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:calll __adddf3
+; NOSSE-NOX87-NEXT:addl $16, %esp
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f5:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:pushl %ebp
+; SSE-NOX87-NEXT:movl %esp, %ebp
+; SSE-NOX87-NEXT:andl $-8, %esp
+; SSE-NOX87-NEXT:subl $8, %esp
+; SSE-NOX87-NEXT:movsd {{.*#+}} xmm0 = mem[0],zero
+; SSE-NOX87-NEXT:addsd 16(%ebp), %xmm0
+; SSE-NOX87-NEXT:movsd %xmm0, (%esp)
+; SSE-NOX87-NEXT:movl (%esp), %eax
+; SSE-NOX87-NEXT:movl {{[0-9]+}}(%esp), %edx
+; SSE-NOX87-NEXT:movl %ebp, %esp
+; SSE-NOX87-NEXT:popl %ebp
+; SSE-NOX87-NEXT:retl
+entry:
+  %0 = fadd double %a, %b
+  ret double %0
+}
+
+; FIXME: We should not generate x87 instructions when x87 is disabled.
+define x86_fp80 @f6(x86_fp80 %a, x86_fp80 %b) nounwind {
+; X87-LABEL: f6:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldt {{[0-9]+}}(%esp)
+; X87-NEXT:fldt {{[0-9]+}}(%esp)
+; X87-NEXT:faddp %st, %st(1)
+; X87-NEXT:retl
+;
+; NOX87-LABEL: f6:
+; NOX87:   # %bb.0: # %entry
+; NOX87-NEXT:pushl %ebp
+; NOX87-NEXT:movl %esp, %ebp
+; NOX87-NEXT:andl $-8, %esp
+; NOX87-NEXT:subl $48, %esp
+; NOX87-NEXT:movl 20(%ebp), %eax
+; NOX87-NEXT:

[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-11-17 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks for the review!




Comment at: llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll:147-150
+; NOX87-NEXT:fldt {{[0-9]+}}(%esp)
+; NOX87-NEXT:fldt {{[0-9]+}}(%esp)
+; NOX87-NEXT:faddp %st, %st(1)
+; NOX87-NEXT:fstpt (%esp)

nickdesaulniers wrote:
> :(
Will fix it as a follow up. D100091 aims to fix these problems.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-11-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added inline comments.



Comment at: llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll:147-150
+; NOX87-NEXT:fldt {{[0-9]+}}(%esp)
+; NOX87-NEXT:fldt {{[0-9]+}}(%esp)
+; NOX87-NEXT:faddp %st, %st(1)
+; NOX87-NEXT:fstpt (%esp)

:(


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-11-17 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: llvm/lib/Target/X86/X86CallingConv.td:279
+  CCIfNotSubtarget<"hasX87()",
+CCIfType<[f32], CCAssignToReg<[EAX, EDX, ECX]>>>,
   CCIfType<[f16], CCAssignToReg<[XMM0,XMM1,XMM2]>>,

nickdesaulniers wrote:
> Is there a test case that exercises the assignment to %ecx?
Add one test case for it, though I don't believe we can really generate it from 
frontend.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-11-17 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 387855.
pengfei added a comment.

1. Add support for f80.
2. Add test case for 3 return values.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

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/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll

Index: llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll
@@ -0,0 +1,193 @@
+; 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-prefixes=NOX87,NOSSE-NOX87
+; RUN: llc < %s -mtriple=i686-- -mattr=-x87,-sse2 | FileCheck %s -check-prefixes=NOX87,NOSSE-NOX87
+; RUN: llc < %s -mtriple=i686-- -mattr=-x87,+sse2 | FileCheck %s -check-prefixes=NOX87,SSE-NOX87
+
+define float @f1(float %a, float %b) nounwind {
+; X87-LABEL: f1:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:flds {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f1:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:movl {{[0-9]+}}(%esp), %eax
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f1:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:movd {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; SSE-NOX87-NEXT:movd %xmm0, %eax
+; SSE-NOX87-NEXT:retl
+entry:
+  ret float %b
+}
+
+define double @f2(double %a, double %b) nounwind {
+; X87-LABEL: f2:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldl {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOX87-LABEL: f2:
+; NOX87:   # %bb.0: # %entry
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %eax
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %edx
+; NOX87-NEXT:retl
+entry:
+  ret double %b
+}
+
+define x86_fp80 @f3(x86_fp80 %a, x86_fp80 %b) nounwind {
+; X87-LABEL: f3:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldt {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOX87-LABEL: f3:
+; NOX87:   # %bb.0: # %entry
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %eax
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %edx
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; NOX87-NEXT:retl
+entry:
+  ret x86_fp80 %b
+}
+
+define float @f4(float %a, float %b) nounwind {
+; X87-LABEL: f4:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:flds {{[0-9]+}}(%esp)
+; X87-NEXT:fadds {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f4:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:calll __addsf3
+; NOSSE-NOX87-NEXT:addl $8, %esp
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f4:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; SSE-NOX87-NEXT:addss {{[0-9]+}}(%esp), %xmm0
+; SSE-NOX87-NEXT:movd %xmm0, %eax
+; SSE-NOX87-NEXT:retl
+entry:
+  %0 = fadd float %a, %b
+  ret float %0
+}
+
+define double @f5(double %a, double %b) nounwind {
+; X87-LABEL: f5:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldl {{[0-9]+}}(%esp)
+; X87-NEXT:faddl {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f5:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:calll __adddf3
+; NOSSE-NOX87-NEXT:addl $16, %esp
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f5:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:pushl %ebp
+; SSE-NOX87-NEXT:movl %esp, %ebp
+; SSE-NOX87-NEXT:andl $-8, %esp
+; SSE-NOX87-NEXT:subl $8, %esp
+; SSE-NOX87-NEXT:movsd {{.*#+}} xmm0 = mem[0],zero
+; SSE-NOX87-NEXT:addsd 16(%ebp), %xmm0
+; SSE-NOX87-NEXT:movsd %xmm0, (%esp)
+; SSE-NOX87-NEXT:movl (%esp), %eax
+; SSE-NOX87-NEXT:movl {{[0-9]+}}(%esp), %edx
+; SSE-NOX87-NEXT:movl %ebp, %esp
+; SSE-NOX87-NEXT:popl %ebp
+; SSE-NOX87-NEXT:retl
+entry:
+  %0 = fadd double %a, %b
+  ret double %0
+}
+
+; FIXME: We should not generate x87 instructions when x87 is disabled.
+define x86_fp80 @f6(x86_fp80 %a, x86_fp80 %b) nounwind {
+; X87-LABEL: f6:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldt {{[0-9]+}}(%esp)
+; X87-NEXT:fldt {{[0-9]+}}(%esp)
+; X87-NEXT:faddp %st, %st(1)
+; X87-NEXT:retl
+;
+; NOX87-LABEL: f6:
+; NOX87:   # %bb.0: # %entry
+; NOX87-NEXT:pushl %ebp
+; NOX87-NEXT:movl %esp, %ebp
+; NOX87-NEXT:andl $-8, %esp
+; NOX87-NEXT:subl $48, %esp
+; NOX87-NEXT:movl 20(%ebp), %eax
+; NOX87-NEXT:movl 24(%ebp), %ecx
+; NOX87-NEXT:movl %ecx, {{[0-9]+}}(%esp)
+; 

[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-11-16 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

Just a comment on the ECX bit, otherwise this patch looks fine to me. Someone 
with more x86 knowledge may want to take a look though. Thanks for the patch!




Comment at: llvm/lib/Target/X86/X86CallingConv.td:279
+  CCIfNotSubtarget<"hasX87()",
+CCIfType<[f32], CCAssignToReg<[EAX, EDX, ECX]>>>,
   CCIfType<[f16], CCAssignToReg<[XMM0,XMM1,XMM2]>>,

Is there a test case that exercises the assignment to %ecx?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-11-15 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/Driver/x86-target-features.c:5
 // 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"

nickdesaulniers wrote:
> If you split this test and the above change to 
> clang/include/clang/Driver/Options.td into a separate patch on Phab, I'd be 
> happy to accept that!
> 
> Otherwise someone more familiar with x86 will have to take a look at the 
> below changes.
This is a simple alias. Spliting it doesn't solve the initial problem. I think 
it's better to commit it together with the backend change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-10-28 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/Driver/x86-target-features.c:5
 // 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"

If you split this test and the above change to 
clang/include/clang/Driver/Options.td into a separate patch on Phab, I'd be 
happy to accept that!

Otherwise someone more familiar with x86 will have to take a look at the below 
changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-10-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D112143#3089072 , @nickdesaulniers 
wrote:

> Fixes https://bugs.llvm.org/show_bug.cgi?id=51498?

sorry, I missed the PR # in the description; my mistake.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-10-26 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

In D112143#3089072 , @nickdesaulniers 
wrote:

> Fixes https://bugs.llvm.org/show_bug.cgi?id=51498?

Yes. I mentioned pr51498 in commit message :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-10-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Fixes https://bugs.llvm.org/show_bug.cgi?id=51498?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-10-21 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 381179.
pengfei added a comment.

Fix bugs. Ready for review now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

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/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll

Index: llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/no-ret-in-x87-reg.ll
@@ -0,0 +1,102 @@
+; 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-prefixes=NOX87,NOSSE-NOX87
+; RUN: llc < %s -mtriple=i686-- -mattr=-x87,-sse2 | FileCheck %s -check-prefixes=NOX87,NOSSE-NOX87
+; RUN: llc < %s -mtriple=i686-- -mattr=-x87,+sse2 | FileCheck %s -check-prefixes=NOX87,SSE-NOX87
+
+define float @f1(float %a, float %b) nounwind {
+; X87-LABEL: f1:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:flds {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f1:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:movl {{[0-9]+}}(%esp), %eax
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f1:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:movd {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; SSE-NOX87-NEXT:movd %xmm0, %eax
+; SSE-NOX87-NEXT:retl
+entry:
+  ret float %b
+}
+
+define double @f2(double %a, double %b) nounwind {
+; X87-LABEL: f2:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldl {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOX87-LABEL: f2:
+; NOX87:   # %bb.0: # %entry
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %eax
+; NOX87-NEXT:movl {{[0-9]+}}(%esp), %edx
+; NOX87-NEXT:retl
+entry:
+  ret double %b
+}
+
+define float @f3(float %a, float %b) nounwind {
+; X87-LABEL: f3:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:flds {{[0-9]+}}(%esp)
+; X87-NEXT:fadds {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f3:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:calll __addsf3
+; NOSSE-NOX87-NEXT:addl $8, %esp
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f3:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
+; SSE-NOX87-NEXT:addss {{[0-9]+}}(%esp), %xmm0
+; SSE-NOX87-NEXT:movd %xmm0, %eax
+; SSE-NOX87-NEXT:retl
+entry:
+  %0 = fadd float %a, %b
+  ret float %0
+}
+
+define double @f4(double %a, double %b) nounwind {
+; X87-LABEL: f4:
+; X87:   # %bb.0: # %entry
+; X87-NEXT:fldl {{[0-9]+}}(%esp)
+; X87-NEXT:faddl {{[0-9]+}}(%esp)
+; X87-NEXT:retl
+;
+; NOSSE-NOX87-LABEL: f4:
+; NOSSE-NOX87:   # %bb.0: # %entry
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:pushl {{[0-9]+}}(%esp)
+; NOSSE-NOX87-NEXT:calll __adddf3
+; NOSSE-NOX87-NEXT:addl $16, %esp
+; NOSSE-NOX87-NEXT:retl
+;
+; SSE-NOX87-LABEL: f4:
+; SSE-NOX87:   # %bb.0: # %entry
+; SSE-NOX87-NEXT:pushl %ebp
+; SSE-NOX87-NEXT:movl %esp, %ebp
+; SSE-NOX87-NEXT:andl $-8, %esp
+; SSE-NOX87-NEXT:subl $8, %esp
+; SSE-NOX87-NEXT:movsd {{.*#+}} xmm0 = mem[0],zero
+; SSE-NOX87-NEXT:addsd 16(%ebp), %xmm0
+; SSE-NOX87-NEXT:movsd %xmm0, (%esp)
+; SSE-NOX87-NEXT:movl (%esp), %eax
+; SSE-NOX87-NEXT:movl {{[0-9]+}}(%esp), %edx
+; SSE-NOX87-NEXT:movl %ebp, %esp
+; SSE-NOX87-NEXT:popl %ebp
+; SSE-NOX87-NEXT:retl
+entry:
+  %0 = fadd double %a, %b
+  ret double %0
+}
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -2367,6 +2367,10 @@
   if (VT == MVT::v3f16 && Subtarget.hasFP16())
 return MVT::v8f16;
 
+  // We will use 2 GPRs for f64 on 32 bits when x87 is disabled.
+  if (VT == MVT::f64 && !Subtarget.is64Bit() && !Subtarget.hasX87())
+return MVT::i32;
+
   return TargetLowering::getRegisterTypeForCallingConv(Context, CC, VT);
 }
 
@@ -2390,6 +2394,10 @@
   if (VT == MVT::v3f16 && Subtarget.hasFP16())
 return 1;
 
+  // We have to split f64 into 2 registers on 32 bits if x87 is disabled.
+  if (VT == MVT::f64 && !Subtarget.is64Bit() && !Subtarget.hasX87())
+return 2;
+
   return TargetLowering::getNumRegistersForCallingConv(Context, CC, VT);
 }
 
Index: llvm/lib/Target/X86/X86CallingConv.td
===
--- llvm/lib/Target/X86/X86CallingConv.td
+++ llvm/lib/Target/X86/X86CallingConv.td
@@ -273,7 

[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-10-20 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei planned changes to this revision.
pengfei added a comment.

Found a mistake, working on that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112143/new/

https://reviews.llvm.org/D112143

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112143: [X86][ABI] Do not return float/double from x87 registers when x87 is disabled

2021-10-20 Thread Pengfei Wang via Phabricator via cfe-commits
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>>>,
+  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
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;
 def m80387 : Flag<["-"], "m80387">, Alias;
 def mno_80387 : Flag<["-"], "mno-80387">, Alias;
+def mno_fp_ret_in_387 : Flag<["-"], "mno-fp-ret-in-387">, Alias;
 def mmmx : Flag<["-"], "mmmx">, Group;
 def mno_mmx : Flag<["-"], "mno-mmx">, Group;
 def m3dnow : Flag<["-"], "m3dnow">, Group;


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>>>,
+  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
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