https://gcc.gnu.org/g:3d441f16194b458212c5f5e3050860cda07efe86

commit r17-6352-g3d441f16194b458212c5f5e3050860cda07efe86
Author: Kyrylo Tkachov <[email protected]>
Date:   Wed Nov 11 15:51:41 2026 +0100

    doc: Allow cmpstr and cmpstrn to read more than one byte at a time
    
    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.
    
    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]>

Diff:
---
 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 a273c2e47075..bcc31a1733bc 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.

Reply via email to