From f28c05c7d8e9ced46208bac5bf5222c2caedc235 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat Date: Wed, 6 Mar 2024 04:38:07 -0800 Subject: [PATCH] [SYCL] fpbuiltin calls not generated for 32bit version of functions. (#12818) This patch adds the missing 32-bit version of the math function. --- clang/lib/CodeGen/CGBuiltin.cpp | 16 ++++++++++++++++ clang/test/CodeGen/fp-accuracy.c | 29 +++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index edefcc9985ec6..04c4252017d7f 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -23449,54 +23449,67 @@ llvm::CallInst *CodeGenFunction::MaybeEmitFPBuiltinofFD( // attribute. return nullptr; case Builtin::BItan: + case Builtin::BItanf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_tan; break; case Builtin::BItanh: + case Builtin::BItanhf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_tanh; break; case Builtin::BIlog2: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_log2; break; case Builtin::BIlog1p: + case Builtin::BIlog1pf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_log1p; break; case Builtin::BIcos: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_cos; break; case Builtin::BIcosh: + case Builtin::BIcoshf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_cosh; break; case Builtin::BIacos: + case Builtin::BIacosf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_acos; break; case Builtin::BIacosh: + case Builtin::BIacoshf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_acosh; break; case Builtin::BIsin: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_sin; break; case Builtin::BIsinh: + case Builtin::BIsinhf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_sinh; break; case Builtin::BIasin: + case Builtin::BIasinf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_asin; break; case Builtin::BIasinh: + case Builtin::BIasinhf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_asinh; break; case Builtin::BIatan: + case Builtin::BIatanf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_atan; break; case Builtin::BIatanh: + case Builtin::BIatanhf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_atanh; break; case Builtin::BIatan2: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_atan2; break; case Builtin::BIerf: + case Builtin::BIerff: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_erf; break; case Builtin::BIerfc: + case Builtin::BIerfcf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_erfc; break; case Builtin::BIexp: @@ -23506,12 +23519,15 @@ llvm::CallInst *CodeGenFunction::MaybeEmitFPBuiltinofFD( FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_exp2; break; case Builtin::BIexpm1: + case Builtin::BIexpm1f: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_expm1; break; case Builtin::BIhypot: + case Builtin::BIhypotf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_hypot; break; case Builtin::BIldexp: + case Builtin::BIldexpf: FPAccuracyIntrinsicID = Intrinsic::fpbuiltin_ldexp; break; } diff --git a/clang/test/CodeGen/fp-accuracy.c b/clang/test/CodeGen/fp-accuracy.c index 3fdde4443b8c8..1bf87bfb9b887 100644 --- a/clang/test/CodeGen/fp-accuracy.c +++ b/clang/test/CodeGen/fp-accuracy.c @@ -209,6 +209,8 @@ double rsqrt(double); // CHECK-F3: call double @llvm.fpbuiltin.tan.f64(double {{.*}}) #[[ATTR_F3_LOW]] // CHECK-F3: call double @llvm.fpbuiltin.log10.f64(double {{.*}}) #[[ATTR_F3_MEDIUM]] // CHECK-F3: call void @llvm.fpbuiltin.sincos.f64(double {{.*}}, ptr {{.*}}, ptr {{.*}}) #[[ATTR_F3_MEDIUM]] +// CHECK-F3: call float @llvm.fpbuiltin.tan.f32(float {{.*}}) #[[ATTR_F3_HIGH]] +// CHECK-F3: call float @llvm.fpbuiltin.hypot.f32(float {{.*}}, float {{.*}}) #[[ATTR_F3_HIGH]] // CHECK-F3-LABEL: define dso_local float @fake_exp10 @@ -409,7 +411,9 @@ void f1(float a, float b) { // CHECK: call double @llvm.fpbuiltin.tan.f64(double {{.*}}) #[[ATTR_HIGH]] // CHECK: call double @llvm.fpbuiltin.log10.f64(double {{.*}}) #[[ATTR_HIGH]] // CHECK: call void @llvm.fpbuiltin.sincos.f64(double {{.*}}, ptr {{.*}}, ptr {{.*}}) #[[ATTR_HIGH]] -// CHECK: call float @tanf(float {{.*}}) +// CHECK: call float @llvm.fpbuiltin.tan.f32(float {{.*}}) #[[ATTR_HIGH]] +// CHECK: call float @llvm.fpbuiltin.hypot.f32(float {{.*}}, float {{.*}}) #[[ATTR_HIGH]] +// CHECK: call float @llvm.fpbuiltin.ldexp.f32(float {{.*}}, i32 {{.*}}) #[[ATTR_HIGH]] // // CHECK-F1-LABEL: define dso_local void @f2 // CHECK-F1: call float @llvm.cos.f32(float {{.*}}) @@ -418,6 +422,8 @@ void f1(float a, float b) { // CHECK-F1: call double @llvm.fpbuiltin.log10.f64(double {{.*}}) #[[ATTR_F1_MEDIUM]] // CHECK-F1: call void @llvm.fpbuiltin.sincos.f64(double {{.*}}, ptr {{.*}}, ptr {{.*}}) #[[ATTR_F1_MEDIUM]] // CHECK-F1: call float @tanf(float {{.*}}) +// CHECK-F1: call float @hypotf(float {{.*}}, float {{.*}}) +// CHECK-F1: call float @ldexpf(float {{.*}}, i32 {{.*}}) // // CHECK-F2-LABEL: define dso_local void @f2 // CHECK-F2: call float @llvm.fpbuiltin.cos.f32(float {{.*}}) #[[ATTR_F2_MEDIUM]] @@ -425,7 +431,9 @@ void f1(float a, float b) { // CHECK-F2: call double @llvm.fpbuiltin.tan.f64(double {{.*}}) #[[ATTR_F2_HIGH]] // CHECK-F2: call double @llvm.fpbuiltin.log10.f64(double {{.*}}) #[[ATTR_F2_MEDIUM]] // CHECK-F2: call void @llvm.fpbuiltin.sincos.f64(double {{.*}}, ptr {{.*}}, ptr {{.*}}) #[[ATTR_F2_MEDIUM]] -// CHECK-F2: call float @tanf(float {{.*}}) +// CHECK-F2: call float @llvm.fpbuiltin.tan.f32(float {{.*}}) #[[ATTR_F2_MEDIUM]] +// CHECK-F2: call float @llvm.fpbuiltin.hypot.f32(float {{.*}}, float {{.*}}) #[[ATTR_F2_MEDIUM]] +// CHECK-F2: call float @llvm.fpbuiltin.ldexp.f32(float {{.*}}, i32 {{.*}}) #[[ATTR_F2_MEDIUM]] // // CHECK-F4-LABEL: define dso_local void @f2 // CHECK-F4: call float @llvm.fpbuiltin.cos.f32(float {{.*}}) #[[ATTR_F4_MEDIUM]] @@ -433,7 +441,9 @@ void f1(float a, float b) { // CHECK-F4: call double @llvm.fpbuiltin.tan.f64(double {{.*}}) #[[ATTR_F4_MEDIUM]] // CHECK-F4: call double @llvm.fpbuiltin.log10.f64(double {{.*}}) #[[ATTR_F4_MEDIUM]] // CHECK-F4: call void @llvm.fpbuiltin.sincos.f64(double {{.*}}, ptr {{.*}}, ptr {{.*}}) #[[ATTR_F4_MEDIUM]] -// CHECK-F4: call float @tanf(float {{.*}}) +// CHECK-F4: call float @llvm.fpbuiltin.tan.f32(float {{.*}}) #[[ATTR_F4_MEDIUM]] +// CHECK-F4: call float @llvm.fpbuiltin.hypot.f32(float {{.*}}, float {{.*}}) #[[ATTR_F4_MEDIUM]] +// CHECK-F4: call float @llvm.fpbuiltin.ldexp.f32(float {{.*}}, i32 {{.*}}) #[[ATTR_F4_MEDIUM]] // // CHECK-F4-LABEL: define dso_local float @fake_exp10 @@ -453,6 +463,8 @@ void f1(float a, float b) { // CHECK-F5: call double @llvm.log10.f64(double {{.*}}) // CHECK-F5: call i32 (double, ptr, ptr, ...) @sincos(double {{.*}}, ptr {{.*}}, ptr {{.*}}) // CHECK-F5: call float @tanf(float {{.*}}) +// CHECK-F5: call float @hypotf(float {{.*}}, float {{.*}}) +// CHECK-F5: call float @ldexpf(float {{.*}}, i32 {{.*}}) // // CHECK-F5-LABEL: define dso_local float @fake_exp10 @@ -472,7 +484,9 @@ void f1(float a, float b) { // CHECK-F6: call double @llvm.fpbuiltin.tan.f64(double {{.*}}) #[[ATTR_F6_MEDIUM]] // CHECK-F6: call double @llvm.fpbuiltin.log10.f64(double {{.*}}) #[[ATTR_F6_MEDIUM]] // CHECK-F6: call void @llvm.fpbuiltin.sincos.f64(double {{.*}}, ptr {{.*}}, ptr {{.*}}) #[[ATTR_F6_MEDIUM]] -// CHECK-F6: call float @tanf(float {{.*}}) #[[ATTR8:[0-9]+]] +// CHECK-F6: call float @llvm.fpbuiltin.tan.f32(float {{.*}}) #[[ATTR_F6_MEDIUM]] +// CHECK-F6: call float @llvm.fpbuiltin.hypot.f32(float {{.*}}, float {{.*}}) #[[ATTR_F6_MEDIUM]] +// CHECK-F6: call float @llvm.fpbuiltin.ldexp.f32(float {{.*}}, i32 {{.*}}) #[[ATTR_F6_MEDIUM]] // // CHECK-F6-LABEL: define dso_local float @fake_exp10 // @@ -492,7 +506,7 @@ void f1(float a, float b) { // CHECK-SPIR: call double @llvm.fpbuiltin.tan.f64(double {{.*}}) #[[ATTR_SYCL2]] // CHECK-SPIR: call double @llvm.fpbuiltin.log10.f64(double {{.*}}) #[[ATTR_SYCL5]] // CHECK-SPIR: call void @llvm.fpbuiltin.sincos.f32(float {{.*}}, ptr {{.*}}, ptr {{.*}}) #[[ATTR_SYCL1]] -// CHECK-SPIR: call spir_func float @tanf(float {{.*}}) +// CHECK-SPIR: call float @llvm.fpbuiltin.tan.f32(float {{.*}}) #[[ATTR_SYCL2]] // CHECK-LABEL: define dso_local void @f3 // CHECK: call float @fake_exp10(float {{.*}}) @@ -588,7 +602,8 @@ void f1(float a, float b) { // CHECK-DEFAULT: call double @llvm.log10.f64(double {{.*}}) // CHECK-DEFAULT: call i32 (double, ptr, ptr, ...) @sincos(double {{.*}}, ptr {{.*}}, ptr {{.*}}) // CHECK-DEFAULT: call float @tanf(float {{.*}}) - +// CHECK-DEFAULT: call float @hypotf(float {{.*}}, float {{.*}}) +// // CHECK-DEFAULT-LABEL: define dso_local void @f3 // CHECK-DEFAULT: call float @fake_exp10(float {{.*}}) @@ -605,6 +620,8 @@ void f2(float a, float b) { b = log10(b); sincos(b, &sin, &cos); b = tanf(b); + b = hypotf(b,b); + b = ldexpf(b,b); } float fake_exp10(float a) __attribute__((no_builtin)){}