From patchwork Fri Mar 17 08:28:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 66510 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8EBE38582A4 for ; Fri, 17 Mar 2023 08:28:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8EBE38582A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679041734; bh=31fw+yZzhfNYaSlvnV3CD5h1wl0SKfEznxhpyki8OYE=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Ud7pM2iIqqncy9cFstlpaup1tsHUfdI6egXxBvHccidyBIERZJw7OOrpswkXtwcvq LJ7ksCZkK6tkDKdvr0e2EwEwwyFb9ZMpb7bIpTFLcEgX8FQitfacrXF1XV8uEirVOE Ugvm3/zeckscWcHVKYdrXfaPp+jCq4zZ5Yo5+fzg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4EAE03858423 for ; Fri, 17 Mar 2023 08:28:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EAE03858423 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-402-ooMabYtFNVu45JetD6rBQw-1; Fri, 17 Mar 2023 04:28:23 -0400 X-MC-Unique: ooMabYtFNVu45JetD6rBQw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 619A529DD995; Fri, 17 Mar 2023 08:28:23 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1CB1F140EBF4; Fri, 17 Mar 2023 08:28:22 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32H8SKRf902022 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 17 Mar 2023 09:28:20 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32H8SJUX902021; Fri, 17 Mar 2023 09:28:19 +0100 Date: Fri, 17 Mar 2023 09:28:19 +0100 To: Richard Biener , Jan Hubicka , Martin =?utf-8?b?TGnFoWth?= Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] cgraphclones: Fix up target_clones cloning of functions with vector arguments [PR105554] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! multiple_target.cc is the only caller of create_version_clone_with_body which calls it with non-NULL target_attributes. The attributes are finalized soon after new_decl is created and then tree_function_versioning is called. This temporarily sets DECL_RESULT and DECL_ARGUMENTS of new_decl to the ones of old_decl, after all usually we don't have the arguments yet and then it initializes cfun for the new function, so that we can later e.g. remap the arguments which needs the inlining infrastructure and dest_cfun in id. Now, initialize_cfun calls allocate_function which with the new cfun pushed does: 4845 /* Now that we have activated any function-specific attributes 4846 that might affect layout, particularly vector modes, relayout 4847 each of the parameters and the result. */ 4848 relayout_decl (result); 4849 for (tree parm = DECL_ARGUMENTS (fndecl); parm; 4850 parm = DECL_CHAIN (parm)) 4851 relayout_decl (parm); Normally that is the correct thing to do, but because in this case DECL_RESULT and DECL_ARGUMENTs are those from old_decl until we change it, the above actually could have changed DECL_MODE of DECL_RESULT and DECL_ARGUMENTS if any of that has vector type and whether a vector_type_mode differs between the old_decl and new_decl enabled ISAs. I don't have an idea how to cleanly resolve this on the tree_function_versioning side, plus most of the time this isn't a problem because usually tree_function_versioning works between old_decl and new_decl with same target attributes. So, the following patch instead fixes it up afterwards, doing the relayout_decl again on old_decl to restore it back. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-17 Jakub Jelinek PR target/105554 * cgraphclones.cc: Include stor-layout.h. (cgraph_node::create_version_clone_with_body): If target_attributes, relayout DECL_RESULT and DECL_ARGUMENTS of old_decl back after tree_function_versioning. * gcc.target/i386/pr105554.c: New test. Jakub --- gcc/cgraphclones.cc.jj 2023-02-24 11:05:19.704595633 +0100 +++ gcc/cgraphclones.cc 2023-03-16 19:46:14.592006501 +0100 @@ -87,6 +87,7 @@ along with GCC; see the file COPYING3. #include "ipa-fnsummary.h" #include "symtab-thunks.h" #include "symtab-clones.h" +#include "stor-layout.h" /* Create clone of edge in the node N represented by CALL_EXPR the callgraph. */ @@ -1094,6 +1095,19 @@ cgraph_node::create_version_clone_with_b || in_lto_p) new_version_node->unique_name = true; + if (target_attributes) + { + /* tree_function_versioning temporarily copies old_decl's DECL_RESULT + and DECL_ARGUMENTS to new_decl, then allocate_struct_function + which will relayout_decl those. Relayout them back. */ + push_cfun (DECL_STRUCT_FUNCTION (old_decl)); + relayout_decl (DECL_RESULT (old_decl)); + for (tree parm = DECL_ARGUMENTS (old_decl); + parm; parm = DECL_CHAIN (parm)) + relayout_decl (parm); + pop_cfun (); + } + /* Update the call_expr on the edges to call the new version node. */ update_call_expr (new_version_node); --- gcc/testsuite/gcc.target/i386/pr105554.c.jj 2023-03-16 19:50:58.126884823 +0100 +++ gcc/testsuite/gcc.target/i386/pr105554.c 2023-03-16 19:50:25.031365400 +0100 @@ -0,0 +1,10 @@ +/* PR target/105554 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wno-psabi -mno-sse3" } */ + +typedef long long v4di __attribute__((__vector_size__(32))); + +__attribute__((target_clones ("arch=core-avx2", "default"))) void +foo (v4di x) +{ +}