Sync patch from openeuler/gcc - 20221201 (cherry picked from commit 5487e8942c694fd317f2cbf1662e9eaf33f2f612)
254 lines
10 KiB
Diff
254 lines
10 KiB
Diff
From 96afd5b761a74e9eef40a2e843810c503c669de8 Mon Sep 17 00:00:00 2001
|
|
From: Eric Botcazou <ebotcazou@gcc.gnu.org>
|
|
Date: Thu, 28 May 2020 00:31:15 +0200
|
|
Subject: [PATCH 09/35] [Backport] Add support for __builtin_bswap128
|
|
|
|
Reference: https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=fe7ebef7fe4f9acb79658ed9db0749b07efc3105
|
|
|
|
This patch introduces a new builtin named __builtin_bswap128 on targets
|
|
where TImode is supported, i.e. 64-bit targets only in practice. The
|
|
implementation simply reuses the existing double word path in optab, so
|
|
no routine is added to libgcc (which means that you get two calls to
|
|
_bswapdi2 in the worst case).
|
|
|
|
gcc/ChangeLog:
|
|
|
|
* builtin-types.def (BT_UINT128): New primitive type.
|
|
(BT_FN_UINT128_UINT128): New function type.
|
|
* builtins.def (BUILT_IN_BSWAP128): New GCC builtin.
|
|
* doc/extend.texi (__builtin_bswap128): Document it.
|
|
* builtins.c (expand_builtin): Deal with BUILT_IN_BSWAP128.
|
|
(is_inexpensive_builtin): Likewise.
|
|
* fold-const-call.c (fold_const_call_ss): Likewise.
|
|
* fold-const.c (tree_call_nonnegative_warnv_p): Likewise.
|
|
* tree-ssa-ccp.c (evaluate_stmt): Likewise.
|
|
* tree-vect-stmts.c (vect_get_data_ptr_increment): Likewise.
|
|
(vectorizable_call): Likewise.
|
|
* optabs.c (expand_unop): Always use the double word path for it.
|
|
* tree-core.h (enum tree_index): Add TI_UINT128_TYPE.
|
|
* tree.h (uint128_type_node): New global type.
|
|
* tree.c (build_common_tree_nodes): Build it if TImode is supported.
|
|
|
|
gcc/testsuite/ChangeLog:
|
|
|
|
* gcc.dg/builtin-bswap-10.c: New test.
|
|
* gcc.dg/builtin-bswap-11.c: Likewise.
|
|
* gcc.dg/builtin-bswap-12.c: Likewise.
|
|
* gcc.target/i386/builtin-bswap-5.c: Likewise.
|
|
---
|
|
gcc/builtin-types.def | 4 ++++
|
|
gcc/builtins.c | 2 ++
|
|
gcc/builtins.def | 2 ++
|
|
gcc/doc/extend.texi | 10 ++++++++--
|
|
gcc/fold-const-call.c | 1 +
|
|
gcc/fold-const.c | 2 ++
|
|
gcc/optabs.c | 5 ++++-
|
|
gcc/tree-core.h | 1 +
|
|
gcc/tree-ssa-ccp.c | 1 +
|
|
gcc/tree-vect-stmts.c | 5 +++--
|
|
gcc/tree.c | 2 ++
|
|
gcc/tree.h | 1 +
|
|
12 files changed, 31 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
|
|
index c7aa691b2..c46b1bc5c 100644
|
|
--- a/gcc/builtin-types.def
|
|
+++ b/gcc/builtin-types.def
|
|
@@ -73,6 +73,9 @@ DEF_PRIMITIVE_TYPE (BT_UINT8, unsigned_char_type_node)
|
|
DEF_PRIMITIVE_TYPE (BT_UINT16, uint16_type_node)
|
|
DEF_PRIMITIVE_TYPE (BT_UINT32, uint32_type_node)
|
|
DEF_PRIMITIVE_TYPE (BT_UINT64, uint64_type_node)
|
|
+DEF_PRIMITIVE_TYPE (BT_UINT128, uint128_type_node
|
|
+ ? uint128_type_node
|
|
+ : error_mark_node)
|
|
DEF_PRIMITIVE_TYPE (BT_WORD, (*lang_hooks.types.type_for_mode) (word_mode, 1))
|
|
DEF_PRIMITIVE_TYPE (BT_UNWINDWORD, (*lang_hooks.types.type_for_mode)
|
|
(targetm.unwind_word_mode (), 1))
|
|
@@ -300,6 +303,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_UINT8_FLOAT, BT_UINT8, BT_FLOAT)
|
|
DEF_FUNCTION_TYPE_1 (BT_FN_UINT16_UINT16, BT_UINT16, BT_UINT16)
|
|
DEF_FUNCTION_TYPE_1 (BT_FN_UINT32_UINT32, BT_UINT32, BT_UINT32)
|
|
DEF_FUNCTION_TYPE_1 (BT_FN_UINT64_UINT64, BT_UINT64, BT_UINT64)
|
|
+DEF_FUNCTION_TYPE_1 (BT_FN_UINT128_UINT128, BT_UINT128, BT_UINT128)
|
|
DEF_FUNCTION_TYPE_1 (BT_FN_UINT64_FLOAT, BT_UINT64, BT_FLOAT)
|
|
DEF_FUNCTION_TYPE_1 (BT_FN_BOOL_INT, BT_BOOL, BT_INT)
|
|
DEF_FUNCTION_TYPE_1 (BT_FN_BOOL_PTR, BT_BOOL, BT_PTR)
|
|
diff --git a/gcc/builtins.c b/gcc/builtins.c
|
|
index 10b6fd3bb..1b1c75cc1 100644
|
|
--- a/gcc/builtins.c
|
|
+++ b/gcc/builtins.c
|
|
@@ -8015,6 +8015,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
|
|
case BUILT_IN_BSWAP16:
|
|
case BUILT_IN_BSWAP32:
|
|
case BUILT_IN_BSWAP64:
|
|
+ case BUILT_IN_BSWAP128:
|
|
target = expand_builtin_bswap (target_mode, exp, target, subtarget);
|
|
if (target)
|
|
return target;
|
|
@@ -11732,6 +11733,7 @@ is_inexpensive_builtin (tree decl)
|
|
case BUILT_IN_BSWAP16:
|
|
case BUILT_IN_BSWAP32:
|
|
case BUILT_IN_BSWAP64:
|
|
+ case BUILT_IN_BSWAP128:
|
|
case BUILT_IN_CLZ:
|
|
case BUILT_IN_CLZIMAX:
|
|
case BUILT_IN_CLZL:
|
|
diff --git a/gcc/builtins.def b/gcc/builtins.def
|
|
index fa8b0641a..ee67ac15d 100644
|
|
--- a/gcc/builtins.def
|
|
+++ b/gcc/builtins.def
|
|
@@ -834,6 +834,8 @@ DEF_GCC_BUILTIN (BUILT_IN_APPLY_ARGS, "apply_args", BT_FN_PTR_VAR, ATTR_L
|
|
DEF_GCC_BUILTIN (BUILT_IN_BSWAP16, "bswap16", BT_FN_UINT16_UINT16, ATTR_CONST_NOTHROW_LEAF_LIST)
|
|
DEF_GCC_BUILTIN (BUILT_IN_BSWAP32, "bswap32", BT_FN_UINT32_UINT32, ATTR_CONST_NOTHROW_LEAF_LIST)
|
|
DEF_GCC_BUILTIN (BUILT_IN_BSWAP64, "bswap64", BT_FN_UINT64_UINT64, ATTR_CONST_NOTHROW_LEAF_LIST)
|
|
+DEF_GCC_BUILTIN (BUILT_IN_BSWAP128, "bswap128", BT_FN_UINT128_UINT128, ATTR_CONST_NOTHROW_LEAF_LIST)
|
|
+
|
|
DEF_EXT_LIB_BUILTIN (BUILT_IN_CLEAR_CACHE, "__clear_cache", BT_FN_VOID_PTR_PTR, ATTR_NOTHROW_LEAF_LIST)
|
|
/* [trans-mem]: Adjust BUILT_IN_TM_CALLOC if BUILT_IN_CALLOC is changed. */
|
|
DEF_LIB_BUILTIN (BUILT_IN_CALLOC, "calloc", BT_FN_PTR_SIZE_SIZE, ATTR_MALLOC_WARN_UNUSED_RESULT_SIZE_1_2_NOTHROW_LEAF_LIST)
|
|
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
|
|
index 9c7345959..a7bd772de 100644
|
|
--- a/gcc/doc/extend.texi
|
|
+++ b/gcc/doc/extend.texi
|
|
@@ -13727,14 +13727,20 @@ exactly 8 bits.
|
|
|
|
@deftypefn {Built-in Function} uint32_t __builtin_bswap32 (uint32_t x)
|
|
Similar to @code{__builtin_bswap16}, except the argument and return types
|
|
-are 32 bit.
|
|
+are 32-bit.
|
|
@end deftypefn
|
|
|
|
@deftypefn {Built-in Function} uint64_t __builtin_bswap64 (uint64_t x)
|
|
Similar to @code{__builtin_bswap32}, except the argument and return types
|
|
-are 64 bit.
|
|
+are 64-bit.
|
|
@end deftypefn
|
|
|
|
+@deftypefn {Built-in Function} uint128_t __builtin_bswap128 (uint128_t x)
|
|
+Similar to @code{__builtin_bswap64}, except the argument and return types
|
|
+are 128-bit. Only supported on targets when 128-bit types are supported.
|
|
+@end deftypefn
|
|
+
|
|
+
|
|
@deftypefn {Built-in Function} Pmode __builtin_extend_pointer (void * x)
|
|
On targets where the user visible pointer size is smaller than the size
|
|
of an actual hardware address this function returns the extended user
|
|
diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c
|
|
index 6150d7ada..da01759d9 100644
|
|
--- a/gcc/fold-const-call.c
|
|
+++ b/gcc/fold-const-call.c
|
|
@@ -1032,6 +1032,7 @@ fold_const_call_ss (wide_int *result, combined_fn fn, const wide_int_ref &arg,
|
|
case CFN_BUILT_IN_BSWAP16:
|
|
case CFN_BUILT_IN_BSWAP32:
|
|
case CFN_BUILT_IN_BSWAP64:
|
|
+ case CFN_BUILT_IN_BSWAP128:
|
|
*result = wide_int::from (arg, precision, TYPE_SIGN (arg_type)).bswap ();
|
|
return true;
|
|
|
|
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
|
|
index 6e635382f..78227a83d 100644
|
|
--- a/gcc/fold-const.c
|
|
+++ b/gcc/fold-const.c
|
|
@@ -13889,8 +13889,10 @@ tree_call_nonnegative_warnv_p (tree type, combined_fn fn, tree arg0, tree arg1,
|
|
CASE_CFN_POPCOUNT:
|
|
CASE_CFN_CLZ:
|
|
CASE_CFN_CLRSB:
|
|
+ case CFN_BUILT_IN_BSWAP16:
|
|
case CFN_BUILT_IN_BSWAP32:
|
|
case CFN_BUILT_IN_BSWAP64:
|
|
+ case CFN_BUILT_IN_BSWAP128:
|
|
/* Always true. */
|
|
return true;
|
|
|
|
diff --git a/gcc/optabs.c b/gcc/optabs.c
|
|
index 049a18ceb..c3751fdf7 100644
|
|
--- a/gcc/optabs.c
|
|
+++ b/gcc/optabs.c
|
|
@@ -2896,8 +2896,11 @@ expand_unop (machine_mode mode, optab unoptab, rtx op0, rtx target,
|
|
if (temp)
|
|
return temp;
|
|
|
|
+ /* We do not provide a 128-bit bswap in libgcc so force the use of
|
|
+ a double bswap for 64-bit targets. */
|
|
if (GET_MODE_SIZE (int_mode) == 2 * UNITS_PER_WORD
|
|
- && optab_handler (unoptab, word_mode) != CODE_FOR_nothing)
|
|
+ && (UNITS_PER_WORD == 64
|
|
+ || optab_handler (unoptab, word_mode) != CODE_FOR_nothing))
|
|
{
|
|
temp = expand_doubleword_bswap (mode, op0, target);
|
|
if (temp)
|
|
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
|
|
index eb01c2434..058e046aa 100644
|
|
--- a/gcc/tree-core.h
|
|
+++ b/gcc/tree-core.h
|
|
@@ -600,6 +600,7 @@ enum tree_index {
|
|
TI_UINT16_TYPE,
|
|
TI_UINT32_TYPE,
|
|
TI_UINT64_TYPE,
|
|
+ TI_UINT128_TYPE,
|
|
|
|
TI_VOID,
|
|
|
|
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
|
|
index 952fd9cd4..dcdf10369 100644
|
|
--- a/gcc/tree-ssa-ccp.c
|
|
+++ b/gcc/tree-ssa-ccp.c
|
|
@@ -2005,6 +2005,7 @@ evaluate_stmt (gimple *stmt)
|
|
case BUILT_IN_BSWAP16:
|
|
case BUILT_IN_BSWAP32:
|
|
case BUILT_IN_BSWAP64:
|
|
+ case BUILT_IN_BSWAP128:
|
|
val = get_value_for_expr (gimple_call_arg (stmt, 0), true);
|
|
if (val.lattice_val == UNDEFINED)
|
|
break;
|
|
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
|
|
index b872cfc8d..4636b7ba2 100644
|
|
--- a/gcc/tree-vect-stmts.c
|
|
+++ b/gcc/tree-vect-stmts.c
|
|
@@ -3085,7 +3085,7 @@ vect_get_data_ptr_increment (dr_vec_info *dr_info, tree aggr_type,
|
|
return iv_step;
|
|
}
|
|
|
|
-/* Check and perform vectorization of BUILT_IN_BSWAP{16,32,64}. */
|
|
+/* Check and perform vectorization of BUILT_IN_BSWAP{16,32,64,128}. */
|
|
|
|
static bool
|
|
vectorizable_bswap (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
|
|
@@ -3454,7 +3454,8 @@ vectorizable_call (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
|
|
else if (modifier == NONE
|
|
&& (gimple_call_builtin_p (stmt, BUILT_IN_BSWAP16)
|
|
|| gimple_call_builtin_p (stmt, BUILT_IN_BSWAP32)
|
|
- || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP64)))
|
|
+ || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP64)
|
|
+ || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP128)))
|
|
return vectorizable_bswap (stmt_info, gsi, vec_stmt, slp_node,
|
|
vectype_in, cost_vec);
|
|
else
|
|
diff --git a/gcc/tree.c b/gcc/tree.c
|
|
index 84a440b35..3e6647ae0 100644
|
|
--- a/gcc/tree.c
|
|
+++ b/gcc/tree.c
|
|
@@ -10394,6 +10394,8 @@ build_common_tree_nodes (bool signed_char)
|
|
uint16_type_node = make_or_reuse_type (16, 1);
|
|
uint32_type_node = make_or_reuse_type (32, 1);
|
|
uint64_type_node = make_or_reuse_type (64, 1);
|
|
+ if (targetm.scalar_mode_supported_p (TImode))
|
|
+ uint128_type_node = make_or_reuse_type (128, 1);
|
|
|
|
/* Decimal float types. */
|
|
if (targetm.decimal_float_supported_p ())
|
|
diff --git a/gcc/tree.h b/gcc/tree.h
|
|
index 328a2d5d2..bddc6e528 100644
|
|
--- a/gcc/tree.h
|
|
+++ b/gcc/tree.h
|
|
@@ -4035,6 +4035,7 @@ tree_strip_any_location_wrapper (tree exp)
|
|
#define uint16_type_node global_trees[TI_UINT16_TYPE]
|
|
#define uint32_type_node global_trees[TI_UINT32_TYPE]
|
|
#define uint64_type_node global_trees[TI_UINT64_TYPE]
|
|
+#define uint128_type_node global_trees[TI_UINT128_TYPE]
|
|
|
|
#define void_node global_trees[TI_VOID]
|
|
|
|
--
|
|
2.27.0.windows.1
|
|
|