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

2024-05-07 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl closed 
https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-07 Thread Justin Bogner via cfe-commits

https://github.com/bogner approved this pull request.


https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-07 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

Okay.  I mostly just want to make sure the plan isn't "land all the intrinsics 
from the RFC, then eventually investigate the constrained intrinsics".

LGTM

https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-07 Thread Farzon Lotfi via cfe-commits

farzonl wrote:

> > I didn't want the current set of changes to go stale.
> 
> How many changes are we talking about here? If it's just the tan() ones, 
> that's fine; it probably makes sense to land constrained-tan separately 
> anyway.

There are 4 for tan. There will be more for the other intrinsics listed in the 
RFC. This one and three backends. There will be a 5th for arm64 after the x86 
changes land.

1. https://github.com/llvm/llvm-project/pull/90276
2. https://github.com/llvm/llvm-project/pull/90277
3. https://github.com/llvm/llvm-project/pull/90278
4. https://github.com/llvm/llvm-project/pull/90503

I'll get started on landing the constrained-tan as part 6 after this change 
makes it.

https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-07 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> I didn't want the current set of changes to go stale.

How many changes are we talking about here?  If it's just the tan() ones, 
that's fine; it probably makes sense to land constrained-tan separately anyway.

https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-06 Thread Farzon Lotfi via cfe-commits

farzonl wrote:

> I'm worried if we add a whole new series of math intrinsics without adding 
> the corresponding constrained intrinsics, it's going to be confusing for 
> anyone trying to understand how math intrinsics work. Why does tan exist, but 
> not constrained tan?
> 
> `tan` is defined basically the same way as `sin` in Builtins.td; the only 
> difference is that instead of `def SinF16F128 : Builtin, 
> F16F128MathTemplate`, there's just `def TanF128 : Builtin {` (so no f16 
> support).

@efriedma-quic Would you be open to me making a new issue to support 
constrained intrinsics. I'll need to spend some time to see what's required to 
support them and I didn't want the current set of changes to go stale. 

https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-05 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I'm worried if we add a whole new series of math intrinsics without adding the 
corresponding constrained intrinsics, it's going to be confusing for anyone 
trying to understand how math intrinsics work.  Why does tan exist, but not 
constrained tan?

`tan` is defined basically the same way as `sin` in Builtins.td; the only 
difference is that instead of `def SinF16F128 : Builtin, F16F128MathTemplate`, 
there's just `def TanF128 : Builtin {` (so no f16 support).

https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-05-03 Thread Farzon Lotfi via cfe-commits

farzonl wrote:

Hi @efriedma-quic @RKSimon when you have time could I get a review? Thank you!

