From patchwork Mon Feb 26 11:34:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 206580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2010415dyb; Mon, 26 Feb 2024 03:35:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCURsGhtkAspZv5tvQ7QglSvI0PJ2RSXAhAfIi1Wfc8/FakTvgHtIofrYUMsJRIKQHv4e4yD+d4SUVhkqEkoMgCQVJ3YMA== X-Google-Smtp-Source: AGHT+IHiscjN+IlTsY9G6Np8E++f/qIuyC0VSNrowdcgMXSr28FrTDCc9hn76H9wjiyZVmSclmbz X-Received: by 2002:a05:6808:318c:b0:3c1:a3df:fb6e with SMTP id cd12-20020a056808318c00b003c1a3dffb6emr2189980oib.18.1708947340019; Mon, 26 Feb 2024 03:35:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708947339; cv=pass; d=google.com; s=arc-20160816; b=C77uKSTamBb3OlmTEoun2zSQQRtjN+m1bXiE7wBIuE3j638ew2Jacn4tWcvC+HjfwX EaFtUTr3iejmsjo3RC9ThhdAsv7S1p90XuHDjoGy+hmLKiJGZLnXhP6N0R+YVcp+Cwbx VtFE2hnA1ODNGPxKYx3SYcgyYngjX31DPQIU64Wmg7cKxhYZk9w2ALnwjqWE+oHc00tv +GnIAwOQXh39DA0lEYUm9+tJX8WyNkJIbqzr7vn2uaPN4doMCuKNew3lCRBTvRQ1SpMp R8HPHgxZjZaaohP/HWq6WiEP1Q5BAEdlFoa65/zBVc82YLmrexpPEa9u73Ro54GOvr8U JiNw== 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:cc:to:from:date:dkim-signature:dkim-signature :dkim-signature:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=KuL/VNTCuruKlJqCmB56JpU+bJfWgpVuI74GMZMgKwg=; fh=iwBcjOQuJQeC9NGqXlwJbGDynxCKlwwYbxsdwpHBsEc=; b=V+83EpeqvCFwOQwktdgPHJsVW6JUDNWCz6OdrFIHJuTO47V6gDx0j6smnY9U9oQPQV EKFrnAplqRgydqvfsXz4pmvtV+BW5m8UKw9z/DbVHMtk4OL0o/zMZ1C2lP7/Afg9fSTe Y2GY6zF+hdd700H99aj9oH07iEOl2o+JqICCrmXPVasepTlv5nPE33dgy2pz04+cUJIo kw3hPenXR3vPeKu4zSTF+z0qf8XeM6cqSkRetgt46Du28gzl2ivhJllOcnF1TZwrMM8g 5L5c6HhzLqpLq3tK6JO8o9QGs/zEeneVOxI7bgqedd+TTlkgK0h6RUxmHtuv6d0Xxjea Oh+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wvOJNue4; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=R2CSHzBl; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wvOJNue4; 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 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=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q5-20020ad45ca5000000b0068ff0cdb67dsi4469468qvh.58.2024.02.26.03.35.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 03:35:39 -0800 (PST) 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=@suse.de header.s=susede2_rsa header.b=wvOJNue4; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=R2CSHzBl; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wvOJNue4; 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 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=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B0E583858C78 for ; Mon, 26 Feb 2024 11:35:39 +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 [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 55DFB3858CDB for ; Mon, 26 Feb 2024 11:34:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55DFB3858CDB 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 55DFB3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708947286; cv=none; b=lS/2DH9IdmHBqDY7fWMFILoy/hDveSzAhTRLhVhWiTggEtOApfi06iWUigK/LhIgu56KydRZyxMrDTHXWXhvpg6plSsZxox1YKmzzFQ+zHEAV4z8X/MKZ7x5Z9qQDo4sfW5fozv1MK+4IXRteLo1wo/IBJ2uC2InwznxXbxgDYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708947286; c=relaxed/simple; bh=eTXS13LgciFyZEpgAa9Yc90xKLXZLDfmQ3QV+51Zc6Q=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=ZH6+E+PjpcQGHnzyH1T+WiZANDGlio4BiMrKSNE5VnniZ1/quZeHNL8Sy7fQco7dBrinLXFuvKtQmGN9sNiG6jSUro1p7YVjQKlkVcSKR16ah6Uowa6zY3DreAUyS3ZGdd+M7iJgw+dNLZGYIwKG5OlpZigAbae43HV7KOiQUv8= 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 35E1D2243B; Mon, 26 Feb 2024 11:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708947283; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=KuL/VNTCuruKlJqCmB56JpU+bJfWgpVuI74GMZMgKwg=; b=wvOJNue4e0geFPVgGM2fo7CKVmw3rgQOgOTTyh+xBCljmuOgy9m+Bt5IKIuXkof2UBXXho b3ZPU28nYuykd0fWto7LbnyTZjiOTSAYjM0Jk/59XnoyGafo8U3H6PgddeiG/SjbUoqdTN JJ1LoicmaJpVQ5eZVhXiFKT5BAYtsgc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708947283; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=KuL/VNTCuruKlJqCmB56JpU+bJfWgpVuI74GMZMgKwg=; b=R2CSHzBlj2l8jSS9rasxcpt7gtFIjhyNOQh4yJa2VWgKu8tIUsGBbgPo1M9Sjfi2d4S5kA n33b4I+PlGFUaUAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708947283; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=KuL/VNTCuruKlJqCmB56JpU+bJfWgpVuI74GMZMgKwg=; b=wvOJNue4e0geFPVgGM2fo7CKVmw3rgQOgOTTyh+xBCljmuOgy9m+Bt5IKIuXkof2UBXXho b3ZPU28nYuykd0fWto7LbnyTZjiOTSAYjM0Jk/59XnoyGafo8U3H6PgddeiG/SjbUoqdTN JJ1LoicmaJpVQ5eZVhXiFKT5BAYtsgc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708947283; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=KuL/VNTCuruKlJqCmB56JpU+bJfWgpVuI74GMZMgKwg=; b=R2CSHzBlj2l8jSS9rasxcpt7gtFIjhyNOQh4yJa2VWgKu8tIUsGBbgPo1M9Sjfi2d4S5kA n33b4I+PlGFUaUAw== Date: Mon, 26 Feb 2024 12:34:42 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: tamar.christina@arm.com Subject: [PATCH 1/2] tree-optimization/114068 - missed virtual LC PHI after vect peeling MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 1.61 X-Spamd-Result: default: False [1.61 / 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)[]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.16)[-0.817]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(2.38)[0.679]; 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-Status: No, score=-10.6 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: <20240226113539.B0E583858C78@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791961165806626877 X-GMAIL-MSGID: 1791961165806626877 When we choose the IV exit to be one leading to no virtual use we fail to have a virtual LC PHI even though we need it for the epilog entry. The following makes sure to create it so that later updating works. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. PR tree-optimization/114068 * tree-vect-loop-manip.cc (get_live_virtual_operand_on_edge): New function. (slpeel_tree_duplicate_loop_to_edge_cfg): Add a virtual LC PHI on the main exit if needed. Remove band-aid for the case it was missing. * gcc.dg/vect/vect-early-break_118-pr114068.c: New testcase. * gcc.dg/vect/vect-early-break_119-pr114068.c: Likewise. --- .../vect/vect-early-break_118-pr114068.c | 23 ++++++++ .../vect/vect-early-break_119-pr114068.c | 25 +++++++++ gcc/tree-vect-loop-manip.cc | 52 ++++++++++++++----- 3 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c create mode 100644 gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c new file mode 100644 index 00000000000..b462a464b66 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-O3" } */ + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ + +struct h { + int b; + int f; +} k; + +void n(int m) { + struct h a = k; + for (int o = m; o; ++o) { + if (a.f) + __builtin_unreachable(); + if (o > 1) + __builtin_unreachable(); + *(&k.b + o) = 1; + } +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c new file mode 100644 index 00000000000..a65ef7b8c49 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-O3" } */ + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ + +struct h { + int b; + int c; + int f; +} k; + +void n(int m) { + struct h a = k; + for (int o = m; o; ++o) { + if (a.f) + __builtin_unreachable(); + if (o > 1) + __builtin_unreachable(); + *(&k.b + o) = 1; + *(&k.c + o*m) = 2; + } +} diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 3f974d6d839..39bac1e99ef 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -1429,6 +1429,32 @@ vect_set_loop_condition (class loop *loop, edge loop_e, loop_vec_info loop_vinfo (gimple *) cond_stmt); } +/* Get the virtual operand live on E. The precondition on this is valid + immediate dominators and an actual virtual definition dominating E. */ +/* ??? Costly band-aid. For the use in question we can populate a + live-on-exit/end-of-BB virtual operand when copying stmts. */ + +static tree +get_live_virtual_operand_on_edge (edge e) +{ + basic_block bb = e->src; + do + { + for (auto gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + if (gimple_vdef (stmt)) + return gimple_vdef (stmt); + if (gimple_vuse (stmt)) + return gimple_vuse (stmt); + } + if (gphi *vphi = get_virtual_phi (bb)) + return gimple_phi_result (vphi); + bb = get_immediate_dominator (CDI_DOMINATORS, bb); + } + while (1); +} + /* Given LOOP this function generates a new copy of it and puts it on E which is either the entry or exit of LOOP. If SCALAR_LOOP is non-NULL, assume LOOP and SCALAR_LOOP are equivalent and copy the @@ -1595,6 +1621,18 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit, flush_pending_stmts (loop_exit); set_immediate_dominator (CDI_DOMINATORS, new_preheader, loop_exit->src); + /* If we ended up choosing an exit leading to a path not using memory + we can end up without a virtual LC PHI. Create it when it is + needed because of the epilog loop continuation. */ + if (need_virtual_phi && !get_virtual_phi (loop_exit->dest)) + { + tree header_def = gimple_phi_result (get_virtual_phi (loop->header)); + gphi *vphi = create_phi_node (copy_ssa_name (header_def), + new_preheader); + add_phi_arg (vphi, get_live_virtual_operand_on_edge (loop_exit), + loop_exit, UNKNOWN_LOCATION); + } + bool multiple_exits_p = loop_exits.length () > 1; basic_block main_loop_exit_block = new_preheader; basic_block alt_loop_exit_block = NULL; @@ -1711,19 +1749,7 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit, { /* 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); + new_arg = gimple_phi_result (vphi); } else if ((res = new_phi_args.get (new_arg))) new_arg = *res; From patchwork Mon Feb 26 11:34:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 206583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2010518dyb; Mon, 26 Feb 2024 03:35:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVSnGdEjhy1Eb5yOW3sZyQNzBXVGjAObsiCvydxbdGAUCvv0Ww9YFY91RetXCUpiZ2l+8boRhaEiAWQmeLcUP2sn9aO4A== X-Google-Smtp-Source: AGHT+IFH+ZYn2nPV5mhua43aZLBL3MOYUaL8kZaHDajasRNK24xfW+hohT/IxsD/SChQr9mjlvcp X-Received: by 2002:a05:622a:289:b0:42e:91af:7201 with SMTP id z9-20020a05622a028900b0042e91af7201mr195373qtw.67.1708947356836; Mon, 26 Feb 2024 03:35:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708947356; cv=pass; d=google.com; s=arc-20160816; b=kUz7UOji+cv6mfTMMBrmDQFrf5+L3Rx9DewDAU/FGCYpT+xm4Fk62ZufkdcqrTsztZ xPhyKO2xqj6JmyladttscroYIRq1Sm8reLo1SLnNVsEC8tJHswFL6gQi5MwVg801sX+r H8wW03Pwk53v4wqhJs3WsuvtgqM6AgMAXCOynBdBSBennQcrkZEu+3GvRgZ5BFaXsv+L tUK81iNxV6t+TCSCv/umM2cCcN4mvCAttfvUi5Oy0Q8NXip2HrRwqxnYVgdpn2j5nM7E jO6aabRp5DnAPWM/HiRk69XJDZxfWWWTXgbATNIzjKxAWPWqIqcsJZ7a8VpkPs8EQ07C 1IWw== 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:cc:to:from:date:dkim-signature:dkim-signature :dkim-signature:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=doeM4eEQShwdIArJU/YCCal5oX9eF7gWNhQdJ93CS7M=; fh=iwBcjOQuJQeC9NGqXlwJbGDynxCKlwwYbxsdwpHBsEc=; b=FcUswTxN+/yatS2Enx6OPZg+7lTEs93Z8i9FpN8QHHxe1iOyVqkxDELIP28W0WZbsp I2UmXlEmBu6S3/oDghQNRRvAiW8uRomd4RbJczA9Zh0xvCMUPG0JlWXEbwsWXGcMq13e Xri+EGnY5xw5iQEsrgsLz8HpIyRdpzJVGEOcPEMLS0QgliesvgvSgD0i8CB0J6S0tuaK I8f0vRzPgV92tjY6JX3m2T+7S0o0SAz+O1tjfaxMffaXOYx6MLCYilrVb2DQm14mFPh5 EeJRhL5I2hV+kS5AmLQ1x67H7Msv2jKlimzSazQNlnrDiVVXmzGiqLhqk1mdsc0WLdc5 cr7A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=o76v4VVy; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=iK04cEWA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=Rf30chyb; arc=pass (i=1); 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=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c3-20020ac853c3000000b0042c66cea37dsi4795742qtq.336.2024.02.26.03.35.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 03:35:56 -0800 (PST) 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=@suse.de header.s=susede2_rsa header.b=o76v4VVy; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=iK04cEWA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=Rf30chyb; arc=pass (i=1); 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=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A3A23858414 for ; Mon, 26 Feb 2024 11:35:56 +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 D57193858427 for ; Mon, 26 Feb 2024 11:35:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D57193858427 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 D57193858427 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=1708947302; cv=none; b=EiWp3RAoGtAtlJI7JbT56tyHzb2zfVC4o6ghaOj6cBHN3gQ7ICc7ssibXhLS0kt7F2yVk7+gGV7cFZGp4832FCxvLticEN/5iyx0V0OxKP6WlxBE2cMRBX5nP84vinwhN0DTaCy1q+qDNzHz3fsuH6pBNKKGt9IwJwcANnvICkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708947302; c=relaxed/simple; bh=5LZSSRBvsoSD0uuiSLchJsYEuMUGmAKGfVcbF1OkZX0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=sVosTbZ6Y+9j9QvhcLCqhrp6DgHPlGBUbgtaXPlyjMowzAR63M6XbQJkAUeo5dONqGH5c61G0RkyYDXuG1cO8hk2P5BO3Vu3rkW9t5SfHEc0jpcp0BUakftQ4YxyunrUwYT6s2t7tAk+5Cf9ZeinoQ2OF1EhS8oaFu1+ouIWOoQ= 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 E2C352248B; Mon, 26 Feb 2024 11:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708947300; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=doeM4eEQShwdIArJU/YCCal5oX9eF7gWNhQdJ93CS7M=; b=o76v4VVy2ka4AjtxolsN9zbUzkC3ZaEHdVyT5bbXAWyZZ+8i6BGIJfZ1w5SUoivc8wEOri Pokl4G+PW1qb34hdIHMfur6jZ+2TJbdVI0n4CbZ/1ug19Exqlhe8qd7CODvdPnV75sJYAL WgM8ukW2WwXtyxI7WjE8o1w6rJ0skko= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708947300; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=doeM4eEQShwdIArJU/YCCal5oX9eF7gWNhQdJ93CS7M=; b=408jiED7KaAgdU5MZz1CPflWoRcDntkHlg04NBImv07raIX3I0lzI0POT28/D5m/epdOqu lalxgLep2aP7PtDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708947299; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=doeM4eEQShwdIArJU/YCCal5oX9eF7gWNhQdJ93CS7M=; b=iK04cEWAl9ehxyy2nahQzrtUUiIu/WiEywvx99qQxKk+7rQDd85KO/hSdv5iJvJn1Xm5Qp uhqN1/NpkBgpq1GFyAM7AzHgp2FvaN8wJFNltiSCtu8gCF91j/EptBqv9+0jhjlggcoNVt 3wtEEDuEXSnkSh12Yu4+RlZDXzxVIbw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708947299; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=doeM4eEQShwdIArJU/YCCal5oX9eF7gWNhQdJ93CS7M=; b=Rf30chybokaeM59Voox5btWW0j6N71fybY/9NNr4Y7OGzlcmHgkD/HsypchpEl8cLLp31d TWTd1x0YAEnk0UAA== Date: Mon, 26 Feb 2024 12:34:59 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: tamar.christina@arm.com Subject: [PATCH 2/2] tree-optimization/114099 - virtual LC PHIs and early exit vect MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 1.59 X-Spamd-Result: default: False [1.59 / 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)[]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.16)[-0.821]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(2.35)[0.672]; 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-Status: No, score=-10.6 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: <20240226113556.8A3A23858414@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791961183572319440 X-GMAIL-MSGID: 1791961183572319440 In some cases exits can lack LC PHI nodes for the virtual operand. We have to create them when the epilog loop requires them which also allows us to remove some only halfway correct fixups. This is the variant triggering for alternate exits. Bootstrap and regtest pending on x86_64-unknown-linux-gnu. PR tree-optimization/114099 * tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg): Create and fill in a needed virtual LC PHI for the alternate exits. Remove code dealing with that missing. * gcc.dg/vect/vect-early-break_120-pr114099.c: New testcase. --- .../vect/vect-early-break_120-pr114099.c | 20 +++++++++++ gcc/tree-vect-loop-manip.cc | 35 +++++++------------ 2 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/vect-early-break_120-pr114099.c diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_120-pr114099.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_120-pr114099.c new file mode 100644 index 00000000000..77e47e30417 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_120-pr114099.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-O3" } */ + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ + +int m; +void __attribute__((noreturn)) n(); +void t1(int jj, int l) { + for (int i = 1; i < l; i++) + { + int p = m++; + if (p) + n(); + if(jj <= i) + __builtin_unreachable(); + } +} diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 39bac1e99ef..137b053ac35 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -1667,17 +1667,18 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit, alt_loop_exit_block = split_edge (exit); if (!need_virtual_phi) continue; - if (vphi_def) - { - if (!vphi) - vphi = create_phi_node (copy_ssa_name (vphi_def), - alt_loop_exit_block); - else - /* Edge redirection might re-allocate the PHI node - so we have to rediscover it. */ - vphi = get_virtual_phi (alt_loop_exit_block); - add_phi_arg (vphi, vphi_def, exit, UNKNOWN_LOCATION); - } + /* When the edge has no virtual LC PHI get at the live + virtual operand by other means. */ + if (!vphi_def) + vphi_def = get_live_virtual_operand_on_edge (exit); + if (!vphi) + vphi = create_phi_node (copy_ssa_name (vphi_def), + alt_loop_exit_block); + else + /* Edge redirection might re-allocate the PHI node + so we have to rediscover it. */ + vphi = get_virtual_phi (alt_loop_exit_block); + add_phi_arg (vphi, vphi_def, exit, UNKNOWN_LOCATION); } set_immediate_dominator (CDI_DOMINATORS, new_preheader, @@ -1789,17 +1790,7 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit, if (virtual_operand_p (alt_arg)) { gphi *vphi = get_virtual_phi (alt_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.c-torture/execute/20150611-1.c */ - if (vphi) - alt_arg = gimple_phi_result (vphi); + alt_arg = gimple_phi_result (vphi); } /* For other live args we didn't create LC PHI nodes. Do so here. */