1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 declare double @llvm.cos.f64(double %Val)
5 declare float @llvm.cos.f32(float %Val)
6 declare <2 x float> @llvm.cos.v2f32(<2 x float> %Val)
8 declare float @llvm.fabs.f32(float %Val)
9 declare <2 x float> @llvm.fabs.v2f32(<2 x float> %Val)
11 define double @undef_arg() {
12 ; CHECK-LABEL: @undef_arg(
13 ; CHECK-NEXT: ret double 0.000000e+00
15 %r = call double @llvm.cos.f64(double undef)
19 define float @undef_arg2(float %d) {
20 ; CHECK-LABEL: @undef_arg2(
21 ; CHECK-NEXT: [[COSVAL:%.*]] = call float @llvm.cos.f32(float [[D:%.*]])
22 ; CHECK-NEXT: [[FSUM:%.*]] = fadd float [[COSVAL]], 0.000000e+00
23 ; CHECK-NEXT: ret float [[FSUM]]
25 %cosval = call float @llvm.cos.f32(float %d)
26 %cosval2 = call float @llvm.cos.f32(float undef)
27 %fsum = fadd float %cosval2, %cosval
31 define float @fneg_f32(float %x) {
32 ; CHECK-LABEL: @fneg_f32(
33 ; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X:%.*]])
34 ; CHECK-NEXT: ret float [[COS]]
36 %x.fneg = fsub float -0.0, %x
37 %cos = call float @llvm.cos.f32(float %x.fneg)
41 define float @unary_fneg_f32(float %x) {
42 ; CHECK-LABEL: @unary_fneg_f32(
43 ; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X:%.*]])
44 ; CHECK-NEXT: ret float [[COS]]
46 %x.fneg = fneg float %x
47 %cos = call float @llvm.cos.f32(float %x.fneg)
51 define <2 x float> @fneg_v2f32(<2 x float> %x) {
52 ; CHECK-LABEL: @fneg_v2f32(
53 ; CHECK-NEXT: [[COS:%.*]] = call <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
54 ; CHECK-NEXT: ret <2 x float> [[COS]]
56 %x.fneg = fsub <2 x float> <float -0.0, float -0.0>, %x
57 %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fneg)
61 define <2 x float> @unary_fneg_v2f32(<2 x float> %x) {
62 ; CHECK-LABEL: @unary_fneg_v2f32(
63 ; CHECK-NEXT: [[COS:%.*]] = call <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
64 ; CHECK-NEXT: ret <2 x float> [[COS]]
66 %x.fneg = fneg <2 x float> %x
67 %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fneg)
71 ; FMF are not required, but they should propagate.
73 define <2 x float> @fneg_cos_fmf(<2 x float> %x){
74 ; CHECK-LABEL: @fneg_cos_fmf(
75 ; CHECK-NEXT: [[R:%.*]] = call nnan afn <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
76 ; CHECK-NEXT: ret <2 x float> [[R]]
78 %negx = fsub fast <2 x float> <float -0.0, float -0.0>, %x
79 %r = call nnan afn <2 x float> @llvm.cos.v2f32(<2 x float> %negx)
83 define <2 x float> @unary_fneg_cos_fmf(<2 x float> %x){
84 ; CHECK-LABEL: @unary_fneg_cos_fmf(
85 ; CHECK-NEXT: [[R:%.*]] = call nnan afn <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
86 ; CHECK-NEXT: ret <2 x float> [[R]]
88 %negx = fneg fast <2 x float> %x
89 %r = call nnan afn <2 x float> @llvm.cos.v2f32(<2 x float> %negx)
93 define float @fabs_f32(float %x) {
94 ; CHECK-LABEL: @fabs_f32(
95 ; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X:%.*]])
96 ; CHECK-NEXT: ret float [[COS]]
98 %x.fabs = call float @llvm.fabs.f32(float %x)
99 %cos = call float @llvm.cos.f32(float %x.fabs)
103 define float @fabs_fneg_f32(float %x) {
104 ; CHECK-LABEL: @fabs_fneg_f32(
105 ; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X:%.*]])
106 ; CHECK-NEXT: ret float [[COS]]
108 %x.fabs = call float @llvm.fabs.f32(float %x)
109 %x.fabs.fneg = fsub float -0.0, %x.fabs
110 %cos = call float @llvm.cos.f32(float %x.fabs.fneg)
114 define float @fabs_unary_fneg_f32(float %x) {
115 ; CHECK-LABEL: @fabs_unary_fneg_f32(
116 ; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X:%.*]])
117 ; CHECK-NEXT: ret float [[COS]]
119 %x.fabs = call float @llvm.fabs.f32(float %x)
120 %x.fabs.fneg = fneg float %x.fabs
121 %cos = call float @llvm.cos.f32(float %x.fabs.fneg)
125 define <2 x float> @fabs_fneg_v2f32(<2 x float> %x) {
126 ; CHECK-LABEL: @fabs_fneg_v2f32(
127 ; CHECK-NEXT: [[COS:%.*]] = call <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
128 ; CHECK-NEXT: ret <2 x float> [[COS]]
130 %x.fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
131 %x.fabs.fneg = fsub <2 x float> <float -0.0, float -0.0>, %x.fabs
132 %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fabs.fneg)
136 define <2 x float> @fabs_unary_fneg_v2f32(<2 x float> %x) {
137 ; CHECK-LABEL: @fabs_unary_fneg_v2f32(
138 ; CHECK-NEXT: [[COS:%.*]] = call <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
139 ; CHECK-NEXT: ret <2 x float> [[COS]]
141 %x.fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
142 %x.fabs.fneg = fneg <2 x float> %x.fabs
143 %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fabs.fneg)
147 ; Negate is canonicalized after sin.
149 declare <2 x float> @llvm.sin.v2f32(<2 x float>)
151 define <2 x float> @fneg_sin(<2 x float> %x){
152 ; CHECK-LABEL: @fneg_sin(
153 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
154 ; CHECK-NEXT: [[R:%.*]] = fneg <2 x float> [[TMP1]]
155 ; CHECK-NEXT: ret <2 x float> [[R]]
157 %negx = fsub <2 x float> <float -0.0, float -0.0>, %x
158 %r = call <2 x float> @llvm.sin.v2f32(<2 x float> %negx)
162 define <2 x float> @unary_fneg_sin(<2 x float> %x){
163 ; CHECK-LABEL: @unary_fneg_sin(
164 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
165 ; CHECK-NEXT: [[R:%.*]] = fneg <2 x float> [[TMP1]]
166 ; CHECK-NEXT: ret <2 x float> [[R]]
168 %negx = fneg <2 x float> %x
169 %r = call <2 x float> @llvm.sin.v2f32(<2 x float> %negx)
173 ; FMF are not required, but they should propagate.
175 define <2 x float> @fneg_sin_fmf(<2 x float> %x){
176 ; CHECK-LABEL: @fneg_sin_fmf(
177 ; CHECK-NEXT: [[TMP1:%.*]] = call nnan arcp afn <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
178 ; CHECK-NEXT: [[R:%.*]] = fneg nnan arcp afn <2 x float> [[TMP1]]
179 ; CHECK-NEXT: ret <2 x float> [[R]]
181 %negx = fsub fast <2 x float> <float -0.0, float -0.0>, %x
182 %r = call nnan arcp afn <2 x float> @llvm.sin.v2f32(<2 x float> %negx)
186 define <2 x float> @unary_fneg_sin_fmf(<2 x float> %x){
187 ; CHECK-LABEL: @unary_fneg_sin_fmf(
188 ; CHECK-NEXT: [[TMP1:%.*]] = call nnan arcp afn <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
189 ; CHECK-NEXT: [[R:%.*]] = fneg nnan arcp afn <2 x float> [[TMP1]]
190 ; CHECK-NEXT: ret <2 x float> [[R]]
192 %negx = fneg fast <2 x float> %x
193 %r = call nnan arcp afn <2 x float> @llvm.sin.v2f32(<2 x float> %negx)