From patchwork Fri Mar 27 18:06:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1262910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=dwdTkrxJ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48pqZc6SKBz9sNg for ; Sat, 28 Mar 2020 05:07:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 914A0385E012; Fri, 27 Mar 2020 18:07:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id DA5ED385E017 for ; Fri, 27 Mar 2020 18:07:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DA5ED385E017 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kito.cheng@sifive.com Received: by mail-pl1-x62c.google.com with SMTP id b9so3717867pls.12 for ; Fri, 27 Mar 2020 11:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m8FPURSVIVvEdpD8ZPXgZ14T7rJBShKZfZ2+Nl9B7eQ=; b=dwdTkrxJ8dCCx1BHcBTzDDwlMy2s/KnoqRRnOC4iZUV71yjB+hpShqp2w5n/2IKxkK AV04yNgmo5lWzPO68yI72E0QStX+wtugrJGrB0WvP6Vgx00uMZzTkKbfUSTCVCBcmgK2 yi4OcRtKn9jrR4GBXXcB38DjBhxS6qfCYNpDGMPGPPDlw4w2Ekhw8TB0e2FwYw2qtXZo iYiZwYL6lCxYBzeABxSTcBe2zGcXxPID0/+ct/963iVT/mo8Bjt3ouG0RezfPq4/dvGZ b2exmGXSLmyHuTS4xrhFIPBSgITTZ8sWd7mkVjwnRRPIjLkDspySQJCOINtnLca0JFE+ 2ocQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m8FPURSVIVvEdpD8ZPXgZ14T7rJBShKZfZ2+Nl9B7eQ=; b=I1+kjyeiAALUyZuI5tpxQbkiFbs4VjOoCHOWnyU8fMUpH4+RnrBacfMFjVy4XuOzJ1 QHIMTLBC79zBBGKhNAuTXXHfsc5GwOAp7nEBwU/Ws2uI8MIkD1XOD8pEGtv5OV8t4Fc3 2K59TJhjRK0JyJ43V1LoZQ0DzdDZWXxPKTc5zIcG6EyMcRRNdLEN/ctxlVF6mYTgCvWQ lOM3yxyzb9Wvh1qtutyEXS1BEhrIF8y+efUnhvfxwyLEfUCeupuNDtr7zOs9T3BJ0vML Vrh1mg0aWISWzejRgTzvkVDTFSrsoX7j5yK8qVcEMf7tqrqRQX/rTigcx9gqjwsMBVZ6 bRQw== X-Gm-Message-State: ANhLgQ2yx9OUNy/wXkBGlayO3p+QaFhhoxDAvCtEXU5zDc3GS7LLXwyr rkcbli7oOsXP26Y5m/M19fhHcT0SjG4= X-Google-Smtp-Source: ADFU+vuhE150vNDc8iRvCOHy4ha7zulnt8T+T/juG0xavcN0hDsY35Pu7Hbh3RooHnO9SaVdRBxSzA== X-Received: by 2002:a17:90a:8a08:: with SMTP id w8mr668226pjn.119.1585332450672; Fri, 27 Mar 2020 11:07:30 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id p70sm4213170pjp.47.2020.03.27.11.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 11:07:30 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, clyon@gcc.gnu.org, jakub@gcc.gnu.org, pinskia@gcc.gnu.org, richard.guenther@gmail.com Subject: [PATCH 2/2] Fix alignment for local variable [PR90811] Date: Sat, 28 Mar 2020 02:06:56 +0800 Message-Id: <20200327180656.83131-2-kito.cheng@sifive.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200327180656.83131-1-kito.cheng@sifive.com> References: <20200327180656.83131-1-kito.cheng@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-27.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kito Cheng Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" - The alignment for local variable was adjust during estimate_stack_frame_size, however it seems wrong spot to adjust that, expand phase will adjust that but it little too late to some gimple optimization, which rely on certain target hooks need to check alignment, forwprop is an example for that, result of simplify_builtin_call rely on the alignment on some target like ARM or RISC-V. - So we must adjust at some point, and here is already a pass to adjust alignment, which is ipa-increase-alignment, used for tree vectorization. - This patch fix gfortran.dg/pr45636.f90 for arm and riscv. - Regression test on riscv32/riscv64 and x86_64-linux-gnu, no new fail introduced. gcc/ChangeLog PR target/90811 * ipa-increase-alignment.cc (increase_alignment_local_var): New. (increase_alignment_global_var): New. (pass_ipa_increase_alignment::gate): Remove. --- gcc/ipa-increase-alignment.cc | 45 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/gcc/ipa-increase-alignment.cc b/gcc/ipa-increase-alignment.cc index 6e34124bc03..8f28ad83349 100644 --- a/gcc/ipa-increase-alignment.cc +++ b/gcc/ipa-increase-alignment.cc @@ -148,10 +148,35 @@ get_vec_alignment_for_type (tree type) return (alignment > TYPE_ALIGN (type)) ? alignment : 0; } -/* Entry point to increase_alignment pass. */ -static unsigned int -increase_alignment (void) +/* Adjust alignment for local variable. */ +static void +increase_alignment_local_var (void) +{ + size_t i; + tree var; + struct cgraph_node *node; + unsigned int align; + + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node) + { + function *fun = node->get_fun (); + FOR_EACH_LOCAL_DECL (fun, i, var) + { + align = LOCAL_DECL_ALIGNMENT (var); + + SET_DECL_ALIGN (var, align); + } + } +} + +/* Adjust alignment for global variable, only used for tree vectorization + currently. */ +static void +increase_alignment_global_var (void) { + if (!(flag_section_anchors && flag_tree_loop_vectorize)) + return; + varpool_node *vnode; vect_location = dump_user_location_t (); @@ -178,6 +203,14 @@ increase_alignment (void) } delete type_align_map; +} + +/* Entry point to increase_alignment pass. */ +static unsigned int +increase_alignment (void) +{ + increase_alignment_local_var (); + increase_alignment_global_var (); return 0; } @@ -204,12 +237,6 @@ public: : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt) {} - /* opt_pass methods: */ - virtual bool gate (function *) - { - return flag_section_anchors && flag_tree_loop_vectorize; - } - virtual unsigned int execute (function *) { return increase_alignment (); } }; // class pass_ipa_increase_alignment