1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2 ; This test makes sure that the undef is propagated for the cos instrinsic
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 ; Function Attrs: nounwind readnone
12 define double @test1() {
13 ; CHECK-LABEL: define double @test1(
14 ; CHECK-NEXT: ret double 0.000000e+00
15 %1 = call double @llvm.cos.f64(double undef)
20 ; Function Attrs: nounwind readnone
21 define float @test2(float %d) {
22 ; CHECK-LABEL: define float @test2(
23 ; CHECK-NEXT: %cosval = call float @llvm.cos.f32(float %d)
24 %cosval = call float @llvm.cos.f32(float %d)
25 %cosval2 = call float @llvm.cos.f32(float undef)
26 %fsum = fadd float %cosval2, %cosval
29 ; CHECK: ret float %fsum
32 ; CHECK-LABEL: @cos_fneg_f32(
33 ; CHECK: %cos = call float @llvm.cos.f32(float %x)
34 ; CHECK-NEXT: ret float %cos
35 define float @cos_fneg_f32(float %x) {
36 %x.fneg = fsub float -0.0, %x
37 %cos = call float @llvm.cos.f32(float %x.fneg)
41 ; FIXME: m_FNeg() doesn't handle vectors
42 ; CHECK-LABEL: @cos_fneg_v2f32(
43 ; CHECK: %x.fneg = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, %x
44 ; CHECK-NEXT: %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fneg)
45 ; CHECK-NEXT: ret <2 x float> %cos
46 define <2 x float> @cos_fneg_v2f32(<2 x float> %x) {
47 %x.fneg = fsub <2 x float> <float -0.0, float -0.0>, %x
48 %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fneg)
52 ; CHECK-LABEL: @cos_fabs_f32(
53 ; CHECK-NEXT: %cos = call float @llvm.cos.f32(float %x)
54 ; CHECK-NEXT: ret float %cos
55 define float @cos_fabs_f32(float %x) {
56 %x.fabs = call float @llvm.fabs.f32(float %x)
57 %cos = call float @llvm.cos.f32(float %x.fabs)
61 ; CHECK-LABEL: @cos_fabs_fneg_f32(
62 ; CHECK: %cos = call float @llvm.cos.f32(float %x)
63 ; CHECK-NEXT: ret float %cos
64 define float @cos_fabs_fneg_f32(float %x) {
65 %x.fabs = call float @llvm.fabs.f32(float %x)
66 %x.fabs.fneg = fsub float -0.0, %x.fabs
67 %cos = call float @llvm.cos.f32(float %x.fabs.fneg)
71 ; CHECK-LABEL: @cos_fabs_fneg_v2f32(
72 ; CHECK: %x.fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
73 ; CHECK-NEXT: %x.fabs.fneg = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, %x.fabs
74 ; CHECK-NEXT: %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fabs.fneg)
75 ; CHECK-NEXT: ret <2 x float> %cos
76 define <2 x float> @cos_fabs_fneg_v2f32(<2 x float> %x) {
77 %x.fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
78 %x.fabs.fneg = fsub <2 x float> <float -0.0, float -0.0>, %x.fabs
79 %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fabs.fneg)