Conanap created this revision.
Conanap added reviewers: PowerPC, saghir, nemanjai.
Conanap added projects: PowerPC, clang, LLVM.
Herald added a subscriber: kbarton.
Conanap requested review of this revision.

This patch implements support for the type `vector bool int128`
for arguments on vector comparison builtins, which would
otherwise crash due to ambiguity.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110084

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

Index: clang/test/CodeGen/builtins-ppc-p10vector.c
===================================================================
--- clang/test/CodeGen/builtins-ppc-p10vector.c
+++ clang/test/CodeGen/builtins-ppc-p10vector.c
@@ -19,6 +19,7 @@
 vector unsigned long long vulla, vullb, vullc;
 vector signed __int128 vsi128a, vsi128b, vsi128c;
 vector unsigned __int128 vui128a, vui128b, vui128c;
+vector bool __int128 vbi128a, vbi128b;
 vector float vfa, vfb;
 vector double vda, vdb;
 float fa;
@@ -1637,6 +1638,13 @@
   return vec_cmpeq(vui128a, vui128b);
 }
 
+vector bool __int128 test_vec_cmpeq_bool_int128(void) {
+  // CHECK-LABEL: @test_vec_cmpeq_bool_int128(
+  // CHECK: call <1 x i128> @llvm.ppc.altivec.vcmpequq(<1 x i128>
+  // CHECK-NEXT: ret <1 x i128>
+  return vec_cmpeq(vbi128a, vbi128b);
+}
+
 vector bool __int128 test_vec_cmpne_s128(void) {
   // CHECK-LABEL: @test_vec_cmpne_s128(
   // CHECK: call <1 x i128> @llvm.ppc.altivec.vcmpequq(<1 x i128>
@@ -1653,6 +1661,14 @@
   return vec_cmpne(vui128a, vui128b);
 }
 
+vector bool __int128 test_vec_cmpne_bool_int128(void) {
+  // CHECK-LABEL: @test_vec_cmpne_bool_int128(
+  // CHECK: call <1 x i128> @llvm.ppc.altivec.vcmpequq(<1 x i128>
+  // CHECK-NEXT: %neg.i = xor <1 x i128> %4, <i128 -1>
+  // CHECK-NEXT: ret <1 x i128>
+  return vec_cmpne(vbi128a, vbi128b);
+}
+
 vector bool __int128 test_vec_cmpgt_s128(void) {
   // CHECK-LABEL: @test_vec_cmpgt_s128(
   // CHECK: call <1 x i128> @llvm.ppc.altivec.vcmpgtsq(<1 x i128>
@@ -1727,6 +1743,13 @@
   return vec_any_eq(vsi128a, vsi128b);
 }
 
+int test_vec_any_eq_bool_int128(void) {
+  // CHECK-LABEL: @test_vec_any_eq_bool_int128(
+  // CHECK: call i32 @llvm.ppc.altivec.vcmpequq.p(i32 1, <1 x i128> %2, <1 x i128> %3)
+  // CHECK-NEXT: ret i32
+  return vec_any_eq(vbi128a, vbi128b);
+}
+
 int test_vec_any_ne_s128(void) {
   // CHECK-LABEL: @test_vec_any_ne_s128(
   // CHECK: call i32 @llvm.ppc.altivec.vcmpequq.p(i32 3, <1 x i128> %2, <1 x i128> %3)
@@ -1741,6 +1764,13 @@
   return vec_any_ne(vui128a, vui128b);
 }
 
+int test_vec_any_ne_bool_int128(void) {
+  // CHECK-LABEL: @test_vec_any_ne_bool_int128(
+  // CHECK: call i32 @llvm.ppc.altivec.vcmpequq.p(i32 3, <1 x i128> %2, <1 x i128> %3)
+  // CHECK-NEXT: ret i32
+  return vec_any_ne(vbi128a, vbi128b);
+}
+
 int test_vec_any_lt_s128(void) {
   // CHECK-LABEL: @test_vec_any_lt_s128(
   // CHECK: call i32 @llvm.ppc.altivec.vcmpgtsq.p(i32 1, <1 x i128> %2, <1 x i128> %3)
@@ -1811,6 +1841,13 @@
   return vec_all_eq(vui128a, vui128b);
 }
 