https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-04-29 Thread Farzon Lotfi via cfe-commits

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 
`/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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-04-29 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Are you intentionally skipping implementing changes to __builtin_tan()?

https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-04-29 Thread Helena Kotas via cfe-commits

https://github.com/hekota approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-04-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Farzon Lotfi (farzonl)


Changes

This change is an implementation of #87367's investigation on 
supporting IEEE math operations as intrinsics.
Which was discussed in this RFC:
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294

If you want an overarching view of how this will all connect see:
https://github.com/llvm/llvm-project/pull/90088

Changes:
- `clang/docs/LanguageExtensions.rst` - Document the new elementwise tan 
builtin.
-  `clang/include/clang/Basic/Builtins.td` - Implement the tan builtin.
-  `clang/lib/CodeGen/CGBuiltin.cpp` - invoke the tan intrinsic on uses of the 
builtin
-  `clang/lib/Headers/hlsl/hlsl_intrinsics.h` - Associate the tan builtin with 
the equivalent hlsl apis
-  `clang/lib/Sema/SemaChecking.cpp` - Add generic sema checks as well as HLSL 
specifc sema checks to the tan builtin
-  `llvm/include/llvm/IR/Intrinsics.td` - Create the tan intrinsic
-  `llvm/docs/LangRef.rst` - Document the tan intrinsic

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


15 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+1) 
- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+3-1) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+23) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+2) 
- (modified) clang/test/CodeGen/builtins-elementwise-math.c (+16) 
- (modified) clang/test/CodeGen/strictfp-elementwise-bulitins.cpp (+10) 
- (added) clang/test/CodeGenHLSL/builtins/tan.hlsl (+59) 
- (modified) clang/test/Sema/aarch64-sve-vector-trig-ops.c (+6) 
- (modified) clang/test/Sema/builtins-elementwise-math.c (+21) 
- (modified) clang/test/Sema/riscv-rvv-vector-trig-ops.c (+6) 
- (modified) clang/test/SemaCXX/builtins-elementwise-math.cpp (+7) 
- (modified) clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl (+1) 
- (modified) llvm/docs/LangRef.rst (+37) 
- (modified) llvm/include/llvm/IR/Intrinsics.td (+1) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f18b946efd4bfa..aa61e239d6984c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -656,6 +656,7 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
  T __builtin_elementwise_ceil(T x)   return the smallest integral 
value greater than or equal to xfloating point types
  T __builtin_elementwise_sin(T x)return the sine of x interpreted 
as an angle in radians  floating point types
  T __builtin_elementwise_cos(T x)return the cosine of x 
interpreted as an angle in radiansfloating point types
+ T __builtin_elementwise_tan(T x)return the tangent of x 
interpreted as an angle in radians   floating point types
  T __builtin_elementwise_floor(T x)  return the largest integral value 
less than or equal to xfloating point types
  T __builtin_elementwise_log(T x)return the natural logarithm of x 
   floating point types
  T __builtin_elementwise_log2(T x)   return the base 2 logarithm of x  
   floating point types
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index de721a87b3341d..11982af3fa609b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1326,6 +1326,12 @@ def ElementwiseSqrt : Builtin {
   let Prototype = "void(...)";
 }
 
+def ElementwiseTan : Builtin {
+  let Spellings = ["__builtin_elementwise_tan"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 def ElementwiseTrunc : Builtin {
   let Spellings = ["__builtin_elementwise_trunc"];
   let Attributes = [NoThrow, Const, CustomTypeChecking];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d08ab539148914..f941e93b0ced2b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3821,7 +3821,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_sin:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::sin, "elt.sin"));
-
+  case Builtin::BI__builtin_elementwise_tan:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::tan, "elt.tan"));
   case Builtin::BI__builtin_elementwise_trunc:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::trunc, "elt.trunc"));
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 06409c6fc77417..3390f0962f67d0 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1441,6 +1441,29 @@ float3 sqrt(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_sqrt)
 float4 sqrt(float4);
 
+/

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

2024-04-29 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-x86

Author: Farzon Lotfi (farzonl)


Changes

This change is an implementation of #87367's investigation on 
supporting IEEE math operations as intrinsics.
Which was discussed in this RFC:
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294

If you want an overarching view of how this will all connect see:
https://github.com/llvm/llvm-project/pull/90088

Changes:
- `clang/docs/LanguageExtensions.rst` - Document the new elementwise tan 
builtin.
-  `clang/include/clang/Basic/Builtins.td` - Implement the tan builtin.
-  `clang/lib/CodeGen/CGBuiltin.cpp` - invoke the tan intrinsic on uses of the 
builtin
-  `clang/lib/Headers/hlsl/hlsl_intrinsics.h` - Associate the tan builtin with 
the equivalent hlsl apis
-  `clang/lib/Sema/SemaChecking.cpp` - Add generic sema checks as well as HLSL 
specifc sema checks to the tan builtin
-  `llvm/include/llvm/IR/Intrinsics.td` - Create the tan intrinsic
-  `llvm/docs/LangRef.rst` - Document the tan intrinsic

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


15 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+1) 
- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+3-1) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+23) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+2) 
- (modified) clang/test/CodeGen/builtins-elementwise-math.c (+16) 
- (modified) clang/test/CodeGen/strictfp-elementwise-bulitins.cpp (+10) 
- (added) clang/test/CodeGenHLSL/builtins/tan.hlsl (+59) 
- (modified) clang/test/Sema/aarch64-sve-vector-trig-ops.c (+6) 
- (modified) clang/test/Sema/builtins-elementwise-math.c (+21) 
- (modified) clang/test/Sema/riscv-rvv-vector-trig-ops.c (+6) 
- (modified) clang/test/SemaCXX/builtins-elementwise-math.cpp (+7) 
- (modified) clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl (+1) 
- (modified) llvm/docs/LangRef.rst (+37) 
- (modified) llvm/include/llvm/IR/Intrinsics.td (+1) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f18b946efd4bfa..aa61e239d6984c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -656,6 +656,7 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
  T __builtin_elementwise_ceil(T x)   return the smallest integral 
value greater than or equal to xfloating point types
  T __builtin_elementwise_sin(T x)return the sine of x interpreted 
as an angle in radians  floating point types
  T __builtin_elementwise_cos(T x)return the cosine of x 
interpreted as an angle in radiansfloating point types
+ T __builtin_elementwise_tan(T x)return the tangent of x 
interpreted as an angle in radians   floating point types
  T __builtin_elementwise_floor(T x)  return the largest integral value 
less than or equal to xfloating point types
  T __builtin_elementwise_log(T x)return the natural logarithm of x 
   floating point types
  T __builtin_elementwise_log2(T x)   return the base 2 logarithm of x  
   floating point types
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index de721a87b3341d..11982af3fa609b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1326,6 +1326,12 @@ def ElementwiseSqrt : Builtin {
   let Prototype = "void(...)";
 }
 
+def ElementwiseTan : Builtin {
+  let Spellings = ["__builtin_elementwise_tan"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 def ElementwiseTrunc : Builtin {
   let Spellings = ["__builtin_elementwise_trunc"];
   let Attributes = [NoThrow, Const, CustomTypeChecking];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d08ab539148914..f941e93b0ced2b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3821,7 +3821,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_sin:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::sin, "elt.sin"));
-
+  case Builtin::BI__builtin_elementwise_tan:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::tan, "elt.tan"));
   case Builtin::BI__builtin_elementwise_trunc:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::trunc, "elt.trunc"));
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 06409c6fc77417..3390f0962f67d0 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1441,6 +1441,29 @@ float3 sqrt(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_sqrt)

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

2024-04-29 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl ready_for_review 
https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-04-26 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/90276
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits