From patchwork Fri Nov 26 08:57:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 73162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 66DE6B70DE for ; Fri, 26 Nov 2010 19:57:52 +1100 (EST) Received: (qmail 3297 invoked by alias); 26 Nov 2010 08:57:49 -0000 Received: (qmail 3287 invoked by uid 22791); 26 Nov 2010 08:57:49 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 26 Nov 2010 08:57:44 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAQ8vhi0002457 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 26 Nov 2010 03:57:43 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAQ8vgiS001701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 26 Nov 2010 03:57:42 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id oAQ8vgCj008762 for ; Fri, 26 Nov 2010 09:57:42 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oAQ8vfHW008760 for gcc-patches@gcc.gnu.org; Fri, 26 Nov 2010 09:57:41 +0100 Date: Fri, 26 Nov 2010 09:57:41 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Another builtin memset fix (PR middle-end/46647) Message-ID: <20101126085741.GK29412@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi! While H.J's patch fixed memset expansion with regard to negative second argument, this patch does the same for memset folding. We don't really care about any upper bits, only the low 8 bits matter. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-11-26 Jakub Jelinek PR middle-end/46647 * builtins.c (fold_builtin_memset): Check c is INTEGER_CST instead of host_integerp check. Use TREE_INT_CST_LOW instead of tree_low_cst. * gcc.dg/pr46647.c: New test. Jakub --- gcc/builtins.c.jj 2010-11-19 20:56:54.000000000 +0100 +++ gcc/builtins.c 2010-11-24 22:23:41.000000000 +0100 @@ -8345,7 +8345,7 @@ fold_builtin_memset (location_t loc, tre if (integer_zerop (len)) return omit_one_operand_loc (loc, type, dest, c); - if (! host_integerp (c, 1) || TREE_SIDE_EFFECTS (dest)) + if (TREE_CODE (c) != INTEGER_CST || TREE_SIDE_EFFECTS (dest)) return NULL_TREE; var = dest; @@ -8384,7 +8384,7 @@ fold_builtin_memset (location_t loc, tre if (CHAR_BIT != 8 || BITS_PER_UNIT != 8 || HOST_BITS_PER_WIDE_INT > 64) return NULL_TREE; - cval = tree_low_cst (c, 1); + cval = TREE_INT_CST_LOW (c); cval &= 0xff; cval |= cval << 8; cval |= cval << 16; --- gcc/testsuite/gcc.dg/pr46647.c.jj 2010-11-25 21:28:03.000000000 +0100 +++ gcc/testsuite/gcc.dg/pr46647.c 2010-11-25 21:29:57.000000000 +0100 @@ -0,0 +1,29 @@ +/* PR middle-end/46647 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int a; + +int +func1 (void) +{ + __builtin_memset (&a, -1, sizeof (a)); + return 0; +} + +int +func2 (void) +{ + __builtin_memset (&a, 123, sizeof (a)); + return 0; +} + +int +func3 (void) +{ + __builtin_memset (&a, 0, sizeof (a)); + return 0; +} + +/* { dg-final { scan-tree-dump-not "memset" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */