From patchwork Thu Apr 14 14:27:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 91244 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 26101B6FDB for ; Fri, 15 Apr 2011 00:27:11 +1000 (EST) Received: (qmail 30272 invoked by alias); 14 Apr 2011 14:27:10 -0000 Received: (qmail 30264 invoked by uid 22791); 14 Apr 2011 14:27:09 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-qw0-f47.google.com (HELO mail-qw0-f47.google.com) (209.85.216.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Apr 2011 14:27:03 +0000 Received: by qwh5 with SMTP id 5so1090693qwh.20 for ; Thu, 14 Apr 2011 07:27:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.43.142 with SMTP id w14mr587036qce.27.1302791222370; Thu, 14 Apr 2011 07:27:02 -0700 (PDT) Received: by 10.229.190.140 with HTTP; Thu, 14 Apr 2011 07:27:02 -0700 (PDT) In-Reply-To: References: <20110414133453.GA18805@intel.com> Date: Thu, 14 Apr 2011 07:27:02 -0700 Message-ID: Subject: Re: PATCH: PR middle-end/48608: Alignment adjust of local variables is lost From: "H.J. Lu" To: Richard Guenther Cc: GCC Patches 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 On Thu, Apr 14, 2011 at 7:09 AM, Richard Guenther wrote: > On Thu, Apr 14, 2011 at 4:01 PM, H.J. Lu wrote: >> On Thu, Apr 14, 2011 at 6:57 AM, Richard Guenther >> wrote: >>> On Thu, Apr 14, 2011 at 3:34 PM, H.J. Lu wrote: >>>> We have >>>> >>>> static unsigned int >>>> get_decl_align_unit (tree decl) >>>> { >>>>  unsigned int align = LOCAL_DECL_ALIGNMENT (decl); >>>>  return align / BITS_PER_UNIT; >>>> } >>>> >>>> LOCAL_DECL_ALIGNMENT may increase alignment for local variable.  But it is >>>> never saved.  DECL_ALIGN (decl) returns the old alignment.  This patch >>>> updates DECL_ALIGN if needed.  OK for trunk if there are no regressions? >>> >>> A get_* function does not seem like a good place to do such things. >> >> Any suggestion to how to do it properly? I can rename >> get_decl_align_unit to align_local_variable. > > That works for me. > >>> Why does it matter that DECL_ALIGN is updated? >>> >> >> My port needs accurate alignment information on local variables. > > I see. Here is the updated patch. OK for trunk if there are no regressions? Thanks. diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index cc1382f..d38d2f9 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -205,13 +205,15 @@ static bool has_protected_decls; smaller than our cutoff threshold. Used for -Wstack-protector. */ static bool has_short_buffer; -/* Discover the byte alignment to use for DECL. Ignore alignment +/* Compute the byte alignment to use for DECL. Ignore alignment we can't do with expected alignment of the stack boundary. */ static unsigned int -get_decl_align_unit (tree decl) +align_local_variable (tree decl) { unsigned int align = LOCAL_DECL_ALIGNMENT (decl); + if (align > DECL_ALIGN (decl)) + DECL_ALIGN (decl) = align; return align / BITS_PER_UNIT; } @@ -273,7 +275,7 @@ add_stack_var (tree decl) variables that are simultaneously live. */ if (v->size == 0) v->size = 1; - v->alignb = get_decl_align_unit (SSAVAR (decl)); + v->alignb = align_local_variable (SSAVAR (decl)); /* All variables are initially in their own partition. */ v->representative = stack_vars_num; @@ -905,7 +907,7 @@ expand_one_stack_var (tree var) unsigned byte_align; size = tree_low_cst (DECL_SIZE_UNIT (SSAVAR (var)), 1); - byte_align = get_decl_align_unit (SSAVAR (var)); + byte_align = align_local_variable (SSAVAR (var)); /* We handle highly aligned variables in expand_stack_vars. */ gcc_assert (byte_align * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT);