diff options
author | Robin Dapp <rdapp@ventanamicro.com> | 2023-12-01 09:30:17 +0100 |
---|---|---|
committer | Robin Dapp <rdapp@ventanamicro.com> | 2023-12-04 16:23:56 +0100 |
commit | 4ae5a7336ac8e1ba57ee1e885b5b76ed86cdbfd5 (patch) | |
tree | aa2060ef13c3123e85aefb8591e4cc1b7756fb45 | |
parent | 0c2ea80a4ffbddc0bc29f5badaf2ae43e59483b2 (diff) | |
download | gcc-4ae5a7336ac8e1ba57ee1e885b5b76ed86cdbfd5.zip gcc-4ae5a7336ac8e1ba57ee1e885b5b76ed86cdbfd5.tar.gz gcc-4ae5a7336ac8e1ba57ee1e885b5b76ed86cdbfd5.tar.bz2 |
RISC-V: Rename and unify stringop strategy handling.
In preparation for the vectorized strlen and strcmp support this NFC
patch unifies the stringop strategy handling a bit. The "auto"
strategy now is a combination of scalar and vector and an expander
should try the strategies in their preferred order.
For the block_move expander this patch does just that.
gcc/ChangeLog:
* config/riscv/riscv-opts.h (enum riscv_stringop_strategy_enum):
Rename...
(enum stringop_strategy_enum): ... to this.
* config/riscv/riscv-string.cc (riscv_expand_block_move): New
wrapper expander handling the strategies and delegation.
(riscv_expand_block_move_scalar): Rename function and make
static.
(expand_block_move): Remove strategy handling.
* config/riscv/riscv.md: Call expander wrapper.
* config/riscv/riscv.opt: Rename.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/base/cpymem-strategy-1.c: Change to
-mstringop-strategy.
* gcc.target/riscv/rvv/base/cpymem-strategy-2.c: Ditto.
* gcc.target/riscv/rvv/base/cpymem-strategy-3.c: Ditto.
* gcc.target/riscv/rvv/base/cpymem-strategy-4.c: Ditto.
* gcc.target/riscv/rvv/base/cpymem-strategy-5.c: Ditto.
-rw-r--r-- | gcc/config/riscv/riscv-opts.h | 18 | ||||
-rw-r--r-- | gcc/config/riscv/riscv-string.cc | 92 | ||||
-rw-r--r-- | gcc/config/riscv/riscv.md | 4 | ||||
-rw-r--r-- | gcc/config/riscv/riscv.opt | 18 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-2.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-3.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-4.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-5.c | 2 |
9 files changed, 78 insertions, 64 deletions
diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index e6e55ad..30efebb 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -104,15 +104,15 @@ enum riscv_entity }; /* RISC-V stringop strategy. */ -enum riscv_stringop_strategy_enum { - /* Use scalar or vector instructions. */ - USE_AUTO, - /* Always use a library call. */ - USE_LIBCALL, - /* Only use scalar instructions. */ - USE_SCALAR, - /* Only use vector instructions. */ - USE_VECTOR +enum stringop_strategy_enum { + /* No expansion. */ + STRATEGY_LIBCALL = 1, + /* Use scalar expansion if possible. */ + STRATEGY_SCALAR = 2, + /* Only vector expansion if possible. */ + STRATEGY_VECTOR = 4, + /* Use any. */ + STRATEGY_AUTO = STRATEGY_SCALAR | STRATEGY_VECTOR }; #define TARGET_ZICOND_LIKE (TARGET_ZICOND || (TARGET_XVENTANACONDOPS && TARGET_64BIT)) diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc index 80e3b59..f3a4d3d 100644 --- a/gcc/config/riscv/riscv-string.cc +++ b/gcc/config/riscv/riscv-string.cc @@ -707,51 +707,68 @@ riscv_block_move_loop (rtx dest, rtx src, unsigned HOST_WIDE_INT length, /* Expand a cpymemsi instruction, which copies LENGTH bytes from memory reference SRC to memory reference DEST. */ -bool -riscv_expand_block_move (rtx dest, rtx src, rtx length) +static bool +riscv_expand_block_move_scalar (rtx dest, rtx src, rtx length) { - if (riscv_memcpy_strategy == USE_LIBCALL - || riscv_memcpy_strategy == USE_VECTOR) + if (!CONST_INT_P (length)) return false; - if (CONST_INT_P (length)) - { - unsigned HOST_WIDE_INT hwi_length = UINTVAL (length); - unsigned HOST_WIDE_INT factor, align; + unsigned HOST_WIDE_INT hwi_length = UINTVAL (length); + unsigned HOST_WIDE_INT factor, align; - align = MIN (MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), BITS_PER_WORD); - factor = BITS_PER_WORD / align; + align = MIN (MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), BITS_PER_WORD); + factor = BITS_PER_WORD / align; - if (optimize_function_for_size_p (cfun) - && hwi_length * factor * UNITS_PER_WORD > MOVE_RATIO (false)) - return false; + if (optimize_function_for_size_p (cfun) + && hwi_length * factor * UNITS_PER_WORD > MOVE_RATIO (false)) + return false; - if (hwi_length <= (RISCV_MAX_MOVE_BYTES_STRAIGHT / factor)) + if (hwi_length <= (RISCV_MAX_MOVE_BYTES_STRAIGHT / factor)) + { + riscv_block_move_straight (dest, src, INTVAL (length)); + return true; + } + else if (optimize && align >= BITS_PER_WORD) + { + unsigned min_iter_words + = RISCV_MAX_MOVE_BYTES_PER_LOOP_ITER / UNITS_PER_WORD; + unsigned iter_words = min_iter_words; + unsigned HOST_WIDE_INT bytes = hwi_length; + unsigned HOST_WIDE_INT words = bytes / UNITS_PER_WORD; + + /* Lengthen the loop body if it shortens the tail. */ + for (unsigned i = min_iter_words; i < min_iter_words * 2 - 1; i++) { - riscv_block_move_straight (dest, src, INTVAL (length)); - return true; + unsigned cur_cost = iter_words + words % iter_words; + unsigned new_cost = i + words % i; + if (new_cost <= cur_cost) + iter_words = i; } - else if (optimize && align >= BITS_PER_WORD) - { - unsigned min_iter_words - = RISCV_MAX_MOVE_BYTES_PER_LOOP_ITER / UNITS_PER_WORD; - unsigned iter_words = min_iter_words; - unsigned HOST_WIDE_INT bytes = hwi_length; - unsigned HOST_WIDE_INT words = bytes / UNITS_PER_WORD; - - /* Lengthen the loop body if it shortens the tail. */ - for (unsigned i = min_iter_words; i < min_iter_words * 2 - 1; i++) - { - unsigned cur_cost = iter_words + words % iter_words; - unsigned new_cost = i + words % i; - if (new_cost <= cur_cost) - iter_words = i; - } - riscv_block_move_loop (dest, src, bytes, iter_words * UNITS_PER_WORD); - return true; - } + riscv_block_move_loop (dest, src, bytes, iter_words * UNITS_PER_WORD); + return true; + } + + return false; +} + +/* This function delegates block-move expansion to either the vector + implementation or the scalar one. Return TRUE if successful or FALSE + otherwise. */ + +bool +riscv_expand_block_move (rtx dest, rtx src, rtx length) +{ + if (TARGET_VECTOR && stringop_strategy & STRATEGY_VECTOR) + { + bool ok = riscv_vector::expand_block_move (dest, src, length); + if (ok) + return true; } + + if (stringop_strategy & STRATEGY_SCALAR) + return riscv_expand_block_move_scalar (dest, src, length); + return false; } @@ -777,9 +794,8 @@ expand_block_move (rtx dst_in, rtx src_in, rtx length_in) bnez a2, loop # Any more? ret # Return */ - if (!TARGET_VECTOR || riscv_memcpy_strategy == USE_LIBCALL - || riscv_memcpy_strategy == USE_SCALAR) - return false; + gcc_assert (TARGET_VECTOR); + HOST_WIDE_INT potential_ew = (MIN (MIN (MEM_ALIGN (src_in), MEM_ALIGN (dst_in)), BITS_PER_WORD) / BITS_PER_UNIT); diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 96abdfc..a98918d 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2354,9 +2354,7 @@ (use (match_operand:SI 3 "const_int_operand"))])] "" { - if (riscv_vector::expand_block_move (operands[0], operands[1], operands[2])) - DONE; - else if (riscv_expand_block_move (operands[0], operands[1], operands[2])) + if (riscv_expand_block_move (operands[0], operands[1], operands[2])) DONE; else FAIL; diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 78186ff..59ce710 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -538,21 +538,21 @@ Enable the use of vector registers for function arguments and return value. This is an experimental switch and may be subject to change in the future. Enum -Name(riscv_stringop_strategy) Type(enum riscv_stringop_strategy_enum) -Valid arguments to -mmemcpy-strategy=: +Name(stringop_strategy) Type(enum stringop_strategy_enum) +Valid arguments to -mstringop-strategy=: EnumValue -Enum(riscv_stringop_strategy) String(auto) Value(USE_AUTO) +Enum(stringop_strategy) String(auto) Value(STRATEGY_AUTO) EnumValue -Enum(riscv_stringop_strategy) String(libcall) Value(USE_LIBCALL) +Enum(stringop_strategy) String(libcall) Value(STRATEGY_LIBCALL) EnumValue -Enum(riscv_stringop_strategy) String(scalar) Value(USE_SCALAR) +Enum(stringop_strategy) String(scalar) Value(STRATEGY_SCALAR) EnumValue -Enum(riscv_stringop_strategy) String(vector) Value(USE_VECTOR) +Enum(stringop_strategy) String(vector) Value(STRATEGY_VECTOR) -mmemcpy-strategy= -Target RejectNegative Joined Enum(riscv_stringop_strategy) Var(riscv_memcpy_strategy) Init(USE_AUTO) -Specify memcpy expansion strategy. +mstringop-strategy= +Target RejectNegative Joined Enum(stringop_strategy) Var(stringop_strategy) Init(STRATEGY_AUTO) +Specify stringop expansion strategy. diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-1.c index ae49706..adad5ab 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-1.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-march=rv32gcv -mabi=ilp32d -mmemcpy-strategy=libcall" } */ +/* { dg-options "-march=rv32gcv -mabi=ilp32d -mstringop-strategy=libcall" } */ #include "cpymem-strategy.h" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-2.c b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-2.c index 73ffc57..7a7c97d 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-2.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -march=rv32gcv -mabi=ilp32d -mmemcpy-strategy=scalar" } */ +/* { dg-options "-O2 -march=rv32gcv -mabi=ilp32d -mstringop-strategy=scalar" } */ #include "cpymem-strategy.h" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-3.c b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-3.c index 44f5f78..83e5a83 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-3.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-march=rv32gcv -mabi=ilp32d -mmemcpy-strategy=vector" } */ +/* { dg-options "-march=rv32gcv -mabi=ilp32d -mstringop-strategy=vector" } */ #include "cpymem-strategy.h" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-4.c b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-4.c index 8056895..800549c 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-4.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-4.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-march=rv32gcv -mabi=ilp32d -mmemcpy-strategy=auto" } */ +/* { dg-options "-march=rv32gcv -mabi=ilp32d -mstringop-strategy=auto" } */ #include "cpymem-strategy.h" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-5.c b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-5.c index 82ecab0..134fd2e 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-5.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-strategy-5.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-march=rv32gc -mabi=ilp32d -mmemcpy-strategy=vector" } */ +/* { dg-options "-march=rv32gc -mabi=ilp32d -mstringop-strategy=vector" } */ #include "cpymem-strategy.h" |