From patchwork Wed Nov 24 23:00:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 72958 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 47E86B7043 for ; Thu, 25 Nov 2010 10:01:30 +1100 (EST) Received: (qmail 19732 invoked by alias); 24 Nov 2010 23:00:49 -0000 Received: (qmail 19704 invoked by uid 22791); 24 Nov 2010 23:00:45 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga14.intel.com (HELO mga14.intel.com) (143.182.124.37) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 24 Nov 2010 23:00:40 +0000 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 24 Nov 2010 15:00:39 -0800 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.135]) by azsmga001.ch.intel.com with ESMTP; 24 Nov 2010 15:00:38 -0800 Received: by gnu-6.sc.intel.com (Postfix, from userid 500) id 6FB091808CA; Wed, 24 Nov 2010 15:00:38 -0800 (PST) Date: Wed, 24 Nov 2010 15:00:38 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: PATCH: PR middle-end/46647: Can't inline memset with -1 Message-ID: <20101124230038.GA23379@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 target_char_cast doesn't properly hanle cast integer constant, whose highest bit is set, to char. When an integer constant is casted to char, we only care about lower bits. This patch fixes it. OK for trunk if it passes bootstrap on Linux/x86-64 with 32bit/64bit tests? Thanks. H.J. --- gcc/ 2010-11-24 H.J. Lu PR middle-end/46647 * builtins.c (target_char_cast): Check INTEGER_CST instead of host_integerp. Replace tree_low_cst with TREE_INT_CST_LOW. gcc/testsuite/ 2010-11-24 H.J. Lu PR middle-end/46647 * gcc.target/i386/pr46647.c: New. diff --git a/gcc/builtins.c b/gcc/builtins.c index c9e8e68..a90bf2f 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -630,11 +630,11 @@ target_char_cast (tree cst, char *p) { unsigned HOST_WIDE_INT val, hostval; - if (!host_integerp (cst, 1) + if (TREE_CODE (cst) != INTEGER_CST || CHAR_TYPE_SIZE > HOST_BITS_PER_WIDE_INT) return 1; - val = tree_low_cst (cst, 1); + val = TREE_INT_CST_LOW (cst); if (CHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT) val &= (((unsigned HOST_WIDE_INT) 1) << CHAR_TYPE_SIZE) - 1; --- /dev/null 2010-11-15 09:06:16.517000001 -0800 +++ gcc/gcc/testsuite/gcc.target/i386/pr46647.c 2010-11-24 14:17:04.885208046 -0800 @@ -0,0 +1,44 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mtune=generic" } */ + +char a[5]; +int +func1 (void) +{ + __builtin_memset (a,-1,sizeof (a)); + return 0; +} + +int a2[5]; +int +func2 (void) +{ + __builtin_memset (a2,-1,sizeof (a2)); + return 0; +} + +char a3[5]; +int +func3 (void) +{ + __builtin_memset (a3,0x8fffffff,sizeof (a3)); + return 0; +} + +char a4[5]; +int +func4 (void) +{ + __builtin_memset (a4,0x8fffff00,sizeof (a4)); + return 0; +} + +int a5[5]; +int +func5 (void) +{ + __builtin_memset (a5,0x8fffffff,sizeof (a5)); + return 0; +} + +/* { dg-final { scan-assembler-not "call\[\\t \]*_?memset" } } */