[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-06-19 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

2a488b4443a9c0aa0f368aed901676508ced202f 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144802/new/

https://reviews.llvm.org/D144802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-06-19 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff accepted this revision.
sepavloff added a comment.
This revision is now accepted and ready to land.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144802/new/

https://reviews.llvm.org/D144802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-06-19 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:647
+ T __builtin_elementwise_round(T x)  round x to the nearest integer value 
in floating point format,   floating point types
+ rounding halfway cases to even 
(that is, to the nearest value
+ that is an even integer), 
regardless of the current rounding

python3kgae wrote:
> Is this still true for round?
No, I got the two crossed. I also need to add elementwise_rint 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144802/new/

https://reviews.llvm.org/D144802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-06-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 532481.
arsenm marked 2 inline comments as done.
arsenm added a comment.

Fix description and add release notes


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144802/new/

https://reviews.llvm.org/D144802

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -459,6 +459,32 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_round(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_round(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_round();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_round(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_round(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_round(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_round(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+
+  // FIXME: Error should not mention integer
+  _Complex float c1, c2;
+  c1 = __builtin_elementwise_round(c1);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
+
 void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_sin(f);
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -468,6 +468,22 @@
   vf2 = __builtin_elementwise_roundeven(vf1);
 }
 
+void test_builtin_elementwise_round(float f1, float f2, double d1, double d2,
+float4 vf1, float4 vf2) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_round(
+  // CHECK:  [[F1:%.+]] = load float, ptr %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.round.f32(float [[F1]])
+  f2 = __builtin_elementwise_round(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, ptr %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.round.f64(double [[D1]])
+  d2 = __builtin_elementwise_round(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.round.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_round(vf1);
+}
+
 void test_builtin_elementwise_sin(float f1, float f2, double d1, double d2,
   float4 vf1, float4 vf2) {
   // CHECK-LABEL: define void @test_builtin_elementwise_sin(
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2636,6 +2636,7 @@
   case Builtin::BI__builtin_elementwise_log2:
   case Builtin::BI__builtin_elementwise_log10:
   case Builtin::BI__builtin_elementwise_roundeven:
+  case Builtin::BI__builtin_elementwise_round:
   case Builtin::BI__builtin_elementwise_sin:
   case Builtin::BI__builtin_elementwise_trunc:
   case Builtin::BI__builtin_elementwise_canonicalize: {
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3194,6 +3194,9 @@
   case Builtin::BI__builtin_elementwise_roundeven:
 return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::roundeven,
 "elt.roundeven"));
+  case Builtin::BI__builtin_elementwise_round:
+return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::round,
+"elt.round"));
   case Builtin::BI__builtin_elementwise_sin:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::sin, "elt.sin"));
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -687,6 +687,7 @@
 BUILTIN(__builtin_elementwise_log2, "v.", "nct")
 

[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-02-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Yep! this does need a release note.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144802/new/

https://reviews.llvm.org/D144802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-02-27 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 added a comment.

Should the addition of this builtin be mentioned in clang\docs\ReleaseNotes.rst?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144802/new/

https://reviews.llvm.org/D144802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-02-26 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:646
  direction.
+ T __builtin_elementwise_round(T x)  round x to the nearest integer value 
in floating point format,   floating point types
+ rounding halfway cases to even 
(that is, to the nearest value

Lost alignment, need more spaces before the 'round x ...'



Comment at: clang/docs/LanguageExtensions.rst:647
+ T __builtin_elementwise_round(T x)  round x to the nearest integer value 
in floating point format,   floating point types
+ rounding halfway cases to even 
(that is, to the nearest value
+ that is an even integer), 
regardless of the current rounding

Is this still true for round?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144802/new/

https://reviews.llvm.org/D144802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-02-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: aaron.ballman, RKSimon, fhahn, junaire, bob80905, 
python3kgae, erichkeane.
Herald added a subscriber: StephenFan.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.

This would only differ from the existing __builtin_elementwise_roundeven
with floating point exceptions. I don't really care about the distinction
other than futureproofing for strictfp support.


https://reviews.llvm.org/D144802

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -416,6 +416,32 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_round(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_round(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_round();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_round(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_round(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_round(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_round(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+
+  // FIXME: Error should not mention integer
+  _Complex float c1, c2;
+  c1 = __builtin_elementwise_round(c1);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
+
 void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_sin(f);
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -435,6 +435,22 @@
   vf2 = __builtin_elementwise_roundeven(vf1);
 }
 
+void test_builtin_elementwise_round(float f1, float f2, double d1, double d2,
+float4 vf1, float4 vf2) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_round(
+  // CHECK:  [[F1:%.+]] = load float, ptr %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.round.f32(float [[F1]])
+  f2 = __builtin_elementwise_round(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, ptr %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.round.f64(double [[D1]])
+  d2 = __builtin_elementwise_round(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.round.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_round(vf1);
+}
+
 void test_builtin_elementwise_sin(float f1, float f2, double d1, double d2,
   float4 vf1, float4 vf2) {
   // CHECK-LABEL: define void @test_builtin_elementwise_sin(
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2619,6 +2619,7 @@
   case Builtin::BI__builtin_elementwise_log2:
   case Builtin::BI__builtin_elementwise_log10:
   case Builtin::BI__builtin_elementwise_roundeven:
+  case Builtin::BI__builtin_elementwise_round:
   case Builtin::BI__builtin_elementwise_sin:
   case Builtin::BI__builtin_elementwise_trunc:
   case Builtin::BI__builtin_elementwise_canonicalize: {
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3106,6 +3106,9 @@
   case Builtin::BI__builtin_elementwise_roundeven:
 return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::roundeven,
 "elt.roundeven"));
+  case Builtin::BI__builtin_elementwise_round:
+return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::round,
+"elt.round"));
   case Builtin::BI__builtin_elementwise_sin:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::sin, "elt.sin"));
Index: clang/include/clang/Basic/Builtins.def