From patchwork Wed Sep 11 12:55:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1983949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MTitrxlW; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=hMOVUYTF; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MTitrxlW; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=hMOVUYTF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3gYf6Cytz1y1C for ; Wed, 11 Sep 2024 22:56:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76B003858406 for ; Wed, 11 Sep 2024 12:56:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 920B83858C52 for ; Wed, 11 Sep 2024 12:55:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 920B83858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 920B83858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726059360; cv=none; b=Ol2Azroych9AluZtXLtX5J2EWNWeIe2EVkwMbldSIUKSVsuuh0wdy8oGetX2U4j96DByyWLHihATDukyNoWqAzfieobJn71eOcv7s20L704cDCVUTmwvmWVNyO/EV/VIeNASeG1sAoEl5RQ6XmCSMdzwbyMKFiILt3sFWRXAGiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726059360; c=relaxed/simple; bh=UACvNJiyJN1mx2ikpPhtXLqSF0fk6gM470fUm4cA1N8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=qVoqMOGI8g+P5M+nj/OqwixzzJROFBFrnaQvVfhKqysn8dUzkeUY/giknyQr7iSR7fAShkG6omELh3kGZvkx8vFTm85aRv0hJZ6kTq9P5VFVvmFSCS5plye9uPCFqEedNO880zWaIEO6zfTzbW9He3CDFcnuweVtXel0ZhoM50I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 8E0E91F8AE for ; Wed, 11 Sep 2024 12:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1726059357; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=cE08d6Zf3xZwDzW3WVSqJ4kkWSUteUOj3SmO/sibP3o=; b=MTitrxlWmRTLTIJh5+a8JeO+zFnlAsd/rGipTL5FTK2dMxoGn1D9WCaWWqH20lE/cwpeOq /+gaEULJ+12pPz+89FVqt4+1GooA/EAqsgEVoGBAzjpnk3O6B4Ai5sFQO0626eUd1IvQQU YJht2h/RJmf0pO6S5zt0uCKT7vU5ex4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1726059357; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=cE08d6Zf3xZwDzW3WVSqJ4kkWSUteUOj3SmO/sibP3o=; b=hMOVUYTFfB0afqgp0xPLBYGTOQN1Opq5uF5HDYpStHq5A+SRVj57VkdnScley9osWeoD/R 15ljualz+43KUCBg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1726059357; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=cE08d6Zf3xZwDzW3WVSqJ4kkWSUteUOj3SmO/sibP3o=; b=MTitrxlWmRTLTIJh5+a8JeO+zFnlAsd/rGipTL5FTK2dMxoGn1D9WCaWWqH20lE/cwpeOq /+gaEULJ+12pPz+89FVqt4+1GooA/EAqsgEVoGBAzjpnk3O6B4Ai5sFQO0626eUd1IvQQU YJht2h/RJmf0pO6S5zt0uCKT7vU5ex4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1726059357; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=cE08d6Zf3xZwDzW3WVSqJ4kkWSUteUOj3SmO/sibP3o=; b=hMOVUYTFfB0afqgp0xPLBYGTOQN1Opq5uF5HDYpStHq5A+SRVj57VkdnScley9osWeoD/R 15ljualz+43KUCBg== Date: Wed, 11 Sep 2024 14:55:57 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/116674 - vectorizable_simd_clone_call and re-analysis MIME-Version: 1.0 X-Spam-Score: -1.10 X-Spamd-Result: default: False [-1.10 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.31)[-0.307]; NEURAL_HAM_SHORT(-0.20)[-0.979]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[] X-Spam-Level: X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240911125620.76B003858406@sourceware.org> When SLP analysis scraps an instance because it fails to analyze we can end up calling vectorizable_* in analysis mode on a node that was analyzed during the analysis of that instance again. vectorizable_simd_clone_call wasn't expecting that and instead guarded analysis/transform code on populated data structures. The following changes it so it survives re-analysis. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/116674 * tree-vect-stmts.cc (vectorizable_simd_clone_call): Support re-analysis. * g++.dg/vect/pr116674.cc: New testcase. --- gcc/testsuite/g++.dg/vect/pr116674.cc | 85 +++++++++++++++++++++++++++ gcc/tree-vect-stmts.cc | 8 ++- 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/vect/pr116674.cc diff --git a/gcc/testsuite/g++.dg/vect/pr116674.cc b/gcc/testsuite/g++.dg/vect/pr116674.cc new file mode 100644 index 00000000000..1c13f12290b --- /dev/null +++ b/gcc/testsuite/g++.dg/vect/pr116674.cc @@ -0,0 +1,85 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-additional-options "-Ofast" } +// { dg-additional-options "-march=x86-64-v3" { target { x86_64-*-* i?86-*-* } } } + +namespace std { + typedef int a; + template struct b; + template class aa {}; + template c d(c e, c) { return e; } + template struct b> { + using f = c; + using g = c *; + template using j = aa; + }; +} // namespace std +namespace l { + template struct m : std::b { + typedef std::b n; + typedef typename n::f &q; + template struct ac { typedef typename n::j ad; }; + }; +} // namespace l +namespace std { + template struct o { + typedef typename l::m::ac::ad ae; + typedef typename l::m::g g; + struct p { + g af; + }; + struct ag : p { + ag(ae) {} + }; + typedef ab u; + o(a, u e) : ah(e) {} + ag ah; + }; + template > class r : o { + typedef o s; + typedef typename s::ae ae; + typedef l::m w; + + public: + c f; + typedef typename w::q q; + typedef a t; + typedef ab u; + r(t x, u e = u()) : s(ai(x, e), e) {} + q operator[](t x) { return *(this->ah.af + x); } + t ai(t x, u) { return x; } + }; + extern "C" __attribute__((__simd__)) double exp(double); +} // namespace std +using namespace std; +int ak; +double v, y; +void am(double, int an, double, double, double, double, double, double, double, + double, double, double, int, double, double, double, double, + r ap, double, double, double, double, double, double, double, + double, r ar, r as, double, double, r at, + r au, r av, double, double) { + double ba; + for (int k;;) + for (int i; i < an; ++i) { + y = i; + v = d(y, 25.0); + ba = exp(v); + ar[i * (ak + 1)] = ba; + as[i * (ak + 1)] = ar[i * (ak + 1)]; + if (k && ap[k]) { + at[i * (ak + 1)] = av[i * (ak + 1)] = as[i * (ak + 1)]; + au[i * (ak + 1)] = ar[i * (ak + 1)]; + } else { + au[i * (ak + 1)] = ba; + at[i * (ak + 1)] = av[i * (ak + 1)] = k; + } + } +} +void b(int bc) { + double bd, be, bf, bg, bh, ao, ap, bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, + by, aq, ar, as, bz, ca, at, au, av, cb, aw; + int bi; + am(bh, bc, bi, bi, bi, bi, bv, bw, bx, by, bu, bt, bi, ao, bn, bo, bp, ap, bq, + br, bs, bd, be, bf, bg, aq, ar, as, bz, ca, at, au, av, cb, aw); +} diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 22d50263cdd..1d919ad2516 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -3987,6 +3987,8 @@ vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info, vec& simd_clone_info = (slp_node ? SLP_TREE_SIMD_CLONE_INFO (slp_node) : STMT_VINFO_SIMD_CLONE_INFO (stmt_info)); + if (!vec_stmt) + simd_clone_info.truncate (0); arginfo.reserve (nargs, true); auto_vec slp_op; slp_op.safe_grow_cleared (nargs); @@ -4035,10 +4037,10 @@ vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info, /* For linear arguments, the analyze phase should have saved the base and step in {STMT_VINFO,SLP_TREE}_SIMD_CLONE_INFO. */ - if (i * 3 + 4 <= simd_clone_info.length () + if (vec_stmt + && i * 3 + 4 <= simd_clone_info.length () && simd_clone_info[i * 3 + 2]) { - gcc_assert (vec_stmt); thisarginfo.linear_step = tree_to_shwi (simd_clone_info[i * 3 + 2]); thisarginfo.op = simd_clone_info[i * 3 + 1]; thisarginfo.simd_lane_linear @@ -4093,7 +4095,7 @@ vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info, unsigned group_size = slp_node ? SLP_TREE_LANES (slp_node) : 1; unsigned int badness = 0; struct cgraph_node *bestn = NULL; - if (simd_clone_info.exists ()) + if (vec_stmt) bestn = cgraph_node::get (simd_clone_info[0]); else for (struct cgraph_node *n = node->simd_clones; n != NULL;