Skip to content

Commit 6a08cf1

Browse files
committed
clang: Add __builtin_exp10* and use new llvm.exp10 intrinsic
https://reviews.llvm.org/D157911
1 parent 9c017a9 commit 6a08cf1

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ Floating Point Support in Clang
377377
semantics. If ``math-errno`` is disabled in the current TU, clang will
378378
re-enable ``math-errno`` in the presense of
379379
``#pragma float_control(precise,on)``.
380+
- Add ``__builtin_exp10``, ``__builtin_exp10f``,
381+
``__builtin_exp10f16``, ``__builtin_exp10l`` and
382+
``__builtin_exp10f128`` builtins.
380383

381384
AST Matchers
382385
------------

clang/include/clang/Basic/Builtins.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ BUILTIN(__builtin_exp2f, "ff" , "Fne")
245245
BUILTIN(__builtin_exp2f16, "hh" , "Fne")
246246
BUILTIN(__builtin_exp2l, "LdLd", "Fne")
247247
BUILTIN(__builtin_exp2f128, "LLdLLd" , "Fne")
248+
BUILTIN(__builtin_exp10 , "dd" , "Fne")
249+
BUILTIN(__builtin_exp10f, "ff" , "Fne")
250+
BUILTIN(__builtin_exp10f16, "hh" , "Fne")
251+
BUILTIN(__builtin_exp10l, "LdLd", "Fne")
252+
BUILTIN(__builtin_exp10f128, "LLdLLd" , "Fne")
248253
BUILTIN(__builtin_expm1 , "dd", "Fne")
249254
BUILTIN(__builtin_expm1f, "ff", "Fne")
250255
BUILTIN(__builtin_expm1l, "LdLd", "Fne")

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,16 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
24332433
return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E,
24342434
Intrinsic::exp2,
24352435
Intrinsic::experimental_constrained_exp2));
2436-
2436+
case Builtin::BI__builtin_exp10:
2437+
case Builtin::BI__builtin_exp10f:
2438+
case Builtin::BI__builtin_exp10f16:
2439+
case Builtin::BI__builtin_exp10l:
2440+
case Builtin::BI__builtin_exp10f128: {
2441+
// TODO: strictfp support
2442+
if (Builder.getIsFPConstrained())
2443+
break;
2444+
return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::exp10));
2445+
}
24372446
case Builtin::BIfabs:
24382447
case Builtin::BIfabsf:
24392448
case Builtin::BIfabsl:

clang/test/CodeGen/constrained-math-builtins.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _
6464
// CHECK: call x86_fp80 @llvm.experimental.constrained.exp2.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
6565
// CHECK: call fp128 @llvm.experimental.constrained.exp2.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
6666

67+
__builtin_exp10(f); __builtin_exp10f(f); __builtin_exp10l(f); __builtin_exp10f128(f);
68+
69+
// CHECK: call double @exp10(double noundef %{{.*}})
70+
// CHECK: call float @exp10f(float noundef %{{.*}})
71+
// CHECK: call x86_fp80 @exp10l(x86_fp80 noundef %{{.*}})
72+
// CHECK: call fp128 @exp10f128(fp128 noundef %{{.*}})
73+
6774
__builtin_floor(f); __builtin_floorf(f); __builtin_floorl(f); __builtin_floorf128(f);
6875

6976
// CHECK: call double @llvm.experimental.constrained.floor.f64(double %{{.*}}, metadata !"fpexcept.strict")
@@ -223,6 +230,11 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _
223230
// CHECK: declare x86_fp80 @llvm.experimental.constrained.exp2.f80(x86_fp80, metadata, metadata)
224231
// CHECK: declare fp128 @llvm.experimental.constrained.exp2.f128(fp128, metadata, metadata)
225232

233+
// CHECK: declare double @exp10(double noundef)
234+
// CHECK: declare float @exp10f(float noundef)
235+
// CHECK: declare x86_fp80 @exp10l(x86_fp80 noundef)
236+
// CHECK: declare fp128 @exp10f128(fp128 noundef)
237+
226238
// CHECK: declare double @llvm.experimental.constrained.floor.f64(double, metadata)
227239
// CHECK: declare float @llvm.experimental.constrained.floor.f32(float, metadata)
228240
// CHECK: declare x86_fp80 @llvm.experimental.constrained.floor.f80(x86_fp80, metadata)

clang/test/CodeGen/math-builtins.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,17 @@ __builtin_exp2(f); __builtin_exp2f(f); __builtin_exp2l(f); __builtin_
318318
// HAS_ERRNO: declare x86_fp80 @exp2l(x86_fp80 noundef) [[NOT_READNONE]]
319319
// HAS_ERRNO: declare fp128 @exp2f128(fp128 noundef) [[NOT_READNONE]]
320320

321+
__builtin_exp10(f); __builtin_exp10f(f); __builtin_exp10l(f); __builtin_exp10f128(f);
322+
323+
// NO__ERRNO: declare double @llvm.exp10.f64(double) [[READNONE_INTRINSIC]]
324+
// NO__ERRNO: declare float @llvm.exp10.f32(float) [[READNONE_INTRINSIC]]
325+
// NO__ERRNO: declare x86_fp80 @llvm.exp10.f80(x86_fp80) [[READNONE_INTRINSIC]]
326+
// NO__ERRNO: declare fp128 @llvm.exp10.f128(fp128) [[READNONE_INTRINSIC]]
327+
// HAS_ERRNO: declare double @exp10(double noundef) [[NOT_READNONE]]
328+
// HAS_ERRNO: declare float @exp10f(float noundef) [[NOT_READNONE]]
329+
// HAS_ERRNO: declare x86_fp80 @exp10l(x86_fp80 noundef) [[NOT_READNONE]]
330+
// HAS_ERRNO: declare fp128 @exp10f128(fp128 noundef) [[NOT_READNONE]]
331+
321332
__builtin_expm1(f); __builtin_expm1f(f); __builtin_expm1l(f); __builtin_expm1f128(f);
322333

323334
// NO__ERRNO: declare double @expm1(double noundef) [[READNONE]]

clang/test/CodeGenOpenCL/builtins-f16.cl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ void test_half_builtins(half h0, half h1, half h2, int i0) {
2424
// CHECK: call half @llvm.exp2.f16(half %h0)
2525
res = __builtin_exp2f16(h0);
2626

27+
// CHECK: call half @llvm.exp10.f16(half %h0)
28+
res = __builtin_exp10f16(h0);
29+
2730
// CHECK: call half @llvm.floor.f16(half %h0)
2831
res = __builtin_floorf16(h0);
2932

0 commit comments

Comments
 (0)