From b93359ea3fe59ea0c652f5e61ee68231e2fb60c4 Mon Sep 17 00:00:00 2001 From: Albion Fung Date: Tue, 21 Sep 2021 15:46:30 -0500 Subject: [PATCH] [PowerPC] Support for vector bool int128 on vector comparison builtins This patch implements support for the type vector bool int128 for arguments on vector comparison builtins listed below, which would otherwise crash due to ambiguity. The following builtins are added: vec_all_eq (vector bool __int128, vector bool __int128) vec_all_ne (vector bool __int128, vector bool __int128) vec_any_eq (vector bool __int128, vector bool __int128) vec_any_ne (vector bool __int128, vector bool __int128) vec_cmpne(vector bool __int128 a, vector bool __int128 b) vec_cmpeq(vector bool __int128 a, vector bool __int128 b) Differential revision: https://reviews.llvm.org/D110084 --- clang/lib/Headers/altivec.h | 30 ++++++++++++++ clang/test/CodeGen/builtins-ppc-p10vector.c | 44 +++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h index fa9100a2639d..239c93d5b115 100644 --- a/clang/lib/Headers/altivec.h +++ b/clang/lib/Headers/altivec.h @@ -1810,6 +1810,11 @@ vec_cmpeq(vector unsigned __int128 __a, vector unsigned __int128 __b) { 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__ @@ -1887,6 +1892,11 @@ vec_cmpne(vector signed __int128 __a, vector signed __int128 __b) { 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 */ @@ -14870,6 +14880,11 @@ static __inline__ int __ATTRS_o_ai vec_all_eq(vector unsigned __int128 __a, 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 */ @@ -15815,6 +15830,11 @@ static __inline__ int __ATTRS_o_ai vec_all_ne(vector unsigned __int128 __a, 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 */ @@ -16104,6 +16124,11 @@ static __inline__ int __ATTRS_o_ai vec_any_eq(vector unsigned __int128 __a, 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 */ @@ -17079,6 +17104,11 @@ static __inline__ int __ATTRS_o_ai vec_any_ne(vector unsigned __int128 __a, 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 */ diff --git a/clang/test/CodeGen/builtins-ppc-p10vector.c b/clang/test/CodeGen/builtins-ppc-p10vector.c index f97b44550926..8816ae8028eb 100644 --- a/clang/test/CodeGen/builtins-ppc-p10vector.c +++ b/clang/test/CodeGen/builtins-ppc-p10vector.c @@ -19,6 +19,7 @@ vector signed long long vslla, vsllb; 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 @@ vector bool __int128 test_vec_cmpeq_u128(void) { 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 @@ vector bool __int128 test_vec_cmpne_u128(void) { 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, + // 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 @@ int test_vec_any_eq_s128(void) { 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 @@ int test_vec_any_ne_u128(void) { 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 @@ int test_vec_all_eq_u128(void) { 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 @@ int test_vec_all_ne_u128(void) { 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)