[clang] [llvm] [clang][hlsl] Add tan intrinsic part 1 (PR #90276)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 13:18:21 PDT 2024


farzonl wrote:

> Are you intentionally skipping implementing changes to __builtin_tan()?

Yes but, maybe my reasoning isn't good enough to exclude. Let me know. I didn't add it for two reasons.

First sine and cosine define builtins like so:
```
def SinF16F128 : Builtin, F16F128MathTemplate {
  let Spellings = ["__builtin_sin"];
  let Attributes = [FunctionWithBuiltinPrefix, NoThrow,
                    ConstIgnoringErrnoAndExceptions];
  let Prototype = "T(T)";

  def CosF16F128 : Builtin, F16F128MathTemplate {
    let Spellings = ["__builtin_cos"];
    let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions];
    let Prototype = "T(T)";
  }
```
There is no equivalent in `clang/include/clang/Basic/Builtins.td` for Tan however tan builins are already defined in `<build_dir>/tools/clang/include/clang/Basic/Builtins.inc` Like So:

```
BUILTIN(__builtin_tanf, "ff", "Fne")
LIBBUILTIN(tanf, "ff", "fne", MATH_H, ALL_LANGUAGES)
BUILTIN(__builtin_tan, "dd", "Fne")
LIBBUILTIN(tan, "dd", "fne", MATH_H, ALL_LANGUAGES)
BUILTIN(__builtin_tanl, "LdLd", "Fne")
LIBBUILTIN(tanl, "LdLd", "fne", MATH_H, ALL_LANGUAGES)
BUILTIN(__builtin_tanf128, "LLdLLd", "Fne")
BUILTIN(__builtin_tanhf, "ff", "Fne")
LIBBUILTIN(tanhf, "ff", "fne", MATH_H, ALL_LANGUAGES)
BUILTIN(__builtin_tanh, "dd", "Fne")
LIBBUILTIN(tanh, "dd", "fne", MATH_H, ALL_LANGUAGES)
BUILTIN(__builtin_tanhl, "LdLd", "Fne")
LIBBUILTIN(tanhl, "LdLd", "fne", MATH_H, ALL_LANGUAGES)
BUILTIN(__builtin_tanhf128, "LLdLLd", "Fne")
LIBBUILTIN(__tanpif, "ff", "fne", MATH_H, ALL_LANGUAGES)
LIBBUILTIN(__tanpi, "dd", "fne", MATH_H, ALL_LANGUAGES)
```
Adding the builtin didn't seem right as it would conflict.

Since they already exist maybe I can just use them?  That leads me to reason 2.

Reason 2 to exclude for now the scalar cos\sin calls all have constrained fp  usages as part of code gen in `clang/lib/CodeGen/CGBuiltin.cpp`. This would increase the testing burden for this change. getting a `experimental_constrained_tan` working seems to be  beyond the scope of what I wanted to accomplish with this pr.

examples:
```cpp
  case Builtin::BI__builtin_cos:
  case Builtin::BI__builtin_cosf:
  case Builtin::BI__builtin_cosf16:
  case Builtin::BI__builtin_cosl:
  case Builtin::BI__builtin_cosf128:
    return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E,
                                 Intrinsic::cos,
                                 Intrinsic::experimental_constrained_cos));
  
  case Builtin::BI__builtin_sin:
  case Builtin::BI__builtin_sinf:
  case Builtin::BI__builtin_sinf16:
  case Builtin::BI__builtin_sinl:
  case Builtin::BI__builtin_sinf128:
    return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E,
                                 Intrinsic::sin,
                                 Intrinsic::experimental_constrained_sin));

```

https://github.com/llvm/llvm-project/pull/90276


More information about the llvm-commits mailing list