From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127127 invoked by alias); 17 Aug 2016 07:52:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 127115 invoked by uid 89); 17 Aug 2016 07:52:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Aug 2016 07:52:38 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 99FC1ABEF for ; Wed, 17 Aug 2016 07:52:36 +0000 (UTC) Subject: Re: [PATCH 3/3] Test folding of strn{case}cmp and memchr To: gcc-patches@gcc.gnu.org References: <8871f5ae1f3151e1de62622d4f918d24d693a48b.1471416736.git.mliska@suse.cz> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <8713f2ee-ff9c-13b9-db4e-40e832fee1a4@suse.cz> Date: Wed, 17 Aug 2016 07:52:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: <8871f5ae1f3151e1de62622d4f918d24d693a48b.1471416736.git.mliska@suse.cz> Content-Type: multipart/mixed; boundary="------------8CB4C7239B32B2D64CFBD790" X-IsSubscribed: yes X-SW-Source: 2016-08/txt/msg01240.txt.bz2 This is a multi-part message in MIME format. --------------8CB4C7239B32B2D64CFBD790 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Content-length: 12 v2. Martin --------------8CB4C7239B32B2D64CFBD790 Content-Type: text/x-patch; name="0003-Test-folding-of-strn-case-cmp-and-memchr-v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0003-Test-folding-of-strn-case-cmp-and-memchr-v2.patch" Content-length: 3305 >From 42ea652d00fec821514d34b2af81f2a9e11b248c Mon Sep 17 00:00:00 2001 From: marxin Date: Tue, 16 Aug 2016 15:56:01 +0200 Subject: [PATCH 3/3] Test folding of strn{case}cmp and memchr gcc/testsuite/ChangeLog: 2016-08-16 Martin Liska * gcc.dg/tree-ssa/builtins-folding.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/builtins-folding.c | 74 ++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/builtins-folding.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding.c b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding.c new file mode 100644 index 0000000..48a86e3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding.c @@ -0,0 +1,74 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +char *buffer1; +char *buffer2; + +int +main (void) +{ + const char* const foo1 = "hello world"; + + buffer1 = __builtin_malloc (1000); + __builtin_strcpy (buffer1, foo1); + buffer2 = __builtin_malloc (1000); + __builtin_strcpy (buffer2, foo1); + + /* MEMCHR. */ + if (__builtin_memchr (foo1, 'x', 11)) + __builtin_abort (); + if (__builtin_memchr (foo1, 'x', 100)) + __builtin_abort (); + if (__builtin_memchr (buffer1, 'x', 0) != 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, '\0', 11)) + __builtin_abort (); + if (__builtin_memchr (foo1, '\0', 12) != foo1 + 11) + __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 (buffer1, buffer2, 1) != 0) + __builtin_abort (); /* not folded away */ + + /* STRNCASECMP. */ + if (__builtin_strncasecmp ("hello", "aaaaa", 0) != 0) + __builtin_abort (); + if (__builtin_strncasecmp ("aaaaa", "aaaaa", 100) != 0) + __builtin_abort (); + if (__builtin_strncasecmp ("aaaaa", "", 100) <= 0) + __builtin_abort (); + if (__builtin_strncasecmp ("", "aaaaa", 100) >= 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_memchr" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "__builtin_strncmp" "optimized" } } */ +/* { dg-final { scan-tree-dump-times "__builtin_strncasecmp" 3 "optimized" } } */ -- 2.9.2 --------------8CB4C7239B32B2D64CFBD790--