[llvm] r310762 - [X86] Don't use fsin/fcos/fsincos instructions ever
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 11 13:55:29 PDT 2017
Author: ctopper
Date: Fri Aug 11 13:55:29 2017
New Revision: 310762
URL: http://llvm.org/viewvc/llvm-project?rev=310762&view=rev
Log:
[X86] Don't use fsin/fcos/fsincos instructions ever
Summary:
Previously we would use these instructions if sse was disabled and fastmath was enabled.
As mentioned in D28335, this is a bad idea.
Reviewers: efriedma, scanon, DavidKreitzer
Reviewed By: DavidKreitzer
Subscribers: zvi, llvm-commits
Differential Revision: https://reviews.llvm.org/D36344
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/test/CodeGen/X86/sincos-opt.ll
llvm/trunk/test/CodeGen/X86/sincos.ll
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=310762&r1=310761&r2=310762&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Aug 11 13:55:29 2017
@@ -573,11 +573,10 @@ X86TargetLowering::X86TargetLowering(con
addLegalFPImmediate(APFloat(-0.0)); // FLD0/FCHS
addLegalFPImmediate(APFloat(-1.0)); // FLD1/FCHS
- if (!TM.Options.UnsafeFPMath) {
- setOperationAction(ISD::FSIN , MVT::f64, Expand);
- setOperationAction(ISD::FCOS , MVT::f64, Expand);
- setOperationAction(ISD::FSINCOS, MVT::f64, Expand);
- }
+ // Always expand sin/cos functions even though x87 has an instruction.
+ setOperationAction(ISD::FSIN , MVT::f64, Expand);
+ setOperationAction(ISD::FCOS , MVT::f64, Expand);
+ setOperationAction(ISD::FSINCOS, MVT::f64, Expand);
} else if (UseX87) {
// f32 and f64 in x87.
// Set up the FP register classes.
@@ -588,11 +587,10 @@ X86TargetLowering::X86TargetLowering(con
setOperationAction(ISD::UNDEF, VT, Expand);
setOperationAction(ISD::FCOPYSIGN, VT, Expand);
- if (!TM.Options.UnsafeFPMath) {
- setOperationAction(ISD::FSIN , VT, Expand);
- setOperationAction(ISD::FCOS , VT, Expand);
- setOperationAction(ISD::FSINCOS, VT, Expand);
- }
+ // Always expand sin/cos functions even though x87 has an instruction.
+ setOperationAction(ISD::FSIN , VT, Expand);
+ setOperationAction(ISD::FCOS , VT, Expand);
+ setOperationAction(ISD::FSINCOS, VT, Expand);
}
addLegalFPImmediate(APFloat(+0.0)); // FLD0
addLegalFPImmediate(APFloat(+1.0)); // FLD1
@@ -636,11 +634,10 @@ X86TargetLowering::X86TargetLowering(con
addLegalFPImmediate(TmpFlt2); // FLD1/FCHS
}
- if (!TM.Options.UnsafeFPMath) {
- setOperationAction(ISD::FSIN , MVT::f80, Expand);
- setOperationAction(ISD::FCOS , MVT::f80, Expand);
- setOperationAction(ISD::FSINCOS, MVT::f80, Expand);
- }
+ // Always expand sin/cos functions even though x87 has an instruction.
+ setOperationAction(ISD::FSIN , MVT::f80, Expand);
+ setOperationAction(ISD::FCOS , MVT::f80, Expand);
+ setOperationAction(ISD::FSINCOS, MVT::f80, Expand);
setOperationAction(ISD::FFLOOR, MVT::f80, Expand);
setOperationAction(ISD::FCEIL, MVT::f80, Expand);
Modified: llvm/trunk/test/CodeGen/X86/sincos-opt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/sincos-opt.ll?rev=310762&r1=310761&r2=310762&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/sincos-opt.ll (original)
+++ llvm/trunk/test/CodeGen/X86/sincos-opt.ll Fri Aug 11 13:55:29 2017
@@ -118,10 +118,10 @@ entry:
; GNU_SINCOS: faddp %st(1)
; GNU_SINCOS_FASTMATH-LABEL: test3:
-; GNU_SINCOS_FASTMATH: fsin
-; GNU_SINCOS_FASTMATH: fcos
+; GNU_SINCOS_FASTMATH: callq sincosl
+; GNU_SINCOS_FASTMATH: fldt 16(%{{[re]}}sp)
+; GNU_SINCOS_FASTMATH: fldt 32(%{{[re]}}sp)
; GNU_SINCOS_FASTMATH: faddp %st(1)
-; GNU_SINCOS_FASTMATH: ret
%call = tail call x86_fp80 @sinl(x86_fp80 %x) readnone
%call1 = tail call x86_fp80 @cosl(x86_fp80 %x) readnone
%add = fadd x86_fp80 %call, %call1
Modified: llvm/trunk/test/CodeGen/X86/sincos.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/sincos.ll?rev=310762&r1=310761&r2=310762&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/sincos.ll (original)
+++ llvm/trunk/test/CodeGen/X86/sincos.ll Fri Aug 11 13:55:29 2017
@@ -10,64 +10,46 @@ declare double @sin(double) readonly
declare x86_fp80 @sinl(x86_fp80) readonly
define float @test1(float %X) {
-; UNSAFE-LABEL: test1:
-; UNSAFE: ## BB#0:
-; UNSAFE-NEXT: flds {{[0-9]+}}(%esp)
-; UNSAFE-NEXT: fsin
-; UNSAFE-NEXT: retl
-;
-; SAFE-LABEL: test1:
-; SAFE: ## BB#0:
-; SAFE-NEXT: subl $12, %esp
-; SAFE-NEXT: Lcfi0:
-; SAFE-NEXT: .cfi_def_cfa_offset 16
-; SAFE-NEXT: flds {{[0-9]+}}(%esp)
-; SAFE-NEXT: fstps (%esp)
-; SAFE-NEXT: calll _sinf
-; SAFE-NEXT: addl $12, %esp
-; SAFE-NEXT: retl
+; CHECK-LABEL: test1:
+; CHECK: ## BB#0:
+; CHECK-NEXT: subl $12, %esp
+; CHECK-NEXT: Lcfi0:
+; CHECK-NEXT: .cfi_def_cfa_offset 16
+; CHECK-NEXT: flds {{[0-9]+}}(%esp)
+; CHECK-NEXT: fstps (%esp)
+; CHECK-NEXT: calll _sinf
+; CHECK-NEXT: addl $12, %esp
+; CHECK-NEXT: retl
%Y = call float @sinf(float %X) readonly
ret float %Y
}
define double @test2(double %X) {
-; UNSAFE-LABEL: test2:
-; UNSAFE: ## BB#0:
-; UNSAFE-NEXT: fldl {{[0-9]+}}(%esp)
-; UNSAFE-NEXT: fsin
-; UNSAFE-NEXT: retl
-;
-; SAFE-LABEL: test2:
-; SAFE: ## BB#0:
-; SAFE-NEXT: subl $12, %esp
-; SAFE-NEXT: Lcfi1:
-; SAFE-NEXT: .cfi_def_cfa_offset 16
-; SAFE-NEXT: fldl {{[0-9]+}}(%esp)
-; SAFE-NEXT: fstpl (%esp)
-; SAFE-NEXT: calll _sin
-; SAFE-NEXT: addl $12, %esp
-; SAFE-NEXT: retl
+; CHECK-LABEL: test2:
+; CHECK: ## BB#0:
+; CHECK-NEXT: subl $12, %esp
+; CHECK-NEXT: Lcfi1:
+; CHECK-NEXT: .cfi_def_cfa_offset 16
+; CHECK-NEXT: fldl {{[0-9]+}}(%esp)
+; CHECK-NEXT: fstpl (%esp)
+; CHECK-NEXT: calll _sin
+; CHECK-NEXT: addl $12, %esp
+; CHECK-NEXT: retl
%Y = call double @sin(double %X) readonly
ret double %Y
}
define x86_fp80 @test3(x86_fp80 %X) {
-; UNSAFE-LABEL: test3:
-; UNSAFE: ## BB#0:
-; UNSAFE-NEXT: fldt {{[0-9]+}}(%esp)
-; UNSAFE-NEXT: fsin
-; UNSAFE-NEXT: retl
-;
-; SAFE-LABEL: test3:
-; SAFE: ## BB#0:
-; SAFE-NEXT: subl $28, %esp
-; SAFE-NEXT: Lcfi2:
-; SAFE-NEXT: .cfi_def_cfa_offset 32
-; SAFE-NEXT: fldt {{[0-9]+}}(%esp)
-; SAFE-NEXT: fstpt (%esp)
-; SAFE-NEXT: calll _sinl
-; SAFE-NEXT: addl $28, %esp
-; SAFE-NEXT: retl
+; CHECK-LABEL: test3:
+; CHECK: ## BB#0:
+; CHECK-NEXT: subl $28, %esp
+; CHECK-NEXT: Lcfi2:
+; CHECK-NEXT: .cfi_def_cfa_offset 32
+; CHECK-NEXT: fldt {{[0-9]+}}(%esp)
+; CHECK-NEXT: fstpt (%esp)
+; CHECK-NEXT: calll _sinl
+; CHECK-NEXT: addl $28, %esp
+; CHECK-NEXT: retl
%Y = call x86_fp80 @sinl(x86_fp80 %X) readonly
ret x86_fp80 %Y
}
@@ -80,64 +62,46 @@ declare x86_fp80 @cosl(x86_fp80) readonl
define float @test4(float %X) {
-; UNSAFE-LABEL: test4:
-; UNSAFE: ## BB#0:
-; UNSAFE-NEXT: flds {{[0-9]+}}(%esp)
-; UNSAFE-NEXT: fcos
-; UNSAFE-NEXT: retl
-;
-; SAFE-LABEL: test4:
-; SAFE: ## BB#0:
-; SAFE-NEXT: subl $12, %esp
-; SAFE-NEXT: Lcfi3:
-; SAFE-NEXT: .cfi_def_cfa_offset 16
-; SAFE-NEXT: flds {{[0-9]+}}(%esp)
-; SAFE-NEXT: fstps (%esp)
-; SAFE-NEXT: calll _cosf
-; SAFE-NEXT: addl $12, %esp
-; SAFE-NEXT: retl
+; CHECK-LABEL: test4:
+; CHECK: ## BB#0:
+; CHECK-NEXT: subl $12, %esp
+; CHECK-NEXT: Lcfi3:
+; CHECK-NEXT: .cfi_def_cfa_offset 16
+; CHECK-NEXT: flds {{[0-9]+}}(%esp)
+; CHECK-NEXT: fstps (%esp)
+; CHECK-NEXT: calll _cosf
+; CHECK-NEXT: addl $12, %esp
+; CHECK-NEXT: retl
%Y = call float @cosf(float %X) readonly
ret float %Y
}
define double @test5(double %X) {
-; UNSAFE-LABEL: test5:
-; UNSAFE: ## BB#0:
-; UNSAFE-NEXT: fldl {{[0-9]+}}(%esp)
-; UNSAFE-NEXT: fcos
-; UNSAFE-NEXT: retl
-;
-; SAFE-LABEL: test5:
-; SAFE: ## BB#0:
-; SAFE-NEXT: subl $12, %esp
-; SAFE-NEXT: Lcfi4:
-; SAFE-NEXT: .cfi_def_cfa_offset 16
-; SAFE-NEXT: fldl {{[0-9]+}}(%esp)
-; SAFE-NEXT: fstpl (%esp)
-; SAFE-NEXT: calll _cos
-; SAFE-NEXT: addl $12, %esp
-; SAFE-NEXT: retl
+; CHECK-LABEL: test5:
+; CHECK: ## BB#0:
+; CHECK-NEXT: subl $12, %esp
+; CHECK-NEXT: Lcfi4:
+; CHECK-NEXT: .cfi_def_cfa_offset 16
+; CHECK-NEXT: fldl {{[0-9]+}}(%esp)
+; CHECK-NEXT: fstpl (%esp)
+; CHECK-NEXT: calll _cos
+; CHECK-NEXT: addl $12, %esp
+; CHECK-NEXT: retl
%Y = call double @cos(double %X) readonly
ret double %Y
}
define x86_fp80 @test6(x86_fp80 %X) {
-; UNSAFE-LABEL: test6:
-; UNSAFE: ## BB#0:
-; UNSAFE-NEXT: fldt {{[0-9]+}}(%esp)
-; UNSAFE-NEXT: fcos
-; UNSAFE-NEXT: retl
-;
-; SAFE-LABEL: test6:
-; SAFE: ## BB#0:
-; SAFE-NEXT: subl $28, %esp
-; SAFE-NEXT: Lcfi5:
-; SAFE-NEXT: .cfi_def_cfa_offset 32
-; SAFE-NEXT: fldt {{[0-9]+}}(%esp)
-; SAFE-NEXT: fstpt (%esp)
-; SAFE-NEXT: calll _cosl
-; SAFE-NEXT: addl $28, %esp
-; SAFE-NEXT: retl
+; CHECK-LABEL: test6:
+; CHECK: ## BB#0:
+; CHECK-NEXT: subl $28, %esp
+; CHECK-NEXT: Lcfi5:
+; CHECK-NEXT: .cfi_def_cfa_offset 32
+; CHECK-NEXT: fldt {{[0-9]+}}(%esp)
+; CHECK-NEXT: fstpt (%esp)
+; CHECK-NEXT: calll _cosl
+; CHECK-NEXT: addl $28, %esp
+; CHECK-NEXT: retl
%Y = call x86_fp80 @cosl(x86_fp80 %X) readonly
ret x86_fp80 %Y
}
More information about the llvm-commits
mailing list