This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR 10339: Remove unsafe memcmp optimizations
> From: Richard Henderson <rth at redhat dot com>
>
> On Sat, Apr 19, 2003 at 11:54:32AM -0400, Kaveh R. Ghazi wrote:
> > +byte by byte in lexicographic order starting at the beginning of each
> > +string. The instruction is not allowed to prefetch more than one word
> > +at a time since either string may end in the first word and reading past
> > +that may access an invalid page or segment and cause a fault.
>
> Not "word", byte.
>
> If the target allows unaligned loads, we can't allow cmpstrsi
> to load an SImode value from (page + pagesize - 3).
> r~
Hmm, perhaps I should have said "aligned word". I thought that was
safe.
Anyway, I switch to "byte".
Ok?
2003-04-19 Kaveh R. Ghazi <ghazi at caip dot rutgers dot edu>
gcc:
* doc/md.texi (cmpstr): Document additional restrictions.
testsuite:
* gcc.c-torture/execute/string-opt-8.c: Don't perform cmpstr
checks for __pj__, but do them for !__OPTIMIZE__ and __s390__.
diff -rup orig/egcc-CVS20030425/gcc/doc/md.texi egcc-CVS20030425/gcc/doc/md.texi
--- orig/egcc-CVS20030425/gcc/doc/md.texi 2003-02-11 16:00:42.000000000 -0500
+++ egcc-CVS20030425/gcc/doc/md.texi 2003-04-26 10:40:56.888288574 -0400
@@ -2788,9 +2788,12 @@ The use for multiple @code{clrstr at var{m}
Block 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{movstr at var{m}} dot The two memory blocks specified are compared
-byte by byte in lexicographic order. The effect of the instruction is
-to store a value in operand 0 whose sign indicates the result of the
-comparison.
+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
+effect of the instruction is to store a value in operand 0 whose sign
+indicates the result of the comparison.
@cindex @code{strlen at var{m}} instruction pattern
@item @samp{strlen at var{m}}
diff -rup orig/egcc-CVS20030425/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c egcc-CVS20030425/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c
--- orig/egcc-CVS20030425/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c 2003-01-21 14:43:53.000000000 -0500
+++ egcc-CVS20030425/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c 2003-04-26 10:40:22.981001826 -0400
@@ -65,8 +65,9 @@ int main ()
s2 = s1; s3 = s1+4;
if (strncmp (++s2, ++s3+2, 1) >= 0 || s2 != s1+1 || s3 != s1+5)
abort();
-#if defined(__i386__) || defined (__pj__) || defined (__i370__)
- /* These tests work on platforms which support cmpstrsi. */
+#if !defined(__OPTIMIZE__) || defined(__i386__) || defined (__i370__) || defined (__s390__)
+ /* These tests work on platforms which support cmpstrsi. We test it
+ at -O0 on all platforms to ensure the strncmp logic is correct. */
s2 = s1;
if (strncmp (++s2, "ello", 3) != 0 || s2 != s1+1)
abort();