1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -instcombine < %s | FileCheck %s
3
4define double @fdiv_sin_cos(double %a) {
5; CHECK-LABEL: @fdiv_sin_cos(
6; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.sin.f64(double [[A:%.*]])
7; CHECK-NEXT:    [[TMP2:%.*]] = call double @llvm.cos.f64(double [[A]])
8; CHECK-NEXT:    [[DIV:%.*]] = fdiv double [[TMP1]], [[TMP2]]
9; CHECK-NEXT:    ret double [[DIV]]
10;
11  %1 = call double @llvm.sin.f64(double %a)
12  %2 = call double @llvm.cos.f64(double %a)
13  %div = fdiv double %1, %2
14  ret double %div
15}
16
17define double @fdiv_strict_sin_strict_cos_reassoc(double %a) {
18; CHECK-LABEL: @fdiv_strict_sin_strict_cos_reassoc(
19; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.sin.f64(double [[A:%.*]])
20; CHECK-NEXT:    [[TMP2:%.*]] = call reassoc double @llvm.cos.f64(double [[A]])
21; CHECK-NEXT:    [[DIV:%.*]] = fdiv double [[TMP1]], [[TMP2]]
22; CHECK-NEXT:    ret double [[DIV]]
23;
24  %1 = call double @llvm.sin.f64(double %a)
25  %2 = call reassoc double @llvm.cos.f64(double %a)
26  %div = fdiv double %1, %2
27  ret double %div
28}
29
30define double @fdiv_reassoc_sin_strict_cos_strict(double %a, i32* dereferenceable(2) %dummy) {
31; CHECK-LABEL: @fdiv_reassoc_sin_strict_cos_strict(
32; CHECK-NEXT:    [[TAN:%.*]] = call reassoc double @tan(double [[A:%.*]]) #1
33; CHECK-NEXT:    ret double [[TAN]]
34;
35  %1 = call double @llvm.sin.f64(double %a)
36  %2 = call double @llvm.cos.f64(double %a)
37  %div = fdiv reassoc double %1, %2
38  ret double %div
39}
40
41define double @fdiv_reassoc_sin_reassoc_cos_strict(double %a) {
42; CHECK-LABEL: @fdiv_reassoc_sin_reassoc_cos_strict(
43; CHECK-NEXT:    [[TAN:%.*]] = call reassoc double @tan(double [[A:%.*]]) #1
44; CHECK-NEXT:    ret double [[TAN]]
45;
46  %1 = call reassoc double @llvm.sin.f64(double %a)
47  %2 = call double @llvm.cos.f64(double %a)
48  %div = fdiv reassoc double %1, %2
49  ret double %div
50}
51
52define double @fdiv_sin_cos_reassoc_multiple_uses(double %a) {
53; CHECK-LABEL: @fdiv_sin_cos_reassoc_multiple_uses(
54; CHECK-NEXT:    [[TMP1:%.*]] = call reassoc double @llvm.sin.f64(double [[A:%.*]])
55; CHECK-NEXT:    [[TMP2:%.*]] = call reassoc double @llvm.cos.f64(double [[A]])
56; CHECK-NEXT:    [[DIV:%.*]] = fdiv reassoc double [[TMP1]], [[TMP2]]
57; CHECK-NEXT:    call void @use(double [[TMP2]])
58; CHECK-NEXT:    ret double [[DIV]]
59;
60  %1 = call reassoc double @llvm.sin.f64(double %a)
61  %2 = call reassoc double @llvm.cos.f64(double %a)
62  %div = fdiv reassoc double %1, %2
63  call void @use(double %2)
64  ret double %div
65}
66
67define double @fdiv_sin_cos_reassoc(double %a) {
68; CHECK-LABEL: @fdiv_sin_cos_reassoc(
69; CHECK-NEXT:    [[TAN:%.*]] = call reassoc double @tan(double [[A:%.*]]) #1
70; CHECK-NEXT:    ret double [[TAN]]
71;
72  %1 = call reassoc double @llvm.sin.f64(double %a)
73  %2 = call reassoc double @llvm.cos.f64(double %a)
74  %div = fdiv reassoc double %1, %2
75  ret double %div
76}
77
78define float @fdiv_sinf_cosf_reassoc(float %a) {
79; CHECK-LABEL: @fdiv_sinf_cosf_reassoc(
80; CHECK-NEXT:    [[TANF:%.*]] = call reassoc float @tanf(float [[A:%.*]]) #1
81; CHECK-NEXT:    ret float [[TANF]]
82;
83  %1 = call reassoc float @llvm.sin.f32(float %a)
84  %2 = call reassoc float @llvm.cos.f32(float %a)
85  %div = fdiv reassoc float %1, %2
86  ret float %div
87}
88
89define fp128 @fdiv_sinfp128_cosfp128_reassoc(fp128 %a) {
90; CHECK-LABEL: @fdiv_sinfp128_cosfp128_reassoc(
91; CHECK-NEXT:    [[TANL:%.*]] = call reassoc fp128 @tanl(fp128 [[A:%.*]]) #1
92; CHECK-NEXT:    ret fp128 [[TANL]]
93;
94  %1 = call reassoc fp128 @llvm.sin.fp128(fp128 %a)
95  %2 = call reassoc fp128 @llvm.cos.fp128(fp128 %a)
96  %div = fdiv reassoc fp128 %1, %2
97  ret fp128 %div
98}
99
100declare double @llvm.sin.f64(double) #1
101declare float @llvm.sin.f32(float) #1
102declare fp128 @llvm.sin.fp128(fp128) #1
103
104declare double @llvm.cos.f64(double) #1
105declare float @llvm.cos.f32(float) #1
106declare fp128 @llvm.cos.fp128(fp128) #1
107
108declare void @use(double)
109
110attributes #0 = { nounwind readnone speculatable }
111attributes #1 = { nounwind readnone }
112