From patchwork Tue Jan 30 10:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 193991 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1132923dyb; Tue, 30 Jan 2024 02:59:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGk7ZHLHhEvEkwYIm5jL8y2zEjVYk5F/Y7+vXUDz4rpzbu4GI7ySRh1s9uVT7s1hWokHaG X-Received: by 2002:a05:620a:468b:b0:785:34fe:876a with SMTP id bq11-20020a05620a468b00b0078534fe876amr9035qkb.15.1706612358450; Tue, 30 Jan 2024 02:59:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706612358; cv=pass; d=google.com; s=arc-20160816; b=wTh456LpXBZB9rDV28jbdemZ14JS3+ahviuMCpnDaoB1pPPAy2GeBCK7rBw+vmXZeo CpTOeu2aIkZOCbG+g5ycmHGR8gmgffr95YopEIeNZmyFRQMgVQg2ufxcGKVwpHXvIXNY m9gb8Crsn09kUrdJZS6yLZN+6q5fpCGkdeDY/CJac8z34ULiDzWsVBRQK5eWmUrelwYO oP5EY8Dt7Z4dZaylTplDRHiqacF4jLEOO53RR4t9uqBEXdXfoBmQ4DX8Bz1L4ckiaOEm wJFDo3EzEwkslb0yRV3SjUG578Nzm9o5axUEieBz3gSiXQgkP4/L1AS09M+YoBP5slZJ 8sZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :subject:to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=8QD/nihOPTkfoHJshwV6dAmgFI2lBG+9sleohd9oU/w=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=WUN4MuA08OpIPZqB1RpUWK3nY1gaih8CZNMiQ8J/JnOCLu3l3TwJCFJ6Vl+B+GSyME lzwB0JXn+FbajYBUcGcg3OVx7pRBzeImfQmHnkP3ClDk2F4GX1FViDsoN0LrTgbPsARy P9cvG/1jje68D21gvhDptOjc45hBLJu71xvRbU3WXw0yTJ9OF+a896dtxs8VjW0lCRoq YxKcEhEAuCmTQfe1coCiQ5mEWvDLqfkFd1/qJRg2CCLa6kM/GB75DTso2/Cufyj9mPY0 Bjp/p1/QTE8+brQoNLu1bF3i2Y08+Uo5+3cQRL0vakxyMjHkyFEiStAG7KePx822wlgz i7TA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=VJR0NxPg; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=CcSTVaaz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l3-20020a37f503000000b007838dfe0156si9620438qkk.255.2024.01.30.02.59.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 02:59:18 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=VJR0NxPg; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=CcSTVaaz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2AB0E3857739 for ; Tue, 30 Jan 2024 10:59:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id B75D03858287 for ; Tue, 30 Jan 2024 10:58:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B75D03858287 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 B75D03858287 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706612314; cv=none; b=h2lBV5scmmfETJ8qLz6yHx2b0TDj/R8Q2dKWn1hlqDLILDar7HdpDCpslTfvVarQ127NP6TfVx5oSiZ3hmQ1LqcnymHh+tzQ9AU2bpS4SKWb8XOzRVdjb3Pz79N8iskH1j8DPiE8qOa0LQ+9I5WA0cZ3VXF7re5yF29+exA+5NE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706612314; c=relaxed/simple; bh=arz9x4S72Dhzna4D4Uebsuer5aZUxm5TGAUDWrsMlc4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=mbEKZdk1kiRK5GOW+fMWKHzGJIpxxkAR+xEiFsWHzOwP5IpZ6k+KEXw0QDXmSgSJefzLHkDyz/uBRRAWg6j14D+xx0TQ4QT322rGnIWlvxOQbWCXDs8FAPYxNIaC0J2Wd0zgt7fCLjFzMngyHe0aZVkrSTrKjljFqqlBKolYK/0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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-out1.suse.de (Postfix) with ESMTPS id A01C9222BF for ; Tue, 30 Jan 2024 10:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706612311; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8QD/nihOPTkfoHJshwV6dAmgFI2lBG+9sleohd9oU/w=; b=VJR0NxPgsykJvAfbhmWHqz3JbPCVOR15z1bMvUAxNpr7a6tLEbj4poBzIvI55GtJU0jrd1 XhCQf59LTFuGkzutrNdZmJTOD1YqK80abeDNlUKkXdoSBmYnaQ5RpVIq2V0oe52Jd6JueT aGV7I8mOOQfKFflsYR1fqG0ttUzjLno= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706612311; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8QD/nihOPTkfoHJshwV6dAmgFI2lBG+9sleohd9oU/w=; b=whFJ6q98eINuQrdu8O3ScEIVW8jIplqULS6jQLCikuj5zMuAhl1EXV0M5CKa6NLrFjXUeS 4Mr7eRJ39dpRKKCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706612309; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8QD/nihOPTkfoHJshwV6dAmgFI2lBG+9sleohd9oU/w=; b=CcSTVaazPgDUl/89RazLerecgJMZ+V5cEadp1gilRshzJ8LvePeN5qoulB1YvXa8udEiZY ygyAUJ7v01vcw0g78RQuOX70AIQNHBjqkDBcnb1WFGb4ydCuGjS3ieSs/xspzjxJwHFw10 vXnOZH4I2FEegFn1CptNKDPYblrYosY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706612309; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8QD/nihOPTkfoHJshwV6dAmgFI2lBG+9sleohd9oU/w=; b=0Fgva+hhUHVGvq6mgZADjUlLRAVmhhSz8BiV8kIkQRqCiwcElMr5FOsOdDeNtlJCnAG5TD iJyJ8nUIocUMg7Ag== Date: Tue, 30 Jan 2024 11:52:54 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/113659 - early exit vectorization and missing VUSE MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-0.60 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-vect-loop-manip.cc:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Score: -0.60 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20240130105918.2AB0E3857739@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789512760286962611 X-GMAIL-MSGID: 1789512760286962611 The following handles the case of the main exit going to a path without virtual use and handles it similar to the alternate exit handling. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/113659 * tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg): Handle main exit without virtual use. * gcc.dg/pr113659.c: New testcase. --- gcc/testsuite/gcc.dg/pr113659.c | 14 ++++++++++++++ gcc/tree-vect-loop-manip.cc | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr113659.c diff --git a/gcc/testsuite/gcc.dg/pr113659.c b/gcc/testsuite/gcc.dg/pr113659.c new file mode 100644 index 00000000000..dc1091b647d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr113659.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-tree-sra" } */ +/* { dg-additional-options "-msse4.1" { target { x86_64-*-* i?86-*-* } } } */ + +struct Foo { + int *ptr; +}; +int Baz(struct Foo first) +{ + while (first.ptr) + if (*first.ptr++) + return 0; + __builtin_unreachable (); +} diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 873a28d7c56..3f974d6d839 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -1708,9 +1708,23 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit, LC PHI node to feed the merge PHI. */ tree *res; if (virtual_operand_p (new_arg)) - /* Use the existing virtual LC SSA from exit block. */ - new_arg = gimple_phi_result - (get_virtual_phi (main_loop_exit_block)); + { + /* Use the existing virtual LC SSA from exit block. */ + gphi *vphi = get_virtual_phi (main_loop_exit_block); + /* ??? When the exit yields to a path without + any virtual use we can miss a LC PHI for the + live virtual operand. Simply choosing the + one live at the start of the loop header isn't + correct, but we should get here only with + early-exit vectorization which will move all + defs after the main exit, so leave a temporarily + wrong virtual operand in place. This happens + for gcc.dg/pr113659.c. */ + if (vphi) + new_arg = gimple_phi_result (vphi); + else + new_arg = gimple_phi_result (from_phi); + } else if ((res = new_phi_args.get (new_arg))) new_arg = *res; else