[PATCH] D101130: [PowerPC] Provide XL-compatible builtins in altivec.h

2021-04-23 Thread Nemanja Ivanovic via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG19b29b1ed1ba: [PowerPC] Provide XL-compatible builtins in 
altivec.h (authored by nemanjai).

Changed prior to commit:
  https://reviews.llvm.org/D101130?vs=339859=340148#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101130

Files:
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-xlcompat.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat.c
@@ -0,0 +1,41 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -triple powerpc64-unknown-unknown -emit-llvm %s -o - \
+// RUN:   -D__XL_COMPAT_ALTIVEC__ -target-cpu pwr7 | FileCheck %s
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -triple powerpc64le-unknown-unknown -emit-llvm %s -o - \
+// RUN:   -D__XL_COMPAT_ALTIVEC__ -target-cpu pwr8 | FileCheck %s
+#include 
+vector double vd = { 3.4e22, 1.8e-3 };
+vector signed long long vsll = { -12345678999ll, 12345678999 };
+vector unsigned long long vull = { 11547229456923630743llu, 18014402265226391llu };
+vector float res_vf;
+vector signed int res_vsi;
+vector unsigned int res_vui;
+
+void test() {
+// CHECK-LABEL: @test(
+// CHECK-NEXT:  entry:
+// CHECK-LE-LABEL: @test(
+// CHECK-LE-NEXT:  entry:
+
+  res_vf = vec_ctf(vsll, 4);
+// CHECK: [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
+// CHECK-NEXT:[[TMP1:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvsxdsp(<2 x i64> [[TMP0]])
+// CHECK-NEXT:fmul <4 x float> [[TMP1]], 
+
+  res_vf = vec_ctf(vull, 4);
+// CHECK: [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
+// CHECK-NEXT:[[TMP3:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvuxdsp(<2 x i64> [[TMP2]])
+// CHECK-NEXT:fmul <4 x float> [[TMP3]], 
+
+  res_vsi = vec_cts(vd, 4);
+// CHECK: [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// CHECK-NEXT:fmul <2 x double> [[TMP4]], 
+// CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpsxws(<2 x double>
+
+  res_vui = vec_ctu(vd, 4);
+// CHECK: [[TMP8:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// CHECK-NEXT:fmul <2 x double> [[TMP8]], 
+// CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
+}
Index: clang/lib/Headers/altivec.h
===
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -3055,6 +3055,23 @@
 /* vec_ctf */
 
 #ifdef __VSX__
+// There are some functions that have different signatures with the XL compiler
+// from those in Clang/GCC and documented in the PVIPR. This macro ensures that
+// the XL-compatible signatures are used for those functions.
+#ifdef __XL_COMPAT_ALTIVEC__
+#define vec_ctf(__a, __b)  \
+  _Generic((__a), vector int   \
+   : (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)),  \
+ vector unsigned int   \
+   : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
+   (__b)), \
+ vector unsigned long long \
+   : (__builtin_vsx_xvcvuxdsp((vector unsigned long long)(__a)) *  \
+  (vector float)(vector unsigned)((0x7f - (__b)) << 23)),  \
+ vector signed long long   \
+   : (__builtin_vsx_xvcvsxdsp((vector signed long long)(__a)) *\
+  (vector float)(vector unsigned)((0x7f - (__b)) << 23)))
+#else // __XL_COMPAT_ALTIVEC__
 #define vec_ctf(__a, __b)  \
   _Generic((__a), vector int   \
: (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)),  \
@@ -3071,6 +3088,7 @@
   vector double) * \
   (vector double)(vector unsigned long long)((0x3ffULL - (__b))\
  << 52)))
