From patchwork Tue Mar 31 08:32:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1264592 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=2620:52:3:1:0:246e:9693:128c; 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=hfsLw/Xc; dkim-atps=neutral Received: from sourceware.org (unknown [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 48s2f9203Xz9sQt for ; Tue, 31 Mar 2020 19:33:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06215385DC00; Tue, 31 Mar 2020 08:33:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by sourceware.org (Postfix) with ESMTPS id 5B2F4385DC07 for ; Tue, 31 Mar 2020 08:33:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5B2F4385DC07 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-pf1-x441.google.com with SMTP id h72so10017295pfe.4 for ; Tue, 31 Mar 2020 01:33:13 -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:mime-version :content-transfer-encoding; bh=FqF0TIPh6wz3F2sGdHphFuCA+yrXGVPjtoZakhlKn44=; b=hfsLw/XcWF57Vc+FEVyAZ1yTYXs79dgteL/ToNSC5uKOyqy8lNM0DuJyWue20P5D7H rBRj8KDiRGQKSS/bRpZDuOINgeJMW5QYAXEGn8ZaFJGwLKTh/Js8AE2pTJvjXFw08bZG mH+K6AFYX+Tjao7vpx6l9jbLykGaAOvdOhAScyWodqgi9xjlB7RDg6OgXVRhdI1HEEYg dvbh7gVdb94ll7ZKJ2tpKayfcSHnILV5FAO7cuCvQ/5V1+7n40LJUNssatKtQQ1m0P0C C7SRl0681nUSXEuC1QKj2SDbyQdux0aQS18iuwSvttuog30kTEcQNAMVu1iT0fY05M8O tejw== 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:mime-version :content-transfer-encoding; bh=FqF0TIPh6wz3F2sGdHphFuCA+yrXGVPjtoZakhlKn44=; b=O80IjKH1heQdq/Uc3ALBdPZLYSLJiMG9Y1fR6wGHtGVfD/ud8AdTDSV5JfcwcFF3pr EQcMuWjAqaHPBq79WXJ1UiSQWD1zdxV5PszNXoFYshEYwvOM1cVa0S/HOe2dOjkU16Qm 30yu8uNkTnbDUM6dTroS3UXrx0aNVvi14hreMoT/6nXJ1j4QHv433tG+4NBgrRcx7YCA rnU5jkGWgITBRj/bZ022SQwK+mNvRRSBPBD13ZYpgNMAEIrsX54bz9Ccv8wBChyQ4FNk 1rQgaCkgzsZcbsF7GtDrHhqnpgbQbn6x+SXWM8bWvAHMfqREPCiUXFb6lDDp5MZc2UAG P6SA== X-Gm-Message-State: ANhLgQ24IwjlNclDBTSvWNqzhpPCqdwzDEkbjkFxDvhE9kNZ2ZZPSiPG CoIbhyekid8MyJGKmnf9KpWfDkcvVWXudw== X-Google-Smtp-Source: ADFU+vuKO1smLM8NwzZOJfw787mNnGsEQlbsQliC2bR5OHCTb1IgPucvrwP+0VRtjGWBXj4ruXvWCA== X-Received: by 2002:a62:2e42:: with SMTP id u63mr17409245pfu.69.1585643591895; Tue, 31 Mar 2020 01:33:11 -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 i124sm11918140pfg.14.2020.03.31.01.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 01:33:11 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jakub@gcc.gnu.org, pinskia@gcc.gnu.org, richard.guenther@gmail.com Subject: [PATCH v3] Fix alignment for local variable [PR90811] Date: Tue, 31 Mar 2020 16:32:53 +0800 Message-Id: <20200331083253.7294-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.25.2 MIME-Version: 1.0 X-Spam-Status: No, score=-27.2 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, KAM_SHORT, 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. - 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 * Makefile.in (OBJS): Add tree-adjust-alignment.o. * tree-adjust-alignment.cc (pass_data_adjust_alignment): New. (pass_adjust_alignment): New. (-pass_adjust_alignment::execute): New. (make_pass_adjust_alignment): New. * tree-pass.h (make_pass_adjust_alignment): New. * passes.def: Add pass_adjust_alignment. --- gcc/Makefile.in | 1 + gcc/passes.def | 1 + gcc/tree-adjust-alignment.cc | 88 ++++++++++++++++++++++++++++++++++++ gcc/tree-pass.h | 1 + 4 files changed, 91 insertions(+) create mode 100644 gcc/tree-adjust-alignment.cc diff --git a/gcc/Makefile.in b/gcc/Makefile.in index fa9923bb270..9b73288f776 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1545,6 +1545,7 @@ OBJS = \ ubsan.o \ sanopt.o \ sancov.o \ + tree-adjust-alignment.o \ tree-call-cdce.o \ tree-cfg.o \ tree-cfgcleanup.o \ diff --git a/gcc/passes.def b/gcc/passes.def index 2bf2cb78fc5..92cbe587a8a 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -183,6 +183,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_oacc_device_lower); NEXT_PASS (pass_omp_device_lower); NEXT_PASS (pass_omp_target_link); + NEXT_PASS (pass_adjust_alignment); NEXT_PASS (pass_all_optimizations); PUSH_INSERT_PASSES_WITHIN (pass_all_optimizations) NEXT_PASS (pass_remove_cgraph_callee_edges); diff --git a/gcc/tree-adjust-alignment.cc b/gcc/tree-adjust-alignment.cc new file mode 100644 index 00000000000..1269f93e56a --- /dev/null +++ b/gcc/tree-adjust-alignment.cc @@ -0,0 +1,88 @@ +/* Adjust alignment for local variable. + Copyright (C) 2003-2020 Free Software Foundation, Inc. + Contributed by Dorit Naishlos + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "target.h" +#include "tree.h" +#include "gimple.h" +#include "tree-pass.h" +#include "cgraph.h" +#include "fold-const.h" +#include "gimple-iterator.h" +#include "tree-cfg.h" +#include "cfgloop.h" +#include "tree-vectorizer.h" +#include "tm_p.h" + +namespace { + +const pass_data pass_data_adjust_alignment = +{ + GIMPLE_PASS, /* type */ + "adjust_alignment", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_NONE, /* tv_id */ + 0, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_adjust_alignment : public gimple_opt_pass +{ +public: + pass_adjust_alignment (gcc::context *ctxt) + : gimple_opt_pass (pass_data_adjust_alignment, ctxt) + {} + + virtual unsigned int execute (function *); + +}; // class pass_adjust_alignment + +} // anon namespace + +/* Entry point to adjust_alignment pass. */ +unsigned int +pass_adjust_alignment::execute (function *fun) { + size_t i; + tree var; + struct cgraph_node *node; + unsigned int align; + + FOR_EACH_LOCAL_DECL (fun, i, var) + { + align = LOCAL_DECL_ALIGNMENT (var); + + gcc_assert (align >= DECL_ALIGN (var)); + + SET_DECL_ALIGN (var, align); + } + return 0; +} + +gimple_opt_pass * +make_pass_adjust_alignment (gcc::context *ctxt) +{ + return new pass_adjust_alignment (ctxt); +} diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index a1207a20a3c..576b3f67434 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -480,6 +480,7 @@ extern gimple_opt_pass *make_pass_sprintf_length (gcc::context *ctxt); extern gimple_opt_pass *make_pass_walloca (gcc::context *ctxt); extern gimple_opt_pass *make_pass_coroutine_lower_builtins (gcc::context *ctxt); extern gimple_opt_pass *make_pass_coroutine_early_expand_ifns (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_adjust_alignment (gcc::context *ctxt); /* IPA Passes */ extern simple_ipa_opt_pass *make_pass_ipa_lower_emutls (gcc::context *ctxt);