1 ; RUN: opt -instcombine -S < %s -mtriple=x86_64-apple-macosx10.9 | FileCheck %s --check-prefix=CHECK-FLOAT-IN-VEC 2 ; RUN: opt -instcombine -S < %s -mtriple=arm-apple-ios7.0 | FileCheck %s 3 ; RUN: opt -instcombine -S < %s -mtriple=arm64-apple-ios7.0 | FileCheck %s 4 ; RUN: opt -instcombine -S < %s -mtriple=x86_64-apple-macosx10.8 | FileCheck %s --check-prefix=CHECK-NO-SINCOS 5 ; RUN: opt -instcombine -S < %s -mtriple=arm-apple-ios6.0 | FileCheck %s --check-prefix=CHECK-NO-SINCOS 6 ; RUN: opt -instcombine -S < %s -mtriple=x86_64-none-linux-gnu | FileCheck %s --check-prefix=CHECK-NO-SINCOS 7 8 9 attributes #0 = { readnone nounwind } 10 11 declare float @__sinpif(float %x) #0 12 declare float @__cospif(float %x) #0 13 14 declare double @__sinpi(double %x) #0 15 declare double @__cospi(double %x) #0 16 17 @var32 = global float 0.0 18 @var64 = global double 0.0 19 20 define float @test_instbased_f32() { 21 %val = load float, float* @var32 22 %sin = call float @__sinpif(float %val) #0 23 %cos = call float @__cospif(float %val) #0 24 %res = fadd float %sin, %cos 25 ret float %res 26 ; CHECK-FLOAT-IN-VEC: [[VAL:%[a-z0-9]+]] = load float, float* @var32 27 ; CHECK-FLOAT-IN-VEC: [[SINCOS:%[a-z0-9]+]] = call <2 x float> @__sincospif_stret(float [[VAL]]) 28 ; CHECK-FLOAT-IN-VEC: extractelement <2 x float> [[SINCOS]], i32 0 29 ; CHECK-FLOAT-IN-VEC: extractelement <2 x float> [[SINCOS]], i32 1 30 31 ; CHECK: [[VAL:%[a-z0-9]+]] = load float, float* @var32 32 ; CHECK: [[SINCOS:%[a-z0-9]+]] = call { float, float } @__sincospif_stret(float [[VAL]]) 33 ; CHECK: extractvalue { float, float } [[SINCOS]], 0 34 ; CHECK: extractvalue { float, float } [[SINCOS]], 1 35 36 ; CHECK-NO-SINCOS: call float @__sinpif 37 ; CHECK-NO-SINCOS: call float @__cospif 38 } 39 40 define float @test_constant_f32() { 41 %sin = call float @__sinpif(float 1.0) #0 42 %cos = call float @__cospif(float 1.0) #0 43 %res = fadd float %sin, %cos 44 ret float %res 45 ; CHECK-FLOAT-IN-VEC: [[SINCOS:%[a-z0-9]+]] = call <2 x float> @__sincospif_stret(float 1.000000e+00) 46 ; CHECK-FLOAT-IN-VEC: extractelement <2 x float> [[SINCOS]], i32 0 47 ; CHECK-FLOAT-IN-VEC: extractelement <2 x float> [[SINCOS]], i32 1 48 49 ; CHECK: [[SINCOS:%[a-z0-9]+]] = call { float, float } @__sincospif_stret(float 1.000000e+00) 50 ; CHECK: extractvalue { float, float } [[SINCOS]], 0 51 ; CHECK: extractvalue { float, float } [[SINCOS]], 1 52 53 ; CHECK-NO-SINCOS: call float @__sinpif 54 ; CHECK-NO-SINCOS: call float @__cospif 55 } 56 57 define double @test_instbased_f64() { 58 %val = load double, double* @var64 59 %sin = call double @__sinpi(double %val) #0 60 %cos = call double @__cospi(double %val) #0 61 %res = fadd double %sin, %cos 62 ret double %res 63 ; CHECK-FLOAT-IN-VEC: [[VAL:%[a-z0-9]+]] = load double, double* @var64 64 ; CHECK-FLOAT-IN-VEC: [[SINCOS:%[a-z0-9]+]] = call { double, double } @__sincospi_stret(double [[VAL]]) 65 ; CHECK-FLOAT-IN-VEC: extractvalue { double, double } [[SINCOS]], 0 66 ; CHECK-FLOAT-IN-VEC: extractvalue { double, double } [[SINCOS]], 1 67 68 ; CHECK: [[VAL:%[a-z0-9]+]] = load double, double* @var64 69 ; CHECK: [[SINCOS:%[a-z0-9]+]] = call { double, double } @__sincospi_stret(double [[VAL]]) 70 ; CHECK: extractvalue { double, double } [[SINCOS]], 0 71 ; CHECK: extractvalue { double, double } [[SINCOS]], 1 72 73 ; CHECK-NO-SINCOS: call double @__sinpi 74 ; CHECK-NO-SINCOS: call double @__cospi 75 } 76 77 define double @test_constant_f64() { 78 %sin = call double @__sinpi(double 1.0) #0 79 %cos = call double @__cospi(double 1.0) #0 80 %res = fadd double %sin, %cos 81 ret double %res 82 ; CHECK-FLOAT-IN-VEC: [[SINCOS:%[a-z0-9]+]] = call { double, double } @__sincospi_stret(double 1.000000e+00) 83 ; CHECK-FLOAT-IN-VEC: extractvalue { double, double } [[SINCOS]], 0 84 ; CHECK-FLOAT-IN-VEC: extractvalue { double, double } [[SINCOS]], 1 85 86 ; CHECK: [[SINCOS:%[a-z0-9]+]] = call { double, double } @__sincospi_stret(double 1.000000e+00) 87 ; CHECK: extractvalue { double, double } [[SINCOS]], 0 88 ; CHECK: extractvalue { double, double } [[SINCOS]], 1 89 90 ; CHECK-NO-SINCOS: call double @__sinpi 91 ; CHECK-NO-SINCOS: call double @__cospi 92 } 93 94 define double @test_fptr(double (double)* %fptr, double %p1) { 95 %sin = call double @__sinpi(double %p1) #0 96 %cos = call double %fptr(double %p1) 97 %res = fadd double %sin, %cos 98 ret double %res 99 ; CHECK-LABEL: @test_fptr 100 ; CHECK: __sinpi 101 } 102