From patchwork Fri Mar 27 18:06:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1262909 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=hMqCLAjK; 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 48pqZ81Dl2z9sNg for ; Sat, 28 Mar 2020 05:07:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB5E9385E01C; Fri, 27 Mar 2020 18:07:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 29EB8385E01C for ; Fri, 27 Mar 2020 18:07:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 29EB8385E01C 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-x42e.google.com with SMTP id 23so4880641pfj.1 for ; Fri, 27 Mar 2020 11:07:04 -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=lP6b/ONcK7FdQTzIwbCPoMlo3R9/M1IY3nyay+mW+io=; b=hMqCLAjK4iUqIxUffyqZDv/0nIsLx6AznwqME1FoOTfzPURMlz55cySAP+7/c7575S giqGVCDn8CF6uSy/Bdu3ur0kXU0n0NNKzFx9yEjv1r4yIobhHPBzF9Zv2SB+J7OcKzJP BFpuO00YWIStrbRHG2qIDxDfsxlRcuPVnR0jyzunCEcZlzVqAslrbEWJceeHo9eOrHig K5hEoXva7g/78+z/YbhBKbaRmRm8a14PzFgF3txauCPlOObV8F5bEPjNCfSQdO7JqtnB mqPrFpcxcK2NdUKd/O5jGxFyBTi98DlQF51mDygnf7TKb2CZqzgnR8Qna/aJJyMaVWIq zh1g== 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=lP6b/ONcK7FdQTzIwbCPoMlo3R9/M1IY3nyay+mW+io=; b=dthtgwNbtFNnaWhLbM3rdqY54put+20kzL5OOU5BHkFa3GtJWML5eseMchXKafIqae z35A3kguywFOuCxhpCtvPQkLiE88CqnGSMIH8fb7mVvMJZ0diVf+TcFeOXYxcgcjpVX9 VckfV9czefp2R80w0sh5jZ1GNZwFQOZ/w3Vd85nIPIP6Op9+pf0FOuK6WUl+uwRKgBMR ALXWDQOv2zWUKFDwHaCTX8qbs3fzJsJowQmj/ad1Ju4Hrdmar07yIndW4MfQILd+h067 22j3yRKWNvDLKRLcOLWb3c1Tw4XEXfyRN9itNTS1r2pwiah7SP9Qdvl2Pou+GDRvMkxI +41Q== X-Gm-Message-State: ANhLgQ37+o42krt7QRcuSoQiypeupi4cAUQ4WyhH6XXgiB0hCOBVmg1s xu41EanVtGzGYelSJLFkaZU9d1nCgB0= X-Google-Smtp-Source: ADFU+vt9iuJtlS49HddWYKWpfae8ijk6tLlLK6cAdY8ZSmp6hbB3eme5mMGXHNC7SJi8tOcAxlNa+Q== X-Received: by 2002:a63:82c6:: with SMTP id w189mr464931pgd.357.1585332422570; Fri, 27 Mar 2020 11:07:02 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 11:07:01 -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 1/2] Move out increase_alignment into ipa-increase-alignment.cc Date: Sat, 28 Mar 2020 02:06:55 +0800 Message-Id: <20200327180656.83131-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.25.2 MIME-Version: 1.0 X-Spam-Status: No, score=-29.7 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" - This patch is prepare for add more logic into increase_alignment pass, which is not related to vectorization. gcc/ChangeLog * Makefile.in (OBJS): Add ipa-increase-alignment.o. * tree-vectorizer.c (get_vec_alignment_for_type): Moved to ipa-increase-alignment.cc. (type_align_map): Ditto. (get_vec_alignment_for_array_type): Ditto. (get_vec_alignment_for_record_type): Ditto. (increase_alignment): Ditto. (pass_data_ipa_increase_alignment): Ditto. (pass_ipa_increase_alignment): Ditto. (make_pass_ipa_increase_alignment): Ditto. * ipa-increase-alignment.cc (get_vec_alignment_for_type) Moved from ipa-increase-alignment.cc. (type_align_map): Ditto. (get_vec_alignment_for_array_type): Ditto. (get_vec_alignment_for_record_type): Ditto. (increase_alignment): Ditto. (pass_data_ipa_increase_alignment): Ditto. (pass_ipa_increase_alignment): Ditto. (make_pass_ipa_increase_alignment): Ditto. --- gcc/Makefile.in | 1 + gcc/ipa-increase-alignment.cc | 223 ++++++++++++++++++++++++++++++++++ gcc/tree-vectorizer.c | 189 ---------------------------- 3 files changed, 224 insertions(+), 189 deletions(-) create mode 100644 gcc/ipa-increase-alignment.cc diff --git a/gcc/Makefile.in b/gcc/Makefile.in index fa9923bb270..2c11252911c 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1408,6 +1408,7 @@ OBJS = \ ipa-inline.o \ ipa-comdats.o \ ipa-visibility.o \ + ipa-increase-alignment.o \ ipa-inline-analysis.o \ ipa-inline-transform.o \ ipa-predicate.o \ diff --git a/gcc/ipa-increase-alignment.cc b/gcc/ipa-increase-alignment.cc new file mode 100644 index 00000000000..6e34124bc03 --- /dev/null +++ b/gcc/ipa-increase-alignment.cc @@ -0,0 +1,223 @@ +/* Increase alignment + 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" + +/* Increase alignment of global arrays to improve vectorization potential. + TODO: + - Consider also structs that have an array field. + - Use ipa analysis to prune arrays that can't be vectorized? + This should involve global alignment analysis and in the future also + array padding. */ + +static unsigned get_vec_alignment_for_type (tree); +static hash_map *type_align_map; + +/* Return alignment of array's vector type corresponding to scalar type. + 0 if no vector type exists. */ +static unsigned +get_vec_alignment_for_array_type (tree type) +{ + gcc_assert (TREE_CODE (type) == ARRAY_TYPE); + poly_uint64 array_size, vector_size; + + tree scalar_type = strip_array_types (type); + tree vectype = get_related_vectype_for_scalar_type (VOIDmode, scalar_type); + if (!vectype + || !poly_int_tree_p (TYPE_SIZE (type), &array_size) + || !poly_int_tree_p (TYPE_SIZE (vectype), &vector_size) + || maybe_lt (array_size, vector_size)) + return 0; + + return TYPE_ALIGN (vectype); +} + +/* Return alignment of field having maximum alignment of vector type + corresponding to it's scalar type. For now, we only consider fields whose + offset is a multiple of it's vector alignment. + 0 if no suitable field is found. */ +static unsigned +get_vec_alignment_for_record_type (tree type) +{ + gcc_assert (TREE_CODE (type) == RECORD_TYPE); + + unsigned max_align = 0, alignment; + HOST_WIDE_INT offset; + tree offset_tree; + + if (TYPE_PACKED (type)) + return 0; + + unsigned *slot = type_align_map->get (type); + if (slot) + return *slot; + + for (tree field = first_field (type); + field != NULL_TREE; + field = DECL_CHAIN (field)) + { + /* Skip if not FIELD_DECL or if alignment is set by user. */ + if (TREE_CODE (field) != FIELD_DECL + || DECL_USER_ALIGN (field) + || DECL_ARTIFICIAL (field)) + continue; + + /* We don't need to process the type further if offset is variable, + since the offsets of remaining members will also be variable. */ + if (TREE_CODE (DECL_FIELD_OFFSET (field)) != INTEGER_CST + || TREE_CODE (DECL_FIELD_BIT_OFFSET (field)) != INTEGER_CST) + break; + + /* Similarly stop processing the type if offset_tree + does not fit in unsigned HOST_WIDE_INT. */ + offset_tree = bit_position (field); + if (!tree_fits_uhwi_p (offset_tree)) + break; + + offset = tree_to_uhwi (offset_tree); + alignment = get_vec_alignment_for_type (TREE_TYPE (field)); + + /* Get maximum alignment of vectorized field/array among those members + whose offset is multiple of the vector alignment. */ + if (alignment + && (offset % alignment == 0) + && (alignment > max_align)) + max_align = alignment; + } + + type_align_map->put (type, max_align); + return max_align; +} + +/* Return alignment of vector type corresponding to decl's scalar type + or 0 if it doesn't exist or the vector alignment is lesser than + decl's alignment. */ +static unsigned +get_vec_alignment_for_type (tree type) +{ + if (type == NULL_TREE) + return 0; + + gcc_assert (TYPE_P (type)); + + static unsigned alignment = 0; + switch (TREE_CODE (type)) + { + case ARRAY_TYPE: + alignment = get_vec_alignment_for_array_type (type); + break; + case RECORD_TYPE: + alignment = get_vec_alignment_for_record_type (type); + break; + default: + alignment = 0; + break; + } + + return (alignment > TYPE_ALIGN (type)) ? alignment : 0; +} + +/* Entry point to increase_alignment pass. */ +static unsigned int +increase_alignment (void) +{ + varpool_node *vnode; + + vect_location = dump_user_location_t (); + type_align_map = new hash_map; + + /* Increase the alignment of all global arrays for vectorization. */ + FOR_EACH_DEFINED_VARIABLE (vnode) + { + tree decl = vnode->decl; + unsigned int alignment; + + if ((decl_in_symtab_p (decl) + && !symtab_node::get (decl)->can_increase_alignment_p ()) + || DECL_USER_ALIGN (decl) || DECL_ARTIFICIAL (decl)) + continue; + + alignment = get_vec_alignment_for_type (TREE_TYPE (decl)); + if (alignment && vect_can_force_dr_alignment_p (decl, alignment)) + { + vnode->increase_alignment (alignment); + if (dump_enabled_p ()) + dump_printf (MSG_NOTE, "Increasing alignment of decl: %T\n", decl); + } + } + + delete type_align_map; + return 0; +} + + +namespace { + +const pass_data pass_data_ipa_increase_alignment = +{ + SIMPLE_IPA_PASS, /* type */ + "increase_alignment", /* name */ + OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */ + TV_IPA_OPT, /* tv_id */ + 0, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_ipa_increase_alignment : public simple_ipa_opt_pass +{ +public: + pass_ipa_increase_alignment (gcc::context *ctxt) + : 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 + +} // anon namespace + +simple_ipa_opt_pass * +make_pass_ipa_increase_alignment (gcc::context *ctxt) +{ + return new pass_ipa_increase_alignment (ctxt); +} diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c index 8f9444d58a3..e9caf91e174 100644 --- a/gcc/tree-vectorizer.c +++ b/gcc/tree-vectorizer.c @@ -1340,195 +1340,6 @@ make_pass_slp_vectorize (gcc::context *ctxt) return new pass_slp_vectorize (ctxt); } - -/* Increase alignment of global arrays to improve vectorization potential. - TODO: - - Consider also structs that have an array field. - - Use ipa analysis to prune arrays that can't be vectorized? - This should involve global alignment analysis and in the future also - array padding. */ - -static unsigned get_vec_alignment_for_type (tree); -static hash_map *type_align_map; - -/* Return alignment of array's vector type corresponding to scalar type. - 0 if no vector type exists. */ -static unsigned -get_vec_alignment_for_array_type (tree type) -{ - gcc_assert (TREE_CODE (type) == ARRAY_TYPE); - poly_uint64 array_size, vector_size; - - tree scalar_type = strip_array_types (type); - tree vectype = get_related_vectype_for_scalar_type (VOIDmode, scalar_type); - if (!vectype - || !poly_int_tree_p (TYPE_SIZE (type), &array_size) - || !poly_int_tree_p (TYPE_SIZE (vectype), &vector_size) - || maybe_lt (array_size, vector_size)) - return 0; - - return TYPE_ALIGN (vectype); -} - -/* Return alignment of field having maximum alignment of vector type - corresponding to it's scalar type. For now, we only consider fields whose - offset is a multiple of it's vector alignment. - 0 if no suitable field is found. */ -static unsigned -get_vec_alignment_for_record_type (tree type) -{ - gcc_assert (TREE_CODE (type) == RECORD_TYPE); - - unsigned max_align = 0, alignment; - HOST_WIDE_INT offset; - tree offset_tree; - - if (TYPE_PACKED (type)) - return 0; - - unsigned *slot = type_align_map->get (type); - if (slot) - return *slot; - - for (tree field = first_field (type); - field != NULL_TREE; - field = DECL_CHAIN (field)) - { - /* Skip if not FIELD_DECL or if alignment is set by user. */ - if (TREE_CODE (field) != FIELD_DECL - || DECL_USER_ALIGN (field) - || DECL_ARTIFICIAL (field)) - continue; - - /* We don't need to process the type further if offset is variable, - since the offsets of remaining members will also be variable. */ - if (TREE_CODE (DECL_FIELD_OFFSET (field)) != INTEGER_CST - || TREE_CODE (DECL_FIELD_BIT_OFFSET (field)) != INTEGER_CST) - break; - - /* Similarly stop processing the type if offset_tree - does not fit in unsigned HOST_WIDE_INT. */ - offset_tree = bit_position (field); - if (!tree_fits_uhwi_p (offset_tree)) - break; - - offset = tree_to_uhwi (offset_tree); - alignment = get_vec_alignment_for_type (TREE_TYPE (field)); - - /* Get maximum alignment of vectorized field/array among those members - whose offset is multiple of the vector alignment. */ - if (alignment - && (offset % alignment == 0) - && (alignment > max_align)) - max_align = alignment; - } - - type_align_map->put (type, max_align); - return max_align; -} - -/* Return alignment of vector type corresponding to decl's scalar type - or 0 if it doesn't exist or the vector alignment is lesser than - decl's alignment. */ -static unsigned -get_vec_alignment_for_type (tree type) -{ - if (type == NULL_TREE) - return 0; - - gcc_assert (TYPE_P (type)); - - static unsigned alignment = 0; - switch (TREE_CODE (type)) - { - case ARRAY_TYPE: - alignment = get_vec_alignment_for_array_type (type); - break; - case RECORD_TYPE: - alignment = get_vec_alignment_for_record_type (type); - break; - default: - alignment = 0; - break; - } - - return (alignment > TYPE_ALIGN (type)) ? alignment : 0; -} - -/* Entry point to increase_alignment pass. */ -static unsigned int -increase_alignment (void) -{ - varpool_node *vnode; - - vect_location = dump_user_location_t (); - type_align_map = new hash_map; - - /* Increase the alignment of all global arrays for vectorization. */ - FOR_EACH_DEFINED_VARIABLE (vnode) - { - tree decl = vnode->decl; - unsigned int alignment; - - if ((decl_in_symtab_p (decl) - && !symtab_node::get (decl)->can_increase_alignment_p ()) - || DECL_USER_ALIGN (decl) || DECL_ARTIFICIAL (decl)) - continue; - - alignment = get_vec_alignment_for_type (TREE_TYPE (decl)); - if (alignment && vect_can_force_dr_alignment_p (decl, alignment)) - { - vnode->increase_alignment (alignment); - if (dump_enabled_p ()) - dump_printf (MSG_NOTE, "Increasing alignment of decl: %T\n", decl); - } - } - - delete type_align_map; - return 0; -} - - -namespace { - -const pass_data pass_data_ipa_increase_alignment = -{ - SIMPLE_IPA_PASS, /* type */ - "increase_alignment", /* name */ - OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */ - TV_IPA_OPT, /* tv_id */ - 0, /* properties_required */ - 0, /* properties_provided */ - 0, /* properties_destroyed */ - 0, /* todo_flags_start */ - 0, /* todo_flags_finish */ -}; - -class pass_ipa_increase_alignment : public simple_ipa_opt_pass -{ -public: - pass_ipa_increase_alignment (gcc::context *ctxt) - : 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 - -} // anon namespace - -simple_ipa_opt_pass * -make_pass_ipa_increase_alignment (gcc::context *ctxt) -{ - return new pass_ipa_increase_alignment (ctxt); -} - /* If the condition represented by T is a comparison or the SSA name result of a comparison, extract the comparison's operands. Represent T as NE_EXPR otherwise. */ 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