1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx | FileCheck %s
3
4declare double @sin(double %f)
5
6; When the subs are strict, they can't be removed because of signed zero.
7
8define double @strict(double %e) nounwind {
9; CHECK-LABEL: strict:
10; CHECK:       # BB#0:
11; CHECK-NEXT:    pushq %rax
12; CHECK-NEXT:    vxorpd %xmm1, %xmm1, %xmm1
13; CHECK-NEXT:    vsubsd %xmm0, %xmm1, %xmm0
14; CHECK-NEXT:    callq sin
15; CHECK-NEXT:    vxorpd %xmm1, %xmm1, %xmm1
16; CHECK-NEXT:    vsubsd %xmm0, %xmm1, %xmm0
17; CHECK-NEXT:    popq %rax
18; CHECK-NEXT:    retq
19;
20  %f = fsub double 0.0, %e
21  %g = call double @sin(double %f) readonly
22  %h = fsub double 0.0, %g
23  ret double %h
24}
25
26; 'fast' implies no-signed-zeros, so the negates fold away.
27; The 'sin' does not need any fast-math-flags for this transform.
28
29define double @fast(double %e) nounwind {
30; CHECK-LABEL: fast:
31; CHECK:       # BB#0:
32; CHECK-NEXT:    jmp sin
33;
34  %f = fsub fast double 0.0, %e
35  %g = call double @sin(double %f) readonly
36  %h = fsub fast double 0.0, %g
37  ret double %h
38}
39
40; No-signed-zeros is all that we need for this transform.
41
42define double @nsz(double %e) nounwind {
43; CHECK-LABEL: nsz:
44; CHECK:       # BB#0:
45; CHECK-NEXT:    jmp sin
46;
47  %f = fsub nsz double 0.0, %e
48  %g = call double @sin(double %f) readonly
49  %h = fsub nsz double 0.0, %g
50  ret double %h
51}
52
53; The 1st negate is strict, so we can't kill that sub, but the 2nd disappears.
54
55define double @semi_strict1(double %e) nounwind {
56; CHECK-LABEL: semi_strict1:
57; CHECK:       # BB#0:
58; CHECK-NEXT:    pushq %rax
59; CHECK-NEXT:    vxorpd %xmm1, %xmm1, %xmm1
60; CHECK-NEXT:    vsubsd %xmm0, %xmm1, %xmm0
61; CHECK-NEXT:    callq sin
62; CHECK-NEXT:    vxorpd {{.*}}(%rip), %xmm0, %xmm0
63; CHECK-NEXT:    popq %rax
64; CHECK-NEXT:    retq
65;
66  %f = fsub double 0.0, %e
67  %g = call double @sin(double %f) readonly
68  %h = fsub nsz double 0.0, %g
69  ret double %h
70}
71
72; The 2nd negate is strict, so we can't kill it. It becomes an add of zero instead.
73
74define double @semi_strict2(double %e) nounwind {
75; CHECK-LABEL: semi_strict2:
76; CHECK:       # BB#0:
77; CHECK-NEXT:    pushq %rax
78; CHECK-NEXT:    callq sin
79; CHECK-NEXT:    vxorpd %xmm1, %xmm1, %xmm1
80; CHECK-NEXT:    vaddsd %xmm1, %xmm0, %xmm0
81; CHECK-NEXT:    popq %rax
82; CHECK-NEXT:    retq
83;
84  %f = fsub nsz double 0.0, %e
85  %g = call double @sin(double %f) readonly
86  %h = fsub double 0.0, %g
87  ret double %h
88}
89
90; FIXME:
91; Auto-upgrade function attribute to IR-level fast-math-flags.
92
93define double @fn_attr(double %e) nounwind #0 {
94; CHECK-LABEL: fn_attr:
95; CHECK:       # BB#0:
96; CHECK-NEXT:    jmp sin
97;
98  %f = fsub double 0.0, %e
99  %g = call double @sin(double %f) readonly
100  %h = fsub double 0.0, %g
101  ret double %h
102}
103
104attributes #0 = { "unsafe-fp-math"="true" }
105
106