Skip to content

Commit

Permalink
[SYCL] fpbuiltin calls not generated for 32bit version of functions. (#…
Browse files Browse the repository at this point in the history
…12818)

This patch adds the missing 32-bit version of the math function.
  • Loading branch information
zahiraam authored Mar 6, 2024
1 parent 6844546 commit f28c05c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
16 changes: 16 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
}
Expand Down
29 changes: 23 additions & 6 deletions clang/test/CodeGen/fp-accuracy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {{.*}})
Expand All @@ -418,22 +422,28 @@ 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]]
// CHECK-F2: call float @llvm.fpbuiltin.sin.f32(float {{.*}}) #[[ATTR_F2_MEDIUM]]
// 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]]
// CHECK-F4: call float @llvm.fpbuiltin.sin.f32(float {{.*}}) #[[ATTR_F4_MEDIUM]]
// 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

Expand All @@ -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

Expand All @@ -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
//
Expand All @@ -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 {{.*}})
Expand Down Expand Up @@ -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 {{.*}})

Expand All @@ -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)){}
Expand Down

0 comments on commit f28c05c

Please sign in to comment.