[RFA,RISC-V] Enable inlining str* by default
Checks
Context |
Check |
Description |
rivoscibot/toolchain-ci-rivos-lint |
warning
|
Lint failed
|
rivoscibot/toolchain-ci-rivos-apply-patch |
success
|
Patch applied
|
rivoscibot/toolchain-ci-rivos-build--newlib-rv64gcv-lp64d-multilib |
success
|
Build passed
|
rivoscibot/toolchain-ci-rivos-build--newlib-rv64gc-lp64d-multilib |
success
|
Build passed
|
rivoscibot/toolchain-ci-rivos-build--linux-rv64gcv-lp64d-multilib |
success
|
Build passed
|
rivoscibot/toolchain-ci-rivos-build--linux-rv64gc_zba_zbb_zbc_zbs-lp64d-non-multilib |
success
|
Build passed
|
rivoscibot/toolchain-ci-rivos-build--linux-rv32gc_zba_zbb_zbc_zbs-ilp32d-non-multilib |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Testing passed
|
rivoscibot/toolchain-ci-rivos-test |
fail
|
Testing failed
|
linaro-tcwg-bot/tcwg_gcc_check--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 |
success
|
Testing passed
|
Commit Message
So with Chrstoph's patches from late 2022 we've had the ability to
inline strlen, and str[n]cmp (scalar). However, we never actually
turned this capability on by default!
This patch flips the those default to allow inlinining by default. It
also fixes one bug exposed by our internal testing when NBYTES is zero
for strncmp. I don't think that case happens enough to try and optimize
it, we just disable inline expansion for that instance.
This has been bootstrapped and regression tested on rv64gc at various
times as well as cross tested on rv64gc more times than I can probably
count (we've have this patch internally for a while). More importantly,
I just successfully tested it on rv64gc and rv32gcv elf configurations
with the trunk ;-)
OK for the trunk (assuming it passes pre-commit CI)?
Jeff
[RFA][RISC-V] Enable inlining str* by default
So with Chrstoph's patches from late 2022 we've had the ability to inline
strlen, and str[n]cmp (scalar). However, we never actually turned this
capability on by default!
This patch flips the those default to allow inlinining by default. It also
fixes one bug exposed by our internal testing when NBYTES is zero for strncmp.
I don't think that case happens enough to try and optimize it, we just disable
inline expansion for that instance.
This has been bootstrapped and regression tested on rv64gc at various times as
well as cross tested on rv64gc more times than I can probably count (we've have
this patch internally for a while). More importantly, I just successfully
tested it on rv64gc and rv32gcv elf configurations with the trunk ;-)
OK for the trunk (assuming it passes pre-commit CI)?
gcc/
* config/riscv/riscv-string.cc (riscv_expand_strcmp): Do not inline
strncmp with zero size.
* config/riscv/riscv.opt (var_inline_strcmp): Enable by default.
(vriscv_inline_strncmp, riscv_inline_strlen): Likewise.
gcc/testsuite
* gcc.target/riscv/zbb-strlen-disabled-2.c: Turn off inlining.
@@ -497,6 +497,13 @@ riscv_expand_strcmp (rtx result, rtx src1, rtx src2,
return false;
nbytes = UINTVAL (bytes_rtx);
+ /* If NBYTES is zero the result of strncmp will always be zero,
+ but that would require special casing in the caller. So for
+ now just don't do an inline expansion. This probably rarely
+ happens in practice, but it is tested by the testsuite. */
+ if (nbytes == 0)
+ return false;
+
/* We don't emit parts of a strncmp() call. */
if (nbytes > compare_max)
return false;
@@ -515,15 +515,15 @@ Target Var(TARGET_INLINE_SUBWORD_ATOMIC) Init(1)
Always inline subword atomic operations.
minline-strcmp
-Target Var(riscv_inline_strcmp) Init(0)
+Target Var(riscv_inline_strcmp) Init(1)
Inline strcmp calls if possible.
minline-strncmp
-Target Var(riscv_inline_strncmp) Init(0)
+Target Var(riscv_inline_strncmp) Init(1)
Inline strncmp calls if possible.
minline-strlen
-Target Var(riscv_inline_strlen) Init(0)
+Target Var(riscv_inline_strlen) Init(1)
Inline strlen calls if possible.
-param=riscv-strcmp-inline-limit=
@@ -1,6 +1,6 @@
/* { dg-do compile } */
-/* { dg-options "-march=rv32gc_zbb" { target { rv32 } } } */
-/* { dg-options "-march=rv64gc_zbb" { target { rv64 } } } */
+/* { dg-options "-mno-inline-strlen -march=rv32gc_zbb" { target { rv32 } } } */
+/* { dg-options "-mno-inline-strlen -march=rv64gc_zbb" { target { rv64 } } } */
/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
typedef long unsigned int size_t;