[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
ilovepi wrote: Thanks for the prompt revert. That's a big help. > @ilovepi, How many platforms do you build Fuchsia for? It will be important > to know which backends needs support before we try to re-land this. Fuchsia builds for Aarch64, RISC-V 64, and X86_64. Our toolchain is also used in a lot of embedded contexts (mostly ARM32) but that is separate from Fuchsia's build. https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
farzonl wrote: @ilovepi, How many platforms do you build Fuchsia for? It will be important to know which backends needs support before we try to re-land this. https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
farzonl wrote: > Hi, we're seeing a codegen issue building Fuchsia after this patch. I'm > looking now, but so far I'm not sure why this is happening. Would you mind > taking a look? > > Error: > fatal error: error in backend: Cannot select: intrinsic %llvm.tan > PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ > and include the crash backtrace, preprocessed source, and associated run > script. > 4.Running pass 'X86 DAG->DAG Instruction Selection' on function > '@spinel_transform_stack_push_skew_x' > #0 0x558e5225bc78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) > (../../prebuilt/third_party/clang/custom/bin/clang+0x8936c78) > clang: error: clang frontend command failed with exit code 70 (use -v to see > invocation) > Fuchsia clang version 19.0.0git (https://llvm.googlesource.com/llvm-project > 1de6011c34b185235cd65c2e3fb030015d182968) Hi @ilovepi, This is interesting because I didn't see anything in x86 dag specific to constraint intrinsics but I suspect exposing `tan` as an ISDOpcodes is causing the problem. The issue is because x86 DAG instruction selection hasn't landed yet: https://github.com/llvm/llvm-project/pull/90503 and the pass is trying to replace the intrinsic with something else and can't. I'm still waiting on approvals for that part. Looks like the right course is to revert this change for now. https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
ilovepi wrote: Hi, we're seeing a codegen issue building Fuchsia after this patch. I'm looking now, but so far I'm not sure why this is happening. Would you mind taking a look? Error: ``` FAILED: obj/src/graphics/lib/compute/spinel/ext/transform_stack/transform_stack.transform_stack.c.o ../../prebuilt/third_party/clang/custom/bin/clang -MD -MF obj/src/graphics/lib/compute/spinel/ext/transform_stack/transform_stack.transform_stack.c.o.d -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -DNDEBUG=1 -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -I../.. -Igen -I../../src/graphics/lib/compute/spinel/include -I../../src/graphics/lib/compute -fcolor-diagnostics -fcrash-diagnostics-dir=clang-crashreports -fcrash-diagnostics=all -gen-reproducer=error -ffp-contract=off --sysroot=gen/zircon/public/sysroot/cpp --target=x86_64-unknown-fuchsia -ffuchsia-api-level=4293918720 -march=x86-64-v2 -mtune=generic -mbranches-within-32B-boundaries -ffile-compilation-dir=. -no-canonical-prefixes -fomit-frame-pointer -fdata-sections -ffunction-sections -Os -flto -mllvm -wholeprogramdevirt-branch-funnel-threshold=0 -ffat-lto-objects -Xclang -debug-info-kind=constructor -g3 -grecord-gcc-switches -gdwarf-5 -gz=zstd -Wall -Wextra -Wconversion -Wextra-semi -Wimplicit-fallthrough -Wnewline-eof -Wstrict-prototypes -Wwrite-strings -Wno-sign-conversion -Wno-unused-parameter -Wnonportable-system-include-path -Wno-missing-field-initializers -Wno-extra-qualification -Wno-cast-function-type-strict -Wno-cast-function-type-mismatch -Wno-unknown-warning-option -Wno-deprecated-pragma -fvisibility=hidden -Werror -Wa,--fatal-warnings -ftrivial-auto-var-init=pattern -Wthread-safety -Wno-unknown-warning-option -Wno-thread-safety-reference-return -std=c11 -c ../../src/graphics/lib/compute/spinel/ext/transform_stack/transform_stack.c -o obj/src/graphics/lib/compute/spinel/ext/transform_stack/transform_stack.transform_stack.c.o fatal error: error in backend: Cannot select: intrinsic %llvm.tan PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: ../../prebuilt/third_party/clang/custom/bin/clang -MD -MF obj/src/graphics/lib/compute/spinel/ext/transform_stack/transform_stack.transform_stack.c.o.d -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -DNDEBUG=1 -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -I../.. -Igen -I../../src/graphics/lib/compute/spinel/include -I../../src/graphics/lib/compute -fcolor-diagnostics -fcrash-diagnostics-dir=clang-crashreports -fcrash-diagnostics=all -gen-reproducer=error -ffp-contract=off --sysroot=gen/zircon/public/sysroot/cpp --target=x86_64-unknown-fuchsia -ffuchsia-api-level=4293918720 -march=x86-64-v2 -mtune=generic -mbranches-within-32B-boundaries -ffile-compilation-dir=. -no-canonical-prefixes -fomit-frame-pointer -fdata-sections -ffunction-sections -Os -flto -mllvm -wholeprogramdevirt-branch-funnel-threshold=0 -ffat-lto-objects -Xclang -debug-info-kind=constructor -g3 -grecord-gcc-switches -gdwarf-5 -gz=zstd -Wall -Wextra -Wconversion -Wextra-semi -Wimplicit-fallthrough -Wnewline-eof -Wstrict-prototypes -Wwrite-strings -Wno-sign-conversion -Wno-unused-parameter -Wnonportable-system-include-path -Wno-missing-field-initializers -Wno-extra-qualification -Wno-cast-function-type-strict -Wno-cast-function-type-mismatch -Wno-unknown-warning-option -Wno-deprecated-pragma -fvisibility=hidden -Werror -Wa,--fatal-warnings -ftrivial-auto-var-init=pattern -Wthread-safety -Wno-unknown-warning-option -Wno-thread-safety-reference-return -std=c11 -c ../../src/graphics/lib/compute/spinel/ext/transform_stack/transform_stack.c -o obj/src/graphics/lib/compute/spinel/ext/transform_stack/transform_stack.transform_stack.c.o 1. parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module '../../src/graphics/lib/compute/spinel/ext/transform_stack/transform_stack.c'. 4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@spinel_transform_stack_push_skew_x' #0 0x558e5225bc78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../prebuilt/third_party/clang/custom/bin/clang+0x8936c78) clang: error: clang frontend command failed with exit code 70 (use -v to see invocation) Fuchsia clang version 19.0.0git (https://llvm.googlesource.com/llvm-project 1de6011c34b185235cd65c2e3fb030015d182968) Target: x86_64-unknown-fuchsia Thread model: posix InstalledDir: ../../prebuilt/third_party/clang/custom/bin Build config: +assertions clang: note: diagnostic msg: PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg:
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/farzonl closed https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/efriedma-quic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/coopp approved this pull request. Looks good to me. https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/93314 >From 683dfa875e024acba12b229dbecd6d10573c891f Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Fri, 24 May 2024 10:01:52 -0400 Subject: [PATCH 1/3] [clang] Add tanf16 builtin and support for tan constrained intrinsic --- clang/include/clang/Basic/Builtins.td | 6 ++-- clang/lib/CodeGen/CGBuiltin.cpp | 13 +++ clang/test/CodeGen/X86/math-builtins.c| 8 ++--- .../test/CodeGen/constrained-math-builtins.c | 13 +++ clang/test/CodeGen/math-libcalls.c| 12 +++ clang/test/CodeGenOpenCL/builtins-f16.cl | 3 ++ llvm/docs/LangRef.rst | 36 +++ llvm/include/llvm/CodeGen/ISDOpcodes.h| 2 ++ llvm/include/llvm/IR/ConstrainedOps.def | 1 + llvm/include/llvm/IR/Intrinsics.td| 4 +++ llvm/test/Assembler/fp-intrinsics-attr.ll | 8 + llvm/test/Feature/fp-intrinsics.ll| 11 ++ 12 files changed, 104 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 11982af3fa609..7bef5fd7ad40f 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -482,11 +482,11 @@ def SqrtF16F128 : Builtin, F16F128MathTemplate { let Prototype = "T(T)"; } -def TanF128 : Builtin { - let Spellings = ["__builtin_tanf128"]; +def TanF16F128 : Builtin, F16F128MathTemplate { + let Spellings = ["__builtin_tan"]; let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions]; - let Prototype = "__float128(__float128)"; + let Prototype = "T(T)"; } def TanhF128 : Builtin { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 91083c1cfae96..7650a006fffb1 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2922,6 +2922,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, SetSqrtFPAccuracy(Call); return RValue::get(Call); } + +case Builtin::BItan: +case Builtin::BItanf: +case Builtin::BItanl: +case Builtin::BI__builtin_tan: +case Builtin::BI__builtin_tanf: +case Builtin::BI__builtin_tanf16: +case Builtin::BI__builtin_tanl: +case Builtin::BI__builtin_tanf128: + return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E, + Intrinsic::tan, + Intrinsic::experimental_constrained_tan)); + case Builtin::BItrunc: case Builtin::BItruncf: case Builtin::BItruncl: diff --git a/clang/test/CodeGen/X86/math-builtins.c b/clang/test/CodeGen/X86/math-builtins.c index 093239b448260..1e0f129b98610 100644 --- a/clang/test/CodeGen/X86/math-builtins.c +++ b/clang/test/CodeGen/X86/math-builtins.c @@ -674,10 +674,10 @@ __builtin_sqrt(f); __builtin_sqrtf(f); __builtin_sqrtl(f); __builtin_ __builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); -// NO__ERRNO: declare double @tan(double noundef) [[READNONE]] -// NO__ERRNO: declare float @tanf(float noundef) [[READNONE]] -// NO__ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[READNONE]] -// NO__ERRNO: declare fp128 @tanf128(fp128 noundef) [[READNONE]] +// NO__ERRNO: declare double @llvm.tan.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare float @llvm.tan.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare x86_fp80 @llvm.tan.f80(x86_fp80) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare fp128 @llvm.tan.f128(fp128) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare double @tan(double noundef) [[NOT_READNONE]] // HAS_ERRNO: declare float @tanf(float noundef) [[NOT_READNONE]] // HAS_ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[NOT_READNONE]] diff --git a/clang/test/CodeGen/constrained-math-builtins.c b/clang/test/CodeGen/constrained-math-builtins.c index 2de832dd2b6ca..4673418c79c97 100644 --- a/clang/test/CodeGen/constrained-math-builtins.c +++ b/clang/test/CodeGen/constrained-math-builtins.c @@ -183,6 +183,14 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _ // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +__builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); + +// CHECK: call double @llvm.experimental.constrained.tan.f64(double %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call float @llvm.experimental.constrained.tan.f32(float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call x86_fp80 @llvm.experimental.constrained.tan.f80(x86_fp80 %{{.*}}, metadata
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
@@ -183,6 +183,14 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _ // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +__builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); farzonl wrote: my mistake looks like im missing a tab. https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
farzonl wrote: > IMO it'd be good to have a bit more context in the commit description about > why this is being done. If you follow the breadcrumbs from the issue to the > thread in the PR I think you can put it together, but a more local summary > might be helpful. done https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/bogner approved this pull request. https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
@@ -183,6 +183,14 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _ // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +__builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); damyanp wrote: super nit: it looks like the other `f` prefixed ones all line up to the same column, apart from this new one. https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/damyanp approved this pull request. IMO it'd be good to have a bit more context in the commit description about why this is being done. If you follow the breadcrumbs from the issue to the thread in the PR I think you can put it together, but a more local summary might be helpful. https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/damyanp edited https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/93314 >From 683dfa875e024acba12b229dbecd6d10573c891f Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Fri, 24 May 2024 10:01:52 -0400 Subject: [PATCH 1/2] [clang] Add tanf16 builtin and support for tan constrained intrinsic --- clang/include/clang/Basic/Builtins.td | 6 ++-- clang/lib/CodeGen/CGBuiltin.cpp | 13 +++ clang/test/CodeGen/X86/math-builtins.c| 8 ++--- .../test/CodeGen/constrained-math-builtins.c | 13 +++ clang/test/CodeGen/math-libcalls.c| 12 +++ clang/test/CodeGenOpenCL/builtins-f16.cl | 3 ++ llvm/docs/LangRef.rst | 36 +++ llvm/include/llvm/CodeGen/ISDOpcodes.h| 2 ++ llvm/include/llvm/IR/ConstrainedOps.def | 1 + llvm/include/llvm/IR/Intrinsics.td| 4 +++ llvm/test/Assembler/fp-intrinsics-attr.ll | 8 + llvm/test/Feature/fp-intrinsics.ll| 11 ++ 12 files changed, 104 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 11982af3fa609..7bef5fd7ad40f 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -482,11 +482,11 @@ def SqrtF16F128 : Builtin, F16F128MathTemplate { let Prototype = "T(T)"; } -def TanF128 : Builtin { - let Spellings = ["__builtin_tanf128"]; +def TanF16F128 : Builtin, F16F128MathTemplate { + let Spellings = ["__builtin_tan"]; let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions]; - let Prototype = "__float128(__float128)"; + let Prototype = "T(T)"; } def TanhF128 : Builtin { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 91083c1cfae96..7650a006fffb1 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2922,6 +2922,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, SetSqrtFPAccuracy(Call); return RValue::get(Call); } + +case Builtin::BItan: +case Builtin::BItanf: +case Builtin::BItanl: +case Builtin::BI__builtin_tan: +case Builtin::BI__builtin_tanf: +case Builtin::BI__builtin_tanf16: +case Builtin::BI__builtin_tanl: +case Builtin::BI__builtin_tanf128: + return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E, + Intrinsic::tan, + Intrinsic::experimental_constrained_tan)); + case Builtin::BItrunc: case Builtin::BItruncf: case Builtin::BItruncl: diff --git a/clang/test/CodeGen/X86/math-builtins.c b/clang/test/CodeGen/X86/math-builtins.c index 093239b448260..1e0f129b98610 100644 --- a/clang/test/CodeGen/X86/math-builtins.c +++ b/clang/test/CodeGen/X86/math-builtins.c @@ -674,10 +674,10 @@ __builtin_sqrt(f); __builtin_sqrtf(f); __builtin_sqrtl(f); __builtin_ __builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); -// NO__ERRNO: declare double @tan(double noundef) [[READNONE]] -// NO__ERRNO: declare float @tanf(float noundef) [[READNONE]] -// NO__ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[READNONE]] -// NO__ERRNO: declare fp128 @tanf128(fp128 noundef) [[READNONE]] +// NO__ERRNO: declare double @llvm.tan.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare float @llvm.tan.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare x86_fp80 @llvm.tan.f80(x86_fp80) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare fp128 @llvm.tan.f128(fp128) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare double @tan(double noundef) [[NOT_READNONE]] // HAS_ERRNO: declare float @tanf(float noundef) [[NOT_READNONE]] // HAS_ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[NOT_READNONE]] diff --git a/clang/test/CodeGen/constrained-math-builtins.c b/clang/test/CodeGen/constrained-math-builtins.c index 2de832dd2b6ca..4673418c79c97 100644 --- a/clang/test/CodeGen/constrained-math-builtins.c +++ b/clang/test/CodeGen/constrained-math-builtins.c @@ -183,6 +183,14 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _ // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +__builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); + +// CHECK: call double @llvm.experimental.constrained.tan.f64(double %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call float @llvm.experimental.constrained.tan.f32(float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call x86_fp80 @llvm.experimental.constrained.tan.f80(x86_fp80 %{{.*}}, metadata
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 7eeec8e6d10a796974c3439529f3de690251b004 683dfa875e024acba12b229dbecd6d10573c891f -- clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/X86/math-builtins.c clang/test/CodeGen/constrained-math-builtins.c clang/test/CodeGen/math-libcalls.c llvm/include/llvm/CodeGen/ISDOpcodes.h `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 7650a006ff..443ed4c025 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2931,9 +2931,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_tanf16: case Builtin::BI__builtin_tanl: case Builtin::BI__builtin_tanf128: - return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E, - Intrinsic::tan, - Intrinsic::experimental_constrained_tan)); + return RValue::get(emitUnaryMaybeConstrainedFPBuiltin( + *this, E, Intrinsic::tan, Intrinsic::experimental_constrained_tan)); case Builtin::BItrunc: case Builtin::BItruncf: `` https://github.com/llvm/llvm-project/pull/93314 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Farzon Lotfi (farzonl) Changes - `Builtins.td` - replace TanF128 with F16F128MathTemplate - `CGBuiltin.cpp` - map existing tan builtins to `tan` and `constrained_tan` intrinsic - `ConstrainedOps.def` map tan and constrained_tan to an ISDOpcode. - `ISDOpcodes.h` - define tan and strict tan opcodes resolves #91421 --- Full diff: https://github.com/llvm/llvm-project/pull/93314.diff 12 Files Affected: - (modified) clang/include/clang/Basic/Builtins.td (+3-3) - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+13) - (modified) clang/test/CodeGen/X86/math-builtins.c (+4-4) - (modified) clang/test/CodeGen/constrained-math-builtins.c (+13) - (modified) clang/test/CodeGen/math-libcalls.c (+6-6) - (modified) clang/test/CodeGenOpenCL/builtins-f16.cl (+3) - (modified) llvm/docs/LangRef.rst (+36) - (modified) llvm/include/llvm/CodeGen/ISDOpcodes.h (+2) - (modified) llvm/include/llvm/IR/ConstrainedOps.def (+1) - (modified) llvm/include/llvm/IR/Intrinsics.td (+4) - (modified) llvm/test/Assembler/fp-intrinsics-attr.ll (+8) - (modified) llvm/test/Feature/fp-intrinsics.ll (+11) ``diff diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 11982af3fa609..7bef5fd7ad40f 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -482,11 +482,11 @@ def SqrtF16F128 : Builtin, F16F128MathTemplate { let Prototype = "T(T)"; } -def TanF128 : Builtin { - let Spellings = ["__builtin_tanf128"]; +def TanF16F128 : Builtin, F16F128MathTemplate { + let Spellings = ["__builtin_tan"]; let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions]; - let Prototype = "__float128(__float128)"; + let Prototype = "T(T)"; } def TanhF128 : Builtin { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 91083c1cfae96..7650a006fffb1 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2922,6 +2922,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, SetSqrtFPAccuracy(Call); return RValue::get(Call); } + +case Builtin::BItan: +case Builtin::BItanf: +case Builtin::BItanl: +case Builtin::BI__builtin_tan: +case Builtin::BI__builtin_tanf: +case Builtin::BI__builtin_tanf16: +case Builtin::BI__builtin_tanl: +case Builtin::BI__builtin_tanf128: + return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E, + Intrinsic::tan, + Intrinsic::experimental_constrained_tan)); + case Builtin::BItrunc: case Builtin::BItruncf: case Builtin::BItruncl: diff --git a/clang/test/CodeGen/X86/math-builtins.c b/clang/test/CodeGen/X86/math-builtins.c index 093239b448260..1e0f129b98610 100644 --- a/clang/test/CodeGen/X86/math-builtins.c +++ b/clang/test/CodeGen/X86/math-builtins.c @@ -674,10 +674,10 @@ __builtin_sqrt(f); __builtin_sqrtf(f); __builtin_sqrtl(f); __builtin_ __builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); -// NO__ERRNO: declare double @tan(double noundef) [[READNONE]] -// NO__ERRNO: declare float @tanf(float noundef) [[READNONE]] -// NO__ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[READNONE]] -// NO__ERRNO: declare fp128 @tanf128(fp128 noundef) [[READNONE]] +// NO__ERRNO: declare double @llvm.tan.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare float @llvm.tan.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare x86_fp80 @llvm.tan.f80(x86_fp80) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare fp128 @llvm.tan.f128(fp128) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare double @tan(double noundef) [[NOT_READNONE]] // HAS_ERRNO: declare float @tanf(float noundef) [[NOT_READNONE]] // HAS_ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[NOT_READNONE]] diff --git a/clang/test/CodeGen/constrained-math-builtins.c b/clang/test/CodeGen/constrained-math-builtins.c index 2de832dd2b6ca..4673418c79c97 100644 --- a/clang/test/CodeGen/constrained-math-builtins.c +++ b/clang/test/CodeGen/constrained-math-builtins.c @@ -183,6 +183,14 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _ // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +__builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); + +// CHECK: call double @llvm.experimental.constrained.tan.f64(double %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +// CHECK: call float @llvm.experimental.constrained.tan.f32(float %{{.*}}, metadata
[clang] [llvm] [clang] Add tanf16 builtin and support for tan constrained intrinsic (PR #93314)
https://github.com/farzonl created https://github.com/llvm/llvm-project/pull/93314 - `Builtins.td` - replace TanF128 with F16F128MathTemplate - `CGBuiltin.cpp` - map existing tan builtins to `tan` and `constrained_tan` intrinsic - `ConstrainedOps.def` map tan and constrained_tan to an ISDOpcode. - `ISDOpcodes.h` - define tan and strict tan opcodes resolves #91421 >From 683dfa875e024acba12b229dbecd6d10573c891f Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Fri, 24 May 2024 10:01:52 -0400 Subject: [PATCH] [clang] Add tanf16 builtin and support for tan constrained intrinsic --- clang/include/clang/Basic/Builtins.td | 6 ++-- clang/lib/CodeGen/CGBuiltin.cpp | 13 +++ clang/test/CodeGen/X86/math-builtins.c| 8 ++--- .../test/CodeGen/constrained-math-builtins.c | 13 +++ clang/test/CodeGen/math-libcalls.c| 12 +++ clang/test/CodeGenOpenCL/builtins-f16.cl | 3 ++ llvm/docs/LangRef.rst | 36 +++ llvm/include/llvm/CodeGen/ISDOpcodes.h| 2 ++ llvm/include/llvm/IR/ConstrainedOps.def | 1 + llvm/include/llvm/IR/Intrinsics.td| 4 +++ llvm/test/Assembler/fp-intrinsics-attr.ll | 8 + llvm/test/Feature/fp-intrinsics.ll| 11 ++ 12 files changed, 104 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 11982af3fa609..7bef5fd7ad40f 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -482,11 +482,11 @@ def SqrtF16F128 : Builtin, F16F128MathTemplate { let Prototype = "T(T)"; } -def TanF128 : Builtin { - let Spellings = ["__builtin_tanf128"]; +def TanF16F128 : Builtin, F16F128MathTemplate { + let Spellings = ["__builtin_tan"]; let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions]; - let Prototype = "__float128(__float128)"; + let Prototype = "T(T)"; } def TanhF128 : Builtin { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 91083c1cfae96..7650a006fffb1 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2922,6 +2922,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, SetSqrtFPAccuracy(Call); return RValue::get(Call); } + +case Builtin::BItan: +case Builtin::BItanf: +case Builtin::BItanl: +case Builtin::BI__builtin_tan: +case Builtin::BI__builtin_tanf: +case Builtin::BI__builtin_tanf16: +case Builtin::BI__builtin_tanl: +case Builtin::BI__builtin_tanf128: + return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E, + Intrinsic::tan, + Intrinsic::experimental_constrained_tan)); + case Builtin::BItrunc: case Builtin::BItruncf: case Builtin::BItruncl: diff --git a/clang/test/CodeGen/X86/math-builtins.c b/clang/test/CodeGen/X86/math-builtins.c index 093239b448260..1e0f129b98610 100644 --- a/clang/test/CodeGen/X86/math-builtins.c +++ b/clang/test/CodeGen/X86/math-builtins.c @@ -674,10 +674,10 @@ __builtin_sqrt(f); __builtin_sqrtf(f); __builtin_sqrtl(f); __builtin_ __builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); -// NO__ERRNO: declare double @tan(double noundef) [[READNONE]] -// NO__ERRNO: declare float @tanf(float noundef) [[READNONE]] -// NO__ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[READNONE]] -// NO__ERRNO: declare fp128 @tanf128(fp128 noundef) [[READNONE]] +// NO__ERRNO: declare double @llvm.tan.f64(double) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare float @llvm.tan.f32(float) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare x86_fp80 @llvm.tan.f80(x86_fp80) [[READNONE_INTRINSIC]] +// NO__ERRNO: declare fp128 @llvm.tan.f128(fp128) [[READNONE_INTRINSIC]] // HAS_ERRNO: declare double @tan(double noundef) [[NOT_READNONE]] // HAS_ERRNO: declare float @tanf(float noundef) [[NOT_READNONE]] // HAS_ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[NOT_READNONE]] diff --git a/clang/test/CodeGen/constrained-math-builtins.c b/clang/test/CodeGen/constrained-math-builtins.c index 2de832dd2b6ca..4673418c79c97 100644 --- a/clang/test/CodeGen/constrained-math-builtins.c +++ b/clang/test/CodeGen/constrained-math-builtins.c @@ -183,6 +183,14 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c, _ // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict") +__builtin_tan(f);__builtin_tanf(f); __builtin_tanl(f); __builtin_tanf128(f); + +// CHECK: call double @llvm.experimental.constrained.tan.f64(double