+#endif // __XL_COMPAT_ALTIVEC__
 #else
 #define vec_ctf(__a, __b)  \
   _Generic((__a), vector int   \
@@ -3113,6 +3131,19 @@
 /* vec_cts */
 
 #ifdef __VSX__
+#ifdef __XL_COMPAT_ALTIVEC__
+#define vec_cts(__a, __b)  \
+  _Generic((__a), vector float \
+ 

[PATCH] D101130: [PowerPC] Provide XL-compatible builtins in altivec.h

2021-04-23 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added inline comments.



Comment at: clang/lib/Headers/altivec.h:3055
 
+#ifdef __XL_COMPAT_ALTIVEC__
+/* vec_ctf */

jsji wrote:
> This only affects __VSX__ version right? If so, can we move `#ifdef 
> __XL_COMPAT_ALTIVEC__` into `#ifdef __VSX__`?
> Or even better only into the part of affected types, eg: vector unsinged long 
> long?
Sure, I'll make the non-vsx version unconditional on `__XL_COMPAT_ALTIVEC__`.



Comment at: clang/lib/Headers/altivec.h:3065
+   (__b)), 
\
+ vector unsigned long long 
\
+   : (__builtin_vsx_xvcvuxdsp((vector unsigned long long)(__a)) *  
\

jsji wrote:
> jsji wrote:
> > Can we also add comments about what is the major difference with and 
> > without `__XL_COMPAT_ALTIVEC__` , for long term maintenance?
> > Can we also add comments about what is the major difference with and 
> > without `__XL_COMPAT_ALTIVEC__` , for long term maintenance?
> 
> I know they are in commit message, but I think comments in source code would 
> be more helpful than in commit message. Thanks.
Will do.



Comment at: clang/test/CodeGen/builtins-ppc-xlcompat.c:2
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+  // RUN:   -triple powerpc64-unknown-unknown -emit-llvm %s -o - \

cebowleratibm wrote:
> Suggest adding an explicit -mcpu.
I'm not sure that works with `cc1`. It would probably neeed to be something 
like `-target-cpu`.



Comment at: clang/test/CodeGen/builtins-ppc-xlcompat.c:6
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+  // RUN:   -triple powerpc64le-unknown-unknown -emit-llvm %s -o - \
+// RUN:   -D__XL_COMPAT_ALTIVEC__ | FileCheck %s

bmahjour wrote:
> [nit] remove extra space
Oops, I'll fix it.



Comment at: clang/test/CodeGen/builtins-ppc-xlcompat.c:8
+// RUN:   -D__XL_COMPAT_ALTIVEC__ | FileCheck %s
+#include 
+vector double vd = { 3.4e22, 1.8e-3 };

jsji wrote:
> Can we add a RUN line to test that novsx are not affected?
I don't think this is useful as that would be a duplicate of the tests in 
`builtins-ppc-vsx.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101130

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


[PATCH] D101130: [PowerPC] Provide XL-compatible builtins in altivec.h

2021-04-23 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added inline comments.



Comment at: clang/lib/Headers/altivec.h:3065
+   (__b)), 
\
+ vector unsigned long long 
\
+   : (__builtin_vsx_xvcvuxdsp((vector unsigned long long)(__a)) *  
\

jsji wrote:
> Can we also add comments about what is the major difference with and without 
> `__XL_COMPAT_ALTIVEC__` , for long term maintenance?
> Can we also add comments about what is the major difference with and without 
> `__XL_COMPAT_ALTIVEC__` , for long term maintenance?

I know they are in commit message, but I think comments in source code would be 
more helpful than in commit message. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101130

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


[PATCH] D101130: [PowerPC] Provide XL-compatible builtins in altivec.h

2021-04-23 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added inline comments.



Comment at: clang/lib/Headers/altivec.h:3055
 
+#ifdef __XL_COMPAT_ALTIVEC__
+/* vec_ctf */

This only affects __VSX__ version right? If so, can we move `#ifdef 
__XL_COMPAT_ALTIVEC__` into `#ifdef __VSX__`?
Or even better only into the part of affected types, eg: vector unsinged long 
long?



Comment at: clang/lib/Headers/altivec.h:3065
+   (__b)), 
\
+ vector unsigned long long 
\
+   : (__builtin_vsx_xvcvuxdsp((vector unsigned long long)(__a)) *  
\

Can we also add comments about what is the major difference with and without 
`__XL_COMPAT_ALTIVEC__` , for long term maintenance?



Comment at: clang/test/CodeGen/builtins-ppc-xlcompat.c:8
+// RUN:   -D__XL_COMPAT_ALTIVEC__ | FileCheck %s
+#include 
+vector double vd = { 3.4e22, 1.8e-3 };

Can we add a RUN line to test that novsx are not affected?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101130

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


[PATCH] D101130: [PowerPC] Provide XL-compatible builtins in altivec.h

2021-04-23 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added a comment.

LGTM




Comment at: clang/test/CodeGen/builtins-ppc-xlcompat.c:6
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+  // RUN:   -triple powerpc64le-unknown-unknown -emit-llvm %s -o - \
+// RUN:   -D__XL_COMPAT_ALTIVEC__ | FileCheck %s

[nit] remove extra space


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101130

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


[PATCH] D101130: [PowerPC] Provide XL-compatible builtins in altivec.h

2021-04-23 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm accepted this revision.
cebowleratibm added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/CodeGen/builtins-ppc-xlcompat.c:2
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+  // RUN:   -triple powerpc64-unknown-unknown -emit-llvm %s -o - \

Suggest adding an explicit -mcpu.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101130

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


[PATCH] D101130: [PowerPC] Provide XL-compatible builtins in altivec.h

2021-04-22 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai created this revision.
nemanjai added reviewers: cebowleratibm, hubert.reinterpretcast, bmahjour, 
PowerPC.
Herald added subscribers: shchenz, kbarton.
nemanjai requested review of this revision.
Herald added a project: clang.

There are some interfaces in altivec.h that are not compatible between Clang 
and XL (although Clang is compatible with GCC). Currently, we have found 3 but 
there may be others.

Clang/GCC signatures:

  vector double vec_ctf(vector signed long long)
  vector double vec_ctf(vector unsigned long long)
  vector signed long long vec_cts(vector double)
  vector unsigned long long vec_ctu(vector double)

XL signatures:

  vector float vec_ctf(vector signed long long)
  vector float vec_ctf(vector unsigned long long)
  vector signed int vec_cts(vector double)
  vector unsigned int vec_ctu(vector double)

This patch provides the XL behaviour under the `__XL_COMPAT_ALTIVEC__` macro 
for users that rely on XL behaviour.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101130

Files:
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-xlcompat.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat.c
@@ -0,0 +1,41 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+  // RUN:   -triple powerpc64-unknown-unknown -emit-llvm %s -o - \
+// RUN:   -D__XL_COMPAT_ALTIVEC__ | FileCheck %s
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+  // RUN:   -triple powerpc64le-unknown-unknown -emit-llvm %s -o - \
+// RUN:   -D__XL_COMPAT_ALTIVEC__ | FileCheck %s
+#include 
+vector double vd = { 3.4e22, 1.8e-3 };
+vector signed long long vsll = { -12345678999ll, 12345678999 };
+vector unsigned long long vull = { 11547229456923630743llu, 18014402265226391llu };
+vector float res_vf;
+vector signed int res_vsi;
+vector unsigned int res_vui;
+
+void test() {
+// CHECK-LABEL: @test(
+// CHECK-NEXT:  entry:
+// CHECK-LE-LABEL: @test(
+// CHECK-LE-NEXT:  entry:
+
+  res_vf = vec_ctf(vsll, 4);
+// CHECK: [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
+// CHECK-NEXT:[[TMP1:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvsxdsp(<2 x i64> [[TMP0]])
+// CHECK-NEXT:fmul <4 x float> [[TMP1]], 
+
+  res_vf = vec_ctf(vull, 4);
+// CHECK: [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
+// CHECK-NEXT:[[TMP3:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvuxdsp(<2 x i64> [[TMP2]])
+// CHECK-NEXT:fmul <4 x float> [[TMP3]], 
+
+  res_vsi = vec_cts(vd, 4);
+// CHECK: [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// CHECK-NEXT:fmul <2 x double> [[TMP4]], 
+// CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpsxws(<2 x double>
+
+  res_vui = vec_ctu(vd, 4);
+// CHECK: [[TMP8:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// CHECK-NEXT:fmul <2 x double> [[TMP8]], 
+// CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
+}
Index: clang/lib/Headers/altivec.h
===
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -3052,6 +3052,31 @@
 }
 #endif
 
+#ifdef __XL_COMPAT_ALTIVEC__
+/* vec_ctf */
+
+#ifdef __VSX__
+#define vec_ctf(__a, __b)  \
+  _Generic((__a), vector int   \
+   : (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)),  \
+ vector unsigned int   \
+   : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
+   (__b)), \
+ vector unsigned long long \
+   : (__builtin_vsx_xvcvuxdsp((vector unsigned long long)(__a)) *  \
+  (vector float)(vector unsigned)((0x7f - (__b)) << 23)),  \
+ vector signed long long   \
+   : (__builtin_vsx_xvcvsxdsp((vector signed long long)(__a)) *\
+  (vector float)(vector unsigned)((0x7f - (__b)) << 23)))
+#else
+#define vec_ctf(__a, __b)  \
+  _Generic((__a), vector int   \
+   : (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)),  \
+ vector unsigned int   \
+   : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
+   (__b)))
+#endif
+#else // __XL_COMPAT_ALTIVEC__
 /* vec_ctf */
 
 #ifdef __VSX__
@@ -3079,6 +3104,7 @@
: (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \