On Mon, Nov 16, 2026 at 1:01 PM <[email protected]> wrote:
>
> From: Kyrylo Tkachov <[email protected]>
>
> md.texi does not allow cmpstrn and cmpstr patterns to read more than one
> byte at a time, because either string may end in its first byte and a
> wider read may fault.  A target that knows that a wider read cannot fault
> can still use such a read.  For example, an aligned block that contains a
> byte that the comparison has to read can be read as a whole, as it never
> crosses into another page or memory tag granule.
>
> This patch relaxes the wording for such reads.  The documentation of the
> memchr pattern already has the same condition.
>
> Bootstrapped and tested on aarch64-none-linux-gnu.
> Ok for trunk?

OK.  IMO just a re-wording of what the previous text actually implies.

Richard.

> Thanks,
> Kyrill
>
> gcc/ChangeLog:
>
>         * doc/md.texi (cmpstrn@var{m}, cmpstr@var{m}): Allow reads of more
>         than one byte that cannot fault.
>
> Signed-off-by: Kyrylo Tkachov <[email protected]>
> ---
>  gcc/doc/md.texi | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
> index 76471cd322e..d2d21d36458 100644
> --- a/gcc/doc/md.texi
> +++ b/gcc/doc/md.texi
> @@ -6010,10 +6010,11 @@ String compare instruction, with five operands.  
> Operand 0 is the output;
>  it has mode @var{m}.  The remaining four operands are like the operands
>  of @samp{cpymem@var{m}}.  The two memory blocks specified are compared
>  byte by byte in lexicographic order starting at the beginning of each
> -string.  The instruction is not allowed to prefetch more than one byte
> -at a time since either string may end in the first byte and reading past
> -that may access an invalid page or segment and cause a fault.  The
> -comparison terminates early if the fetched bytes are different or if
> +string.  Since either string may end in the first byte, the instruction
> +is not allowed to read more than one byte at a time unless the target
> +knows that the wider reads cannot fault, for example because they stay
> +within an aligned block that contains a byte the comparison has to read.
> +The comparison terminates early if the fetched bytes are different or if
>  they are equal to zero.  The effect of the instruction is to store a
>  value in operand 0 whose sign indicates the result of the comparison.
>
> @@ -6030,11 +6031,11 @@ compiler knows that both source and destination are 
> word-aligned,
>  it may provide the value 4 for this operand.
>
>  The two memory blocks specified are compared byte by byte in lexicographic
> -order starting at the beginning of each string.  The instruction is not 
> allowed
> -to prefetch more than one byte at a time since either string may end in the
> -first byte and reading past that may access an invalid page or segment and
> -cause a fault.  The comparison will terminate when the fetched bytes
> -are different or if they are equal to zero.  The effect of the
> +order starting at the beginning of each string.  As for
> +@samp{cmpstrn@var{m}}, the instruction is not allowed to read more than one
> +byte at a time unless the target knows that the wider reads cannot fault.
> +The comparison will terminate when the fetched bytes are different or if
> +they are equal to zero.  The effect of the
>  instruction is to store a value in operand 0 whose sign indicates the
>  result of the comparison.
>
> --
> 2.54.0 (Apple Git-157)
>

Reply via email to