From patchwork Tue Dec 12 14:12:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 177374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7750002vqy; Tue, 12 Dec 2023 06:14:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8+DNRPiEipmDGdxVyd5oq4zm4qAX6rIBne0Q0geaj9wkJaK9owZTlxqP24sNqrPqlfbhv X-Received: by 2002:a05:6870:f68a:b0:1fb:75b:2b8a with SMTP id el10-20020a056870f68a00b001fb075b2b8amr3978511oab.70.1702390461161; Tue, 12 Dec 2023 06:14:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702390461; cv=pass; d=google.com; s=arc-20160816; b=AhmgYzaR6ZRcfyJDqW/uaSoqZXLuQbZ7FzE8YiV9m+WtfbKVriF2iPUFX2RMl/+DIL D+WF+gYtBk+HUlzgfyaoJ6PhdVzDc+kmKCRon+PxNeq6KAMADKngmj5GJnPn+Nm193jM tLs9QS+oPGaO9HmpmIx6Zxttjs+UMBDyHRHkxa3axHshwjFRpgbpExZyqnOBBUxh3BGn f6HKgXOAul2v3qQzTVTKFHMttPkczD3jhkeqRHo1g4hZpN8DhIsbuv3jbKuKi47YzrA1 YFBCjqQh3Z6l4TW1tCYrrrz87AsGbC2Guos/HFgfU7ZYyjtAnaFpIajswE3kPXhLR+st kLjQ== 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=sR1ty5Avx3BMGRRRGe/vZ6r6UXHM96DRsOsofq+/IUQ=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=boUEh90J2d/Mc/kmKLxgej6F/3fwmolnV3pOfC+mywkVYnEd8DvyoyXWCqpKn3MndB xjIYoePJJyFhXKO0jRlAUCS59+cUuGIgebv4RDWlv62mMJyzCBkEABzjAjyboxz5cPBw kp5TBCUjPOtiQTJ4n3K75o6HDqqPu83QbL5yQJb6C8KT99pfRb6BdwtKShtMtXshp6NP ndJyfsnZ+dF6sc4itaXMZzZUiHlIVTtQlVg3Pia3lD8NKoyc9C3vDLZxeAzqMPnZutBq yQiidLkTUYkRvaIcpGiwAYw6U6FnsTsXFe1dh3SyXFqN95Xp8lATmQqUwX/pKCyVmt+K tkYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=AlQ7vTy1; dkim=neutral (no key) header.i=@suse.de header.b=pYmQxpS1; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=AlQ7vTy1; dkim=neutral (no key) header.i=@suse.de header.b=pYmQxpS1; 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 g17-20020a67e291000000b0046488915105si1678619vsf.25.2023.12.12.06.14.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 06:14:21 -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=AlQ7vTy1; dkim=neutral (no key) header.i=@suse.de header.b=pYmQxpS1; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=AlQ7vTy1; dkim=neutral (no key) header.i=@suse.de header.b=pYmQxpS1; 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 8B98C385C419 for ; Tue, 12 Dec 2023 14:14:10 +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 E79663858C2A for ; Tue, 12 Dec 2023 14:13:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E79663858C2A 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 E79663858C2A 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=1702390428; cv=none; b=QyKYMIGP4nmYGSHxKWz2MMJfRm2RaaTDic+YYw+0xa+uEm6Quio2P5kuAwGaycDbURY/8rx3NUzdBc3TFoz5dpoGfxo8mXqJWLscoKAqY0ZxkhGLKpxkFR5WjWeeMW38VZZ4vu2PlmxOpqzIkWsU8GrTzGUhwpsXSTef0jVWq4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702390428; c=relaxed/simple; bh=4hEOqjupN3yQc4iowgpyCDk5PpGYnYdVooUIOWEmcW8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=FwVc87mFqioozmu9AbuX4HpapVnRfUa/i1KD3IgWq6zR7oMw23Gv/z9v9r+f4/ZKRKjXV1JplsGcjfUHAolit3f9/42aNaoLn6gdUOVr6YhhKNk1QzCnSmWo3sbSHD3aSWuwF9gfpTk3YqBogqZQzOIpS0BHypdQ45glK7JF7Xk= 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 24A93223F0 for ; Tue, 12 Dec 2023 14:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702390422; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=sR1ty5Avx3BMGRRRGe/vZ6r6UXHM96DRsOsofq+/IUQ=; b=AlQ7vTy1KsTM5kfkQ2npJh6ERmx+ec4oTL7LAeDp49Ys8YoVH/m8q/dnVfr0WxdzZoNywy TrvNMheqDWa6STvscQYA1NcA6YwTZ6rTwLS7mmU5PldFzwK8oYwt1d9/cSvPo5Mqks0nZb 5m1KQ9VaE+p32SAK1Jlzy9e3BdWTY7w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702390422; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=sR1ty5Avx3BMGRRRGe/vZ6r6UXHM96DRsOsofq+/IUQ=; b=pYmQxpS1e6F+IZ/6Opw2ege84AZykWS4O2hmpW/d0TgReHWg2g2cfJcekIEdIEjwMY1rmQ BucLiFalrM27z8BQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702390422; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=sR1ty5Avx3BMGRRRGe/vZ6r6UXHM96DRsOsofq+/IUQ=; b=AlQ7vTy1KsTM5kfkQ2npJh6ERmx+ec4oTL7LAeDp49Ys8YoVH/m8q/dnVfr0WxdzZoNywy TrvNMheqDWa6STvscQYA1NcA6YwTZ6rTwLS7mmU5PldFzwK8oYwt1d9/cSvPo5Mqks0nZb 5m1KQ9VaE+p32SAK1Jlzy9e3BdWTY7w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702390422; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=sR1ty5Avx3BMGRRRGe/vZ6r6UXHM96DRsOsofq+/IUQ=; b=pYmQxpS1e6F+IZ/6Opw2ege84AZykWS4O2hmpW/d0TgReHWg2g2cfJcekIEdIEjwMY1rmQ BucLiFalrM27z8BQ== Date: Tue, 12 Dec 2023 15:12:39 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/112961 - include latch in if-conversion CSE MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: 0.93 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: 0.91 X-Spamd-Result: default: False [0.91 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; 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]; NEURAL_SPAM_SHORT(2.51)[0.838]; 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-Flag: NO X-Spam-Status: No, score=-10.9 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: <20231212141410.8B98C385C419@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785085780378297227 X-GMAIL-MSGID: 1785085780378297227 The following makes sure to also process the (empty) latch when performing CSE on the if-converted loop body. That's important to get all uses of copies propagated out on the backedge as well. To avoid CSE on the PHI nodes itself which is prohibitive (see PR90402) this temporarily adds a fake entry edge to the loop. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/112961 * tree-if-conv.cc (tree_if_conversion): Instead of excluding the latch block from VN, add a fake entry edge. * g++.dg/vect/pr112961.cc: New testcase. --- gcc/testsuite/g++.dg/vect/pr112961.cc | 17 +++++++++++++++++ gcc/tree-if-conv.cc | 9 +++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/vect/pr112961.cc diff --git a/gcc/testsuite/g++.dg/vect/pr112961.cc b/gcc/testsuite/g++.dg/vect/pr112961.cc new file mode 100644 index 00000000000..52759e180fb --- /dev/null +++ b/gcc/testsuite/g++.dg/vect/pr112961.cc @@ -0,0 +1,17 @@ +// { dg-do compile } +// { dg-require-effective-target vect_int } + +inline const int& maxx (const int& a, const int &b) +{ + return a > b ? a : b; +} + +int foo(int *a) +{ + int max = 0; + for (int i = 0; i < 1024; ++i) + max = maxx(max, a[i]); + return max; +} + +// { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { xfail vect_no_int_min_max } } } diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 0bde281c246..f9fd0149937 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -3734,7 +3734,7 @@ tree_if_conversion (class loop *loop, vec *preds) auto_vec reads_to_lower; auto_vec writes_to_lower; bitmap exit_bbs; - edge pe; + edge pe, e; auto_vec refs; bool loop_versioned; @@ -3894,11 +3894,13 @@ tree_if_conversion (class loop *loop, vec *preds) /* Perform local CSE, this esp. helps the vectorizer analysis if loads and stores are involved. CSE only the loop body, not the entry PHIs, those are to be kept in sync with the non-if-converted copy. + Do this by adding a fake entry edge - we do want to include the + latch as otherwise copies on a reduction path cannot be propagated out. ??? We'll still keep dead stores though. */ + e = make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), loop->header, EDGE_FAKE); exit_bbs = BITMAP_ALLOC (NULL); for (edge exit : get_loop_exit_edges (loop)) bitmap_set_bit (exit_bbs, exit->dest->index); - bitmap_set_bit (exit_bbs, loop->latch->index); std::pair *name_pair; unsigned ssa_names_idx; @@ -3908,6 +3910,9 @@ tree_if_conversion (class loop *loop, vec *preds) todo |= do_rpo_vn (cfun, loop_preheader_edge (loop), exit_bbs); + /* Remove the fake edge again. */ + remove_edge (e); + /* Delete dead predicate computations. */ ifcvt_local_dce (loop); BITMAP_FREE (exit_bbs);