https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129059

            Bug ID: 129059
           Summary: RISC-V inlines a constant-size memcpy that exceeds
                    memcpy-size-threshold
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: majin at gcc dot gnu.org
  Target Milestone: ---

Description:
With memcpy-size-threshold set to 6 bytes, GCC still inlines a 7-byte copy.

Compiler information
GCC 17.0.0 20261125 (experimental) targeting riscv64-unknown-linux-gnu
GCC master revision tested: 1330eed38849ad186518f609c52bd5651c2bfdc1

Reproducer
Save the following as testcase.c.

void copy_2 (char *dst, const char *src)
{
  __builtin_memcpy (dst, src, 2);
}

void copy_7 (char *dst, const char *src)
{
  __builtin_memcpy (dst, src, 7);
}

riscv64-unknown-linux-gnu-gcc -O2 -march=rv64gcv_zvl256b -mabi=lp64d \
  -mcmodel=medany -mtune=generic-ooo -mstrict-align -mstringop-strategy=vector
\
  --param=memcpy-size-threshold=6 -S testcase.c -o testcase.s

Actual result
copy_7 emits one lbu/sb pair at each offset from 0 through 6, then returns.

Expected result
The explicit threshold should make copy_7 call memcpy. With the proposed
fix, copy_7 emits tail memcpy and the 2-byte copy in copy_2 stays inline.

Reply via email to