+int test_vec_all_eq_bool_int128(void) {
+  // CHECK-LABEL: @test_vec_all_eq_bool_int128
+  // CHECK: call i32 @llvm.ppc.altivec.vcmpequq.p(i32 2, <1 x i128> %2, <1 x i128> %3)
+  // CHECK-NEXT: ret i32
+  return vec_all_eq(vbi128a, vbi128b);
+}
+
 int test_vec_all_ne_s128(void) {
   // CHECK-LABEL: @test_vec_all_ne_s128(
   // CHECK: call i32 @llvm.ppc.altivec.vcmpequq.p(i32 0, <1 x i128> %2, <1 x i128> %3)
@@ -1825,6 +1862,13 @@
   return vec_all_ne(vui128a, vui128b);
 }
 
+int test_vec_all_ne_bool_int128(void) {
+  // CHECK-LABEL: test_vec_all_ne_bool_int128
+  // CHECK: call i32 @llvm.ppc.altivec.vcmpequq.p(i32 0, <1 x i128> %2, <1 x i128> %3)
+  // CHECK-NEXT: ret i32
+  return vec_all_ne(vbi128a, vbi128b);
+}
+
 int test_vec_all_lt_s128(void) {
   // CHECK-LABEL: @test_vec_all_lt_s128(
   // CHECK: call i32 @llvm.ppc.altivec.vcmpgtsq.p(i32 2, <1 x i128> %2, <1 x i128> %3)
Index: clang/lib/Headers/altivec.h
===================================================================
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -1805,6 +1805,11 @@
   return (vector bool __int128)__builtin_altivec_vcmpequq(
       (vector bool __int128)__a, (vector bool __int128)__b);
 }
+
+static __inline__ vector bool __int128 __ATTRS_o_ai
+vec_cmpeq(vector bool __int128 __a, vector bool  __int128 __b) {
+  return (vector bool __int128)__builtin_altivec_vcmpequq(__a, __b);
+}
 #endif
 
 #ifdef __POWER9_VECTOR__
@@ -1882,6 +1887,11 @@
   return (vector bool __int128) ~(__builtin_altivec_vcmpequq(
       (vector bool __int128)__a, (vector bool __int128)__b));
 }
+
+static __inline__ vector bool __int128 __ATTRS_o_ai
+vec_cmpne(vector bool __int128 __a, vector bool __int128 __b) {
+  return (vector bool __int128) ~(__builtin_altivec_vcmpequq(__a, __b));
+}
 #endif
 
 /* vec_cmpnez */
@@ -14865,6 +14875,11 @@
                                               vector unsigned __int128 __b) {
   return __builtin_altivec_vcmpequq_p(__CR6_LT, __a, __b);
 }
+
+static __inline__ int __ATTRS_o_ai vec_all_eq(vector bool __int128 __a,
+                                              vector bool __int128 __b) {
+  return __builtin_altivec_vcmpequq_p(__CR6_LT, __a, __b);
+}
 #endif
 
 /* vec_all_ge */
@@ -15822,6 +15837,11 @@
                                               vector unsigned __int128 __b) {
   return __builtin_altivec_vcmpequq_p(__CR6_EQ, __a, __b);
 }
+
+static __inline__ int __ATTRS_o_ai vec_all_ne(vector bool __int128 __a,
+                                              vector bool __int128 __b) {
+  return __builtin_altivec_vcmpequq_p(__CR6_EQ, __a, __b);
+}
 #endif
 
 /* vec_all_nge */
@@ -16111,6 +16131,11 @@
                                               vector unsigned __int128 __b) {
   return __builtin_altivec_vcmpequq_p(__CR6_EQ_REV, __a, __b);
 }
+
+static __inline__ int __ATTRS_o_ai vec_any_eq(vector bool __int128 __a,
+                                              vector bool __int128 __b) {
+  return __builtin_altivec_vcmpequq_p(__CR6_EQ_REV, __a, __b);
+}
 #endif
 
 /* vec_any_ge */
@@ -17090,6 +17115,11 @@
                                               vector unsigned __int128 __b) {
   return __builtin_altivec_vcmpequq_p(__CR6_LT_REV, __a, __b);
 }
+
+static __inline__ int __ATTRS_o_ai vec_any_ne(vector bool __int128 __a,
+                                              vector bool __int128 __b) {
+  return __builtin_altivec_vcmpequq_p(__CR6_LT_REV, __a, __b);
+}
 #endif
 
 /* vec_any_nge */
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to