From patchwork Fri Jul 29 02:12:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 107372 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 D5020B6EE8 for ; Fri, 29 Jul 2011 21:43:48 +1000 (EST) Received: (qmail 27005 invoked by alias); 29 Jul 2011 11:43:47 -0000 Received: (qmail 26997 invoked by uid 22791); 29 Jul 2011 11:43:46 -0000 X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL,BAYES_00,SPF_FAIL X-Spam-Check-By: sourceware.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (140.186.70.92) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 29 Jul 2011 11:43:33 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QmcYt-00036J-Vx for gcc-patches@gcc.gnu.org; Thu, 28 Jul 2011 22:12:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51220) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmcYt-00035j-NO for gcc-patches@gcc.gnu.org; Thu, 28 Jul 2011 22:12:27 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6T2C8nW016502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 28 Jul 2011 22:12:08 -0400 Received: from houston.quesejoda.com (vpn-227-112.phx2.redhat.com [10.3.227.112]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6T2C7Yn009873; Thu, 28 Jul 2011 22:12:07 -0400 Message-ID: <4E3216F7.10504@redhat.com> Date: Thu, 28 Jul 2011 21:12:07 -0500 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110707 Thunderbird/5.0 MIME-Version: 1.0 To: Richard Guenther CC: Jason Merrill , Jeff Law , gcc-patches , Jakub Jelinek Subject: Re: [C++0x] contiguous bitfields race implementation References: <4DC8155A.3040401@redhat.com> <4DC82136.6030802@redhat.com> <4DC83549.8010709@redhat.com> <4DC83F49.5020101@redhat.com> <4DCD8412.9020005@redhat.com> <4DD440EA.2080500@redhat.com> <4DD5AA47.4000902@redhat.com> <4DDE8CE6.40203@redhat.com> <4DDE9040.8000807@redhat.com> <4DDE99D2.4020502@redhat.com> <4DDE9DED.6040801@redhat.com> <4DDFF90E.7070408@redhat.com> <4E2420E6.8090809@redhat.com> <4E29C502.8020100@redhat.com> <4E2DA2BA.1010003@redhat.com> <4E2E0264.30909@redhat.com> <4E2EED10.5030901@redhat.com> <4E2EF1E7.4020606@redhat.com> <4E2EFA1C.10803@redhat.com> <4E2EFB89.7060503@redhat.com> In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 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 On 07/28/11 06:40, Richard Guenther wrote: > Looking at the C++ memory model what you need is indeed simple enough > to recover here. Still this loop does quadratic work for a struct with > N bitfield members and a function which stores into all of them. > And that with a big constant factor as you build a component-ref > and even unshare trees (which isn't necessary here anyway). In fact > you could easily manually keep track of bitpos when walking adjacent > bitfield members. An initial call to get_inner_reference on > TREE_OPERAND (exp, 0) would give you the starting position of the record. > > That would still be quadratic of course. Actually, we don't need to call get_inner_reference at all. It seems DECL_FIELD_BIT_OFFSET has all the information we need. How about we simplify things further as in the attached patch? Tested on x86-64 Linux. OK for mainline? * expr.c (get_bit_range): Get field bit offset from DECL_FIELD_BIT_OFFSET. Index: expr.c =================================================================== --- expr.c (revision 176891) +++ expr.c (working copy) @@ -4179,18 +4179,10 @@ get_bit_range (unsigned HOST_WIDE_INT *b prev_field_is_bitfield = true; for (fld = TYPE_FIELDS (record_type); fld; fld = DECL_CHAIN (fld)) { - tree t, offset; - enum machine_mode mode; - int unsignedp, volatilep; - if (TREE_CODE (fld) != FIELD_DECL) continue; - t = build3 (COMPONENT_REF, TREE_TYPE (exp), - unshare_expr (TREE_OPERAND (exp, 0)), - fld, NULL_TREE); - get_inner_reference (t, &bitsize, &bitpos, &offset, - &mode, &unsignedp, &volatilep, true); + bitpos = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (fld)); if (field == fld) found_field = true;