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: 1892753 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=VJR0NxPg; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=whFJ6q98; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=CcSTVaaz; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0Fgva+hh; 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 4TPMc00XVXz23gZ for ; Tue, 30 Jan 2024 21:58:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C6163857C75 for ; Tue, 30 Jan 2024 10:58:54 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240130105854.1C6163857C75@sourceware.org> 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