From patchwork Fri Mar 17 17:47:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 71378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp476363wrt; Fri, 17 Mar 2023 10:48:17 -0700 (PDT) X-Google-Smtp-Source: AK7set+QH5SC/4Glw//+g93HU0q01ogeybfbzCKIHKywc6QBRlqVYBrV5GKsLUetgSFGnLQi6HWQ X-Received: by 2002:aa7:c752:0:b0:4fa:733f:8abb with SMTP id c18-20020aa7c752000000b004fa733f8abbmr4091789eds.32.1679075296884; Fri, 17 Mar 2023 10:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679075296; cv=none; d=google.com; s=arc-20160816; b=IHfN4xsr0yc7q8xk0Ycm8Jmh0C0fPCdQg/J2uFGmEExhjYoU4iyKPlMBm/5MEkZrkR SNocG+wNxcFPsYmNKK2XrdoMfKgA/CkvkkPi5VxhLfEJYXXZDyI4+NRhFNkEzt7iAXAB XQ1aWANS7e9LRdmGxJlwihi5K+Gnut1j2zCTvgBgFgoVOsVWqdEEdda4dVXc1q+ClIXp rbX7J0afcX7qhY1AuZMcieD6o06t+6KIUbZFJn+fTHMgqfWrnrS78EyS4DIFDeR4WrBB pxMrndWjG+8EWGQ73jBLE7Bcb6VAHXobqHB1U2YovqZc6lbrs4k7tJ+szA6M2qwirEYA RA8Q== 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=nxXkVWjc2XGQ/KNNnwF7U61q8tZfgP2U4zz93An6vNY=; b=INMTTXJSnj50ZL3H/A8SFRvUKYboHLXqtWvwa3iVlOZWPA0Ci/OAiLbh2GfvGZoMqE ndQyg4SB9TPwQ/7fmOssfZK7IQpZQO7b6DmfSy6is6C7F5RpkaFcBnWQjO5bp3VtzQJL LvC0h49I6H8tNaGBH1VjjnP7/YC7OVX9xZiq2KWH8oXPg/A4dJnJGac0j0Ra5xPROc+m y6Htz8TiNSGrhTU1idXoXYMizX9TxNKe5ayaH9gl2th6OMErXP75lX83DWKR44iDtLQj eJfwChsuB+vSb1aTiToyzOU/Ib3Vd/H8ErOWC1FR1/Kos4jS+OXN1H6abnxy5MTXLJQF 7mpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=etBmvpmP; 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 c20-20020a056402101400b004fd2a8b4b39si2910636edu.501.2023.03.17.10.48.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 10:48:16 -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=etBmvpmP; 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 AC6053850854 for ; Fri, 17 Mar 2023 17:48:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC6053850854 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679075295; bh=nxXkVWjc2XGQ/KNNnwF7U61q8tZfgP2U4zz93An6vNY=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=etBmvpmP/sWDYlWN7UxIb+dyfZ4ie8jpLC8eGlsL9ox+3J8lv3tVakd3SoiigzwGm Ve5F8Jwf8DH1bD0dHB+mtDEykL3gS6aKUFGUVTxOPIe59t0IJu8ZalY/+kYWdHFbHq ZteExesm+f0Bk4P5z1lvdjMXtsKsCZhzskiXM4Is= 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 2D877385559F for ; Fri, 17 Mar 2023 17:47:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D877385559F Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-584-2u2RS43CPGyfE5_FaFrrNQ-1; Fri, 17 Mar 2023 13:47:24 -0400 X-MC-Unique: 2u2RS43CPGyfE5_FaFrrNQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2DD31100DEAF; Fri, 17 Mar 2023 17:47:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E11AAC15BA0; Fri, 17 Mar 2023 17:47:23 +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 32HHlLAg3137286 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 17 Mar 2023 18:47:21 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32HHlKFS3137285; Fri, 17 Mar 2023 18:47:20 +0100 Date: Fri, 17 Mar 2023 18:47:20 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-inline: Fix up multiversioning with vector arguments [PR105554] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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?1760638058779575378?= X-GMAIL-MSGID: =?utf-8?q?1760638058779575378?= Hi! The following testcase ICEs, because we call tree_function_versioning from old_decl which has target attributes not supporting V4DImode and so DECL_MODE of DECL_ARGUMENTS is BLKmode, while new_decl supports those. tree_function_versioning initially copies DECL_RESULT and DECL_ARGUMENTS from old_decl to new_decl, then calls initialize_cfun to create cfun and only when the cfun is created it can later actually remap_decl DECL_RESULT and DECL_ARGUMENTS etc. The problem is that initialize_cfun -> push_struct_function -> allocate_struct_function calls relayout_decl on DECL_RESULT and DECL_ARGUMENTS, which clobbers DECL_MODE of old_decl and we then ICE because of it. In particular, allocate_struct_function does: if (!abstract_p) { /* Now that we have activated any function-specific attributes that might affect layout, particularly vector modes, relayout each of the parameters and the result. */ relayout_decl (result); for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm)) relayout_decl (parm); /* Similarly relayout the function decl. */ targetm.target_option.relayout_function (fndecl); } if (!abstract_p && aggregate_value_p (result, fndecl)) { #ifdef PCC_STATIC_STRUCT_RETURN cfun->returns_pcc_struct = 1; #endif cfun->returns_struct = 1; } Now, in the case of tree_function_versioning, I believe all that we need from these is possibly the targetm.target_option.relayout_function (fndecl); call (arm only), we will remap DECL_RESULT and DECL_ARGUMENTS later on and copy_decl_for_dup_finish in that case will handle all we need: /* For vector typed decls make sure to update DECL_MODE according to the new function context. */ if (VECTOR_TYPE_P (TREE_TYPE (copy))) SET_DECL_MODE (copy, TYPE_MODE (TREE_TYPE (copy))); We don't need the cfun->returns_*struct either, because we override it in initialize_cfun a few lines later: /* Copy items we preserve during cloning. */ ... cfun->returns_struct = src_cfun->returns_struct; cfun->returns_pcc_struct = src_cfun->returns_pcc_struct; So, to avoid the clobbering of DECL_RESULT/DECL_ARGUMENTS of old_decl, the following patch arranges allocate_struct_function to be called with abstract_p true and calls targetm.target_option.relayout_function (fndecl); by hand. The removal of DECL_RESULT/DECL_ARGUMENTS copying at the start of initialize_cfun is removed because the only caller - tree_function_versioning, does that unconditionally before. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-17 Jakub Jelinek PR target/105554 * function.h (push_struct_function): Add ABSTRACT_P argument defaulted to false. * function.cc (push_struct_function): Add ABSTRACT_P argument, pass it to allocate_struct_function instead of false. * tree-inline.cc (initialize_cfun): Don't copy DECL_ARGUMENTS nor DECL_RESULT here. Pass true as ABSTRACT_P to push_struct_function. Call targetm.target_option.relayout_function after it. (tree_function_versioning): Formatting fix. * gcc.target/i386/pr105554.c: New test. Jakub --- gcc/function.h.jj 2023-01-12 21:04:08.647239183 +0100 +++ gcc/function.h 2023-03-17 10:47:27.489571469 +0100 @@ -687,7 +687,7 @@ extern void pop_cfun (void); extern int get_next_funcdef_no (void); extern int get_last_funcdef_no (void); extern void allocate_struct_function (tree, bool); -extern void push_struct_function (tree fndecl); +extern void push_struct_function (tree fndecl, bool = false); extern void push_dummy_function (bool); extern void pop_dummy_function (void); extern void init_dummy_function_start (void); --- gcc/function.cc.jj 2023-01-14 10:00:20.308560059 +0100 +++ gcc/function.cc 2023-03-17 10:48:10.009945483 +0100 @@ -4891,7 +4891,7 @@ allocate_struct_function (tree fndecl, b instead of just setting it. */ void -push_struct_function (tree fndecl) +push_struct_function (tree fndecl, bool abstract_p) { /* When in_dummy_function we might be in the middle of a pop_cfun and current_function_decl and cfun may not match. */ @@ -4900,7 +4900,7 @@ push_struct_function (tree fndecl) || (cfun && current_function_decl == cfun->decl)); cfun_stack.safe_push (cfun); current_function_decl = fndecl; - allocate_struct_function (fndecl, false); + allocate_struct_function (fndecl, abstract_p); } /* Reset crtl and other non-struct-function variables to defaults as --- gcc/tree-inline.cc.jj 2023-01-19 09:58:51.037226790 +0100 +++ gcc/tree-inline.cc 2023-03-17 10:56:50.321285330 +0100 @@ -2781,16 +2781,12 @@ initialize_cfun (tree new_fndecl, tree c { struct function *src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl); - if (!DECL_ARGUMENTS (new_fndecl)) - DECL_ARGUMENTS (new_fndecl) = DECL_ARGUMENTS (callee_fndecl); - if (!DECL_RESULT (new_fndecl)) - DECL_RESULT (new_fndecl) = DECL_RESULT (callee_fndecl); - /* Register specific tree functions. */ gimple_register_cfg_hooks (); /* Get clean struct function. */ - push_struct_function (new_fndecl); + push_struct_function (new_fndecl, true); + targetm.target_option.relayout_function (new_fndecl); /* We will rebuild these, so just sanity check that they are empty. */ gcc_assert (VALUE_HISTOGRAMS (cfun) == NULL); @@ -6235,8 +6231,7 @@ tree_function_versioning (tree old_decl, id.transform_return_to_modify = false; id.transform_parameter = false; - old_entry_block = ENTRY_BLOCK_PTR_FOR_FN - (DECL_STRUCT_FUNCTION (old_decl)); + old_entry_block = ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (old_decl)); DECL_RESULT (new_decl) = DECL_RESULT (old_decl); DECL_ARGUMENTS (new_decl) = DECL_ARGUMENTS (old_decl); initialize_cfun (new_decl, old_decl, --- gcc/testsuite/gcc.target/i386/pr105554.c.jj 2023-03-17 10:11:38.998223934 +0100 +++ gcc/testsuite/gcc.target/i386/pr105554.c 2023-03-17 10:11:38.998223934 +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) +{ +}