From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 8B7DB158042 for ; Sat, 9 Nov 2024 07:55:51 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C787EE087B; Sat, 9 Nov 2024 07:55:50 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B262BE087B for ; Sat, 9 Nov 2024 07:55:50 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 037A633BE1D for ; Sat, 9 Nov 2024 07:55:50 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 984E3197F for ; Sat, 9 Nov 2024 07:55:48 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1731138937.a6cc1808601268d37a0c43ad67b5c116d9678c4d.sam@gentoo> Subject: [gentoo-commits] proj/gcc-patches:master commit in: 15.0.0/gentoo/ X-VCS-Repository: proj/gcc-patches X-VCS-Files: 15.0.0/gentoo/73_all_PR117493-sccvn-insert_predicates_for_cond-limit.patch X-VCS-Directories: 15.0.0/gentoo/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: a6cc1808601268d37a0c43ad67b5c116d9678c4d X-VCS-Branch: master Date: Sat, 9 Nov 2024 07:55:48 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 093548a7-428d-465b-8d8e-bb8fceeeeb48 X-Archives-Hash: 1d348347f7f144441ac363fd948f548e commit: a6cc1808601268d37a0c43ad67b5c116d9678c4d Author: Sam James gentoo org> AuthorDate: Sat Nov 9 07:55:37 2024 +0000 Commit: Sam James gentoo org> CommitDate: Sat Nov 9 07:55:37 2024 +0000 URL: https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=a6cc1808 15.0.0: update 73_all_PR117493-sccvn-insert_predicates_for_cond-limit.patch This version will be committed shortly. Signed-off-by: Sam James gentoo.org> ...93-sccvn-insert_predicates_for_cond-limit.patch | 107 ++++++++++++++++----- 1 file changed, 82 insertions(+), 25 deletions(-) diff --git a/15.0.0/gentoo/73_all_PR117493-sccvn-insert_predicates_for_cond-limit.patch b/15.0.0/gentoo/73_all_PR117493-sccvn-insert_predicates_for_cond-limit.patch index 2000754..9816e52 100644 --- a/15.0.0/gentoo/73_all_PR117493-sccvn-insert_predicates_for_cond-limit.patch +++ b/15.0.0/gentoo/73_all_PR117493-sccvn-insert_predicates_for_cond-limit.patch @@ -1,41 +1,98 @@ -https://gcc.gnu.org/PR117493 -https://gcc.gnu.org/PR117496 +From a49a60790ae2032dfeee617ba9488fc80e09b3a8 Mon Sep 17 00:00:00 2001 +Message-ID: +From: Andrew Pinski +Date: Fri, 8 Nov 2024 17:35:02 -0800 +Subject: [PATCH] VN: Don't recurse on for the same value of `a | b` [PR117496] -https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117493#c5 +After adding vn_valueize to the handle the `a | b ==/!= 0` case +of insert_predicates_for_cond, it would go into an infinite loop +as the Value number for either a or b could be the same as what it +is for the whole expression. This avoids that recursion so there is +no infinite loop here. + +Bootstrapped and tested on x86_64-linux. + + PR tree-optimization/117496 + +gcc/ChangeLog: + + * tree-ssa-sccvn.cc (insert_predicates_for_cond): If the + valueization for the new lhs is the same as the old one, + don't recurse. + +gcc/testsuite/ChangeLog: + + * gcc.dg/torture/pr117496-1.c: New test. + +Signed-off-by: Andrew Pinski +--- + gcc/testsuite/gcc.dg/torture/pr117496-1.c | 25 +++++++++++++++++++++++ + gcc/tree-ssa-sccvn.cc | 11 ++++++++-- + 2 files changed, 34 insertions(+), 2 deletions(-) + create mode 100644 gcc/testsuite/gcc.dg/torture/pr117496-1.c + +diff --git a/gcc/testsuite/gcc.dg/torture/pr117496-1.c b/gcc/testsuite/gcc.dg/torture/pr117496-1.c +new file mode 100644 +index 000000000000..f35d13dfa85d +--- /dev/null ++++ b/gcc/testsuite/gcc.dg/torture/pr117496-1.c +@@ -0,0 +1,25 @@ ++/* { dg-do compile } */ ++ ++ ++/* PR tree-optimization/117496 */ ++/* This would go into an infinite loop into VN while recording ++ the predicates for the `tracks == 0 && wm == 0` GIMPLE_COND. ++ As wm_N and tracks_N would valueize back to `tracks | wm`. */ ++ ++int main_argc, gargs_preemp, gargs_nopreemp; ++static void gargs(); ++void main_argv() { ++ int tracks = 0; ++ gargs(main_argc, main_argv, &tracks); ++} ++void gargs(int, char *, int *tracksp) { ++ int tracks = *tracksp, wm; ++ for (;;) { ++ if (tracks == 0) ++ wm |= 4; ++ if (gargs_nopreemp) ++ gargs_preemp = 0; ++ if (tracks == 0 && wm == 0) ++ tracks++; ++ } ++} +diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc +index 1967bbdca84d..9c460fc1bdb3 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc -@@ -7902,8 +7902,11 @@ insert_related_predicates_on_edge (enum tree_code code, tree *ops, edge pred_e) +@@ -7897,6 +7897,7 @@ insert_related_predicates_on_edge (enum tree_code code, tree *ops, edge pred_e) + + /* Insert on the TRUE_E true and FALSE_E false predicates derived from LHS CODE RHS. */ ++ static void insert_predicates_for_cond (tree_code code, tree lhs, tree rhs, -- edge true_e, edge false_e) -+ edge true_e, edge false_e, int n = 0) - { -+ if (n > 5) -+ return; -+ - /* If both edges are null, then there is nothing to be done. */ - if (!true_e && !false_e) - return; -@@ -7964,7 +7967,7 @@ insert_predicates_for_cond (tree_code code, tree lhs, tree rhs, - edge nf = false_e; - if (code == EQ_EXPR) - std::swap (nt, nf); -- insert_predicates_for_cond (nc, nlhs, nrhs, nt, nf); -+ insert_predicates_for_cond (nc, nlhs, nrhs, nt, nf, n + 1); - } - /* (a | b) == 0 -> - on true edge assert: a == 0 & b == 0. */ -@@ -7977,10 +7980,10 @@ insert_predicates_for_cond (tree_code code, tree lhs, tree rhs, + edge true_e, edge false_e) +@@ -7973,10 +7974,16 @@ insert_predicates_for_cond (tree_code code, tree lhs, tree rhs, tree nlhs; nlhs = vn_valueize (gimple_assign_rhs1 (def_stmt)); - insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr); -+ insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr, n + 1); ++ /* A valueization of the `a` might return the old lhs ++ which is already handled above. */ ++ if (nlhs != lhs) ++ insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr); ++ /* A valueization of the `b` might return the old lhs ++ which is already handled above. */ nlhs = vn_valueize (gimple_assign_rhs2 (def_stmt)); - insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr); -+ insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr, n + 1); ++ if (nlhs != lhs) ++ insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr); } } } +-- +2.47.0 +