public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Test folding of str{n}{case}cmp and memchr (version 3)
Date: Wed, 12 Oct 2016 13:20:00 -0000	[thread overview]
Message-ID: <6ad4965b-2b6f-83bb-f0ae-04a19c1fd47c@suse.cz> (raw)
In-Reply-To: <CAFiYyc1YKXujOXesL_6WcaRYAXTHWYzKvLYxmLrh0SbHz_pa6Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 437 bytes --]

On 10/12/2016 10:34 AM, Richard Biener wrote:
> On Tue, Oct 11, 2016 at 11:38 AM, Martin Liška <mliska@suse.cz> wrote:
>> Third iteration of tests, where I added both GENERIC and GIMPLE folding
>> tests.
> 
> They should work already with -O1?

Yes, they work. Sending new version where I also added few situations
that trigger an undefined behavior (and should not be folded).

Martin

> 
> Otherwise ok.
> 
> Richard.
> 
>> Martin


[-- Attachment #2: 0005-Test-folding-of-str-n-case-cmp-and-memchr-v4.patch --]
[-- Type: text/x-patch, Size: 9060 bytes --]

From bae7f32a3f602d111ac67019c6cd6dd8efacae00 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 16 Aug 2016 15:56:01 +0200
Subject: [PATCH 5/5] Test folding of str{n}{case}cmp and memchr

gcc/testsuite/ChangeLog:

2016-08-16  Martin Liska  <mliska@suse.cz>

	* gcc.dg/tree-ssa/builtins-folding-generic.c: New test.
	* gcc.dg/tree-ssa/builtins-folding-gimple.c: Likewise.
	* gcc.dg/tree-ssa/builtins-folding-gimple-ub.c: Likewise.
---
 .../gcc.dg/tree-ssa/builtins-folding-generic.c     |  76 +++++++++++
 .../gcc.dg/tree-ssa/builtins-folding-gimple-ub.c   |  23 ++++
 .../gcc.dg/tree-ssa/builtins-folding-gimple.c      | 140 +++++++++++++++++++++
 3 files changed, 239 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-generic.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-generic.c b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-generic.c
new file mode 100644
index 0000000..175feff
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-generic.c
@@ -0,0 +1,76 @@
+/* { dg-do run } */
+/* { dg-options "-O1 -fdump-tree-original" } */
+
+char *buffer1;
+char *buffer2;
+
+#define SIZE 1000
+
+int
+main (void)
+{
+  const char* const foo1 = "hello world";
+
+  buffer1 = __builtin_malloc (SIZE);
+  __builtin_strcpy (buffer1, foo1);
+  buffer2 = __builtin_malloc (SIZE);
+  __builtin_strcpy (buffer2, foo1);
+
+  /* MEMCHR.  */
+  if (__builtin_memchr ("hello world", 'x', 11))
+    __builtin_abort ();
+  if (__builtin_memchr ("hello world", 'x', 0) != 0)
+    __builtin_abort ();
+  if (__builtin_memchr ("hello world", 'w', 2))
+    __builtin_abort ();
+  if (__builtin_memchr ("hello world", 'd', 10))
+    __builtin_abort ();
+  if (__builtin_memchr ("hello world", '\0', 11))
+    __builtin_abort ();
+
+  /* STRCMP.  */
+  if (__builtin_strcmp ("hello", "aaaaa") <= 0)
+    __builtin_abort ();
+  if (__builtin_strcmp ("aaaaa", "aaaaa") != 0)
+    __builtin_abort ();
+  if (__builtin_strcmp ("aaaaa", "") <= 0)
+    __builtin_abort ();
+  if (__builtin_strcmp ("", "aaaaa") >= 0)
+    __builtin_abort ();
+  if (__builtin_strcmp ("ab", "ba") >= 0)
+    __builtin_abort ();
+
+  /* STRNCMP.  */
+  if (__builtin_strncmp ("hello", "aaaaa", 0) != 0)
+    __builtin_abort ();
+  if (__builtin_strncmp ("aaaaa", "aaaaa", 100) != 0)
+    __builtin_abort ();
+  if (__builtin_strncmp ("aaaaa", "", 100) <= 0)
+    __builtin_abort ();
+  if (__builtin_strncmp ("", "aaaaa", 100) >= 0)
+    __builtin_abort ();
+  if (__builtin_strncmp ("ab", "ba", 1) >= 0)
+    __builtin_abort ();
+  if (__builtin_strncmp ("aab", "aac", 2) != 0)
+    __builtin_abort ();
+
+  /* STRCASECMP.  */
+  if (__builtin_strcasecmp ("aaaaa", "aaaaa") != 0)
+    __builtin_abort ();
+
+  /* STRNCASECMP.  */
+  if (__builtin_strncasecmp ("hello", "aaaaa", 0) != 0)
+    __builtin_abort ();
+  if (__builtin_strncasecmp ("aaaaa", "aaaaa", 100) != 0)
+    __builtin_abort ();
+  if (__builtin_strncasecmp ("aab", "aac", 2) != 0)
+    __builtin_abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "__builtin_strcmp" "original" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_strcasecmp" "original" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_strncmp" "original" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_strncasecmp" "original" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_memchr" "original" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c
new file mode 100644
index 0000000..df0ede2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+char *buffer1;
+char *buffer2;
+
+#define SIZE 1000
+
+int
+main (void)
+{
+  const char* const foo1 = "hello world";
+
+  /* MEMCHR.  */
+  if (__builtin_memchr ("", 'x', 1000)) /* Not folded away.  */
+    __builtin_abort ();
+  if (__builtin_memchr (foo1, 'x', 1000)) /* Not folded away.  */
+    __builtin_abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "__builtin_memchr" 2 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple.c b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple.c
new file mode 100644
index 0000000..4cac93a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple.c
@@ -0,0 +1,140 @@
+/* { dg-do run } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+char *buffer1;
+char *buffer2;
+
+#define SIZE 1000
+
+int
+main (void)
+{
+  const char* const foo1 = "hello world";
+
+  buffer1 = __builtin_malloc (SIZE);
+  __builtin_strcpy (buffer1, foo1);
+  buffer2 = __builtin_malloc (SIZE);
+  __builtin_strcpy (buffer2, foo1);
+
+  char x = 'x';
+  char o = 'o';
+  char w = 'w';
+  char d = 'd';
+  char e = 'e';
+  char null = '\0';
+
+  int zero = 0;
+  int one = 0;
+
+  /* MEMCHR.  */
+  if (__builtin_memchr (foo1, x, 11))
+    __builtin_abort ();
+  if (__builtin_memchr (buffer1, x, zero) != 0)
+    __builtin_abort ();
+  if (__builtin_memchr (foo1, o, 11) != foo1 + 4)
+    __builtin_abort ();
+  if (__builtin_memchr (foo1, w, 2))
+    __builtin_abort ();
+  if (__builtin_memchr (foo1 + 5, o, 6) != foo1 + 7)
+    __builtin_abort ();
+  if (__builtin_memchr (foo1, d, 11) != foo1 + 10)
+    __builtin_abort ();
+  if (__builtin_memchr (foo1, d, 10))
+    __builtin_abort ();
+  if (__builtin_memchr (foo1, null, 11))
+    __builtin_abort ();
+  if (__builtin_memchr (foo1, null, 12) != foo1 + 11)
+    __builtin_abort ();
+
+  __builtin_memchr (foo1, x, 11);
+  __builtin_memchr (buffer1, x, zero);
+  __builtin_memchr (foo1, w, 2);
+  __builtin_memchr (foo1, e, 5);
+
+  const char *aaaaa = "aaaaa";
+  const char *hello = "hello";
+  const char *empty = "";
+  const char *ab = "ab";
+  const char *ba = "ba";
+  const char *aac = "aac";
+  const char *aab = "aab";
+
+  /* STRCMP.  */
+  if (__builtin_strcmp (hello, aaaaa) <= 0)
+    __builtin_abort ();
+  if (__builtin_strcmp (aaaaa, aaaaa) != 0)
+    __builtin_abort ();
+  if (__builtin_strcmp (aaaaa, empty) <= 0)
+    __builtin_abort ();
+  if (__builtin_strcmp (empty, aaaaa) >= 0)
+    __builtin_abort ();
+  if (__builtin_strcmp (ab, ba) >= 0)
+    __builtin_abort ();
+
+  __builtin_strcmp (hello, aaaaa);
+  __builtin_strcmp (aaaaa, aaaaa);
+  __builtin_strcmp (aaaaa, empty);
+  __builtin_strcmp (empty, aaaaa);
+  __builtin_strcmp (ab, ba);
+
+  /* STRNCMP.  */
+  if (__builtin_strncmp (hello, aaaaa, zero) != 0)
+    __builtin_abort ();
+  if (__builtin_strncmp (aaaaa, aaaaa, 100) != 0)
+    __builtin_abort ();
+  if (__builtin_strncmp (aaaaa, empty, 100) <= 0)
+    __builtin_abort ();
+  if (__builtin_strncmp (empty, aaaaa, 100) >= 0)
+    __builtin_abort ();
+  if (__builtin_strncmp (ab, ba, 1) >= 0)
+    __builtin_abort ();
+  if (__builtin_strncmp (aab, aac, 2) != 0)
+    __builtin_abort ();
+  if (__builtin_strncmp (buffer1, buffer2, 1) != 0)
+    __builtin_abort (); /* not folded away */
+
+  __builtin_strncmp (hello, aaaaa, zero);
+  __builtin_strncmp (aaaaa, aaaaa, 100);
+  __builtin_strncmp (aaaaa, empty, 100);
+  __builtin_strncmp (empty, aaaaa, 100);
+  __builtin_strncmp (ab, ba, 1);
+  __builtin_strncmp (aab, aac, 2);
+  __builtin_strncmp (buffer1, buffer2, zero);
+  __builtin_strncmp (buffer1, buffer2, one);
+  __builtin_strncmp (empty, buffer2, 1);
+  __builtin_strncmp (buffer1, empty, 1);
+
+  /* STRCASECMP.  */
+  if (__builtin_strcasecmp (aaaaa, aaaaa) != 0)
+    __builtin_abort ();
+  if (__builtin_strcasecmp (aaaaa, empty) <= 0)
+    __builtin_abort ();
+  if (__builtin_strcasecmp (empty, aaaaa) >= 0)
+    __builtin_abort ();
+
+  /* STRNCASECMP.  */
+  if (__builtin_strncasecmp (hello, aaaaa, zero) != 0)
+    __builtin_abort ();
+  if (__builtin_strncasecmp (aaaaa, aaaaa, 100) != 0)
+    __builtin_abort ();
+  if (__builtin_strncasecmp (aaaaa, empty, 100) <= 0)
+    __builtin_abort ();
+  if (__builtin_strncasecmp (empty, aaaaa, 100) >= 0)
+    __builtin_abort ();
+  if (__builtin_strncasecmp (aab, aac, 2) != 0)
+    __builtin_abort ();
+  if (__builtin_strncasecmp (ab, ba, 1) >= 0) /* not folded away */
+    __builtin_abort (); /* not folded away */
+  if (__builtin_strncasecmp (buffer1, buffer2, 1) != 0) /* not folded away */
+    __builtin_abort (); /* not folded away */
+  if (__builtin_strncasecmp (buffer1, buffer2, 100) != 0) /* not folded away */
+    __builtin_abort (); /* not folded away */
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "__builtin_strcmp" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_strcasecmp" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_strncmp" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_memchr" "optimized" } } */
+/* { dg-final { scan-tree-dump-times "__builtin_strncasecmp" 3 "optimized" } } */
-- 
2.9.2


  reply	other threads:[~2016-10-12 13:20 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17  6:55 [PATCH 0/3] Better folding of 2 string builtin-ins marxin
2016-08-17  6:55 ` [PATCH 1/3] Fold BUILT_IN_STRNCASECMP marxin
2016-08-17  7:10   ` Jakub Jelinek
2016-08-17  7:52     ` Martin Liška
2016-10-07  8:39   ` [PATCH 1/3] Fold __builtin_str{n}{case}cmp functions (version 2) Martin Liška
2016-10-07 10:50     ` Richard Biener
2016-10-11  9:26       ` Martin Liška
2016-10-11 10:27         ` Richard Biener
2016-10-11  9:28       ` [PATCH] Check \0-termination of string in c_getstr Martin Liška
2016-10-11 10:28         ` Richard Biener
2016-10-12 13:14           ` Martin Liška
2016-10-13 15:24             ` [PATCH] Check \0-termination of string in c_getstr (simplified version) Martin Liška
2016-10-14  9:38               ` Richard Biener
2016-10-14 11:10                 ` Martin Liška
2016-10-11  9:28       ` [PATCH] Add a helper function: create_tmp Martin Liška
2016-10-11 10:30         ` Richard Biener
2016-10-11 10:31           ` Richard Biener
2016-10-12 10:50             ` Martin Liška
2016-10-11  9:34       ` [PATCH] Fold __builtin_str{n}{case}cmp functions (version 3) Martin Liška
2016-10-12  8:30         ` Richard Biener
2016-10-12 13:17           ` Martin Liška
2016-10-13 15:25             ` [PATCH] Fold __builtin_str{n}{case}cmp functions (simplified version 4) Martin Liška
2016-10-14 11:55               ` Richard Biener
2016-08-17  6:55 ` [PATCH 3/3] Test folding of strn{case}cmp and memchr marxin
2016-08-17  7:52   ` Martin Liška
2016-10-07  8:42     ` [PATCH 3/3] Test folding of str{n}{case}cmp and memchr (version 2) Martin Liška
2016-10-11  9:39       ` [PATCH] Test folding of str{n}{case}cmp and memchr (version 3) Martin Liška
2016-10-12  8:35         ` Richard Biener
2016-10-12 13:20           ` Martin Liška [this message]
2016-10-13 15:27             ` [PATCH] Test folding of str{n}{case}cmp and memchr (simplified version 4) Martin Liška
2016-10-14 11:58               ` Richard Biener
2016-08-17  6:55 ` [PATCH 2/3] Smarter folding of __builtin_memchr marxin
2016-08-17  8:41   ` Richard Biener
2016-10-07  8:41     ` [PATCH 2/3] Fold __builtin_memchr (version 2) Martin Liška
2016-10-07 11:01       ` Richard Biener
2016-10-11  9:38         ` [PATCH] Fold __builtin_memchr (version 3) Martin Liška
2016-10-12  8:34           ` Richard Biener
2016-10-12  8:36           ` Richard Biener
2016-10-12 13:19             ` Martin Liška
2016-10-13 15:26               ` [PATCH] Fold __builtin_memchr (simplified version 4) Martin Liška
2016-10-14 11:57                 ` Richard Biener
2016-10-12 13:48 ` [RFC] Possible folding opportunities for string built-ins Martin Liška
2016-10-12 15:55   ` Joseph Myers
2016-10-12 19:45     ` Jim Wilson
2016-10-13  8:38   ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ad4965b-2b6f-83bb-f0ae-04a19c1fd47c@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).