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: 71150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp215151wrt; Fri, 17 Mar 2023 01:29:14 -0700 (PDT) X-Google-Smtp-Source: AK7set83eo1BOhgjQ+fhjGddyS/ws4U7+3XwdyAB7Ws+LpcWKRY4MEvbdSn1u2bFzJ47ISWTTlH2 X-Received: by 2002:a17:906:b147:b0:87b:d60a:fcbb with SMTP id bt7-20020a170906b14700b0087bd60afcbbmr15020471ejb.47.1679041754161; Fri, 17 Mar 2023 01:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679041754; cv=none; d=google.com; s=arc-20160816; b=BUFcyjmLH3YOJjQKlz0E/tU35glXAGqfvpLFay1LemYHAPk6z2xoaLqtx5fJz3sdZ+ YbJDiQK/8Iwe+1E6Nu+Ar0gkFHt9hOPFPlroG1EHw91ItEYAjXpsFBQN0997R/4BRBJR syYr/KB+z2TbXVfhkPBvFWU3bZAjWWg5WJWqvrF3LRtixzdN/0Gze67B9YTmFuoPY31Y pV/R37anSDFrHbawhthuiKWNk4sSr7DNT/3E9TEI1MXhL044D49Bjyp8k4ODmzUBMuMK 3MZwp4tOAtb2fOVNXa/OTgJ/skq8irW12nC7zCxNa5r7lQc+Qnn3uP85jnnAin3SH4Le aBqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=31fw+yZzhfNYaSlvnV3CD5h1wl0SKfEznxhpyki8OYE=; b=qOpJ2Q1+hhM3F+9hqIVbJt2HT0WhSBddqrZdJFs9kzEzRcYD7OJzb7VI+IWE7q6il1 y0pYrXg1A6Z9t6yE8WZ4sLfVho0ITS8Ze862iwGBLqri637csqyaVpmmsEYXTTO2wKR2 9GBk0pqv/BuAYeptx4wldHrKmDaVoPqalGEkppTuPUbvvt8Kd04p3c1sHd7/QO9kBZHG kdhXk7/3o24aCxzKMOmmitNthdq/Cb61S6KOj9ap+a9T22RJLAHJrSISaxFkhQFYWo3G x5SlqjgSgu9qbQqUGt/mJoSdyHJ2GNGRCw3uRF2XqFH/3Kxt9FTKVNpKxA6mm4AL0mLE Ifhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s2qTstMY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id md5-20020a170906ae8500b008e3da5c56f4si1621349ejb.485.2023.03.17.01.29.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 01:29:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s2qTstMY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAD6D385482E for ; Fri, 17 Mar 2023 08:29:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAD6D385482E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679041753; 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=s2qTstMYM14O+sGPggSW+q2fGdH53C+xz13LouFiQIXLCzD4cdB0KU8IW2O2+vlDk zpqbzv+Zj2DaGx37dFnqDcfLfxAz4zBcKlRENTiwEG5pNacM/WVuVv4atSmIcNdjkw X65ada63SnrJBDQbzGzbTZXncYbIyjA/5mLHqNkc= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760602886463931533?= X-GMAIL-MSGID: =?utf-8?q?1760602886463931533?= 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) +{ +}