From patchwork Sun Sep 17 01:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 141119 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1924322vqi; Sat, 16 Sep 2023 18:45:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTZLwe+OoZ9djlt5E+Tw/H5PStQCUbc23ogDhkrRkakrbdQrgkqBWXwsnMN/eLskRTv/CT X-Received: by 2002:a05:6402:6c2:b0:52a:38c3:1b4b with SMTP id n2-20020a05640206c200b0052a38c31b4bmr7926539edy.15.1694915142015; Sat, 16 Sep 2023 18:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694915142; cv=none; d=google.com; s=arc-20160816; b=LCBLxXcjhADNaeuuZg/1nGFPQSWHFINugsI3sbz3zQknxl09J29Nqfj6vAc2OITlok UXZaR9oAL/slHtvK4YaVxeDd8TPbqinrb9d1zN0I2tPOBVG5umIKNmduxNsyw0VrrF4d 877jjcMj9ZYR7Lcw85KdFEUZYwLTQzLYFDphs/Qy24+/7LxkeXqUoSw7zvXxOFHJ8Pm0 JQ2n0tdNtS6BLw+JZt96t4IW/xDuGNF88/NSZU6bH+497zjuDGST/CHyP/FzWKeuQYpF 0s+wdyRPpt7L67CwXGSCgFIkmID/uQkqqpln6KBUe4mQHWnn6hOz8uAhFchLDTaum0+i 55ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=h/UlUo2/8a2AajzCy4hiZFv/PPHfptQ5/xCaTyTZ01g=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=MyDlkInic8Od0Xz7BI4ght/UrGjlsm/c5bHk2ufiJCQ4RmQ2uMC+bQei3f76w1ggTi Z/ADwzKyno8g9ZuHfDB5OpH3ZrzJQT83HoOv+vkLkcrdP+6HNxowWM55VO2diU205Wfj wg3mqTuBIJDCZk6U8vHBcLsbPy/szEnjVRiZHD3dQDZeilM39u8m7+B64jPq0poC/uJn W3ngg5d+CCEDFHAqLobGfOC0eSEvkFzGqAnFLWef8voE3lenZUijtglsrfdAdmz9nSbE Q5W2CqWY/oyluhxm8vRMDXHsU6b/R3717JZ7K323CbQ2Z5lQ5DdjXrCHTDd2dlzLvPgj Ewqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hWh33DVF; 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=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l16-20020aa7d950000000b00529fbe83905si6025229eds.196.2023.09.16.18.45.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 18:45:41 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=hWh33DVF; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24D4F3858C60 for ; Sun, 17 Sep 2023 01:45:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24D4F3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694915140; bh=h/UlUo2/8a2AajzCy4hiZFv/PPHfptQ5/xCaTyTZ01g=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hWh33DVFLlCFUc1Cx1qgtZqcm4FuOoVuRg0CdAZWBW7LdCQ3SiW4FolXTkIG7qYOZ 7dduKvTZh4dr2WCSyfyOlZPANKU365hHO6E6u2NAVyDedNmoeW8DXC+zTlreAEvcd4 AszU6FxBP5NMIrpw4Dwf61hgwUebDmsiBUyePTrQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 8DDDB3858D28 for ; Sun, 17 Sep 2023 01:44:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DDDB3858D28 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38GKoOOA025280 for ; Sat, 16 Sep 2023 18:44:37 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3t59qps64t-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 16 Sep 2023 18:44:37 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 16 Sep 2023 18:44:34 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sat, 16 Sep 2023 18:44:34 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id B02CB3F705A; Sat, 16 Sep 2023 18:44:33 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Avoid recusive zero_one_valued_p for conversions Date: Sat, 16 Sep 2023 18:44:18 -0700 Message-ID: <20230917014418.1703031-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: eJGxjDDWryH26DTMKPXwOhUkpTkzdzJT X-Proofpoint-GUID: eJGxjDDWryH26DTMKPXwOhUkpTkzdzJT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-15_20,2023-09-15_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP 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: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777247339859615710 X-GMAIL-MSGID: 1777247339859615710 So when VN finds a name which has a nop conversion, it says both names are equivalent to each other and the valuaization function for one will return the other. This normally does not cause any issues as there is no recusive matches. But after r14-4038-gb975c0dc3be285, there was one added. So we would do an infinite recusion on the match and never finish. This fixes the issue (and adds a comment in match.pd) by for converts just handle one level instead of being recusive always. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note the testcase was reduced from tree-ssa-loop-niter.cc and then changed slightly into C rather than C++ but it still needs exceptions turned on get the IR that VN would produce this equivalence relationship going on. Also had to turn off early inline to force put to be inlined later. PR tree-optimization/111435 gcc/ChangeLog: * match.pd (zero_one_valued_p): Don't do recusion on converts. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr111435-1.c: New test. --- gcc/match.pd | 8 +++++++- .../gcc.c-torture/compile/pr111435-1.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr111435-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 97405e6a5c3..887665633d4 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2188,8 +2188,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* A conversion from an zero_one_valued_p is still a [0,1]. This is useful when the range of a variable is not known */ +/* Note this matches can't be recusive because of the way VN handles + nop conversions being equivalent and then recusive between them. */ (match zero_one_valued_p - (convert@0 zero_one_valued_p)) + (convert@0 @1) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && (TYPE_UNSIGNED (TREE_TYPE (@1)) + || TYPE_PRECISION (TREE_TYPE (@1)) > 1) + && wi::leu_p (tree_nonzero_bits (@1), 1)))) /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 }. */ (simplify diff --git a/gcc/testsuite/gcc.c-torture/compile/pr111435-1.c b/gcc/testsuite/gcc.c-torture/compile/pr111435-1.c new file mode 100644 index 00000000000..afa84dd59dd --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr111435-1.c @@ -0,0 +1,18 @@ +/* { dg-options "-fexceptions -fno-early-inlining" } */ +/* { dg-require-effective-target exceptions } */ + +void find_slot_with_hash(const int *); + +void put(const int *k, const int *) { + find_slot_with_hash(k); +} +unsigned len(); +int *address(); +void h(int header, int **bounds) { + if (!*bounds) + return; + unsigned t = *bounds ? len() : 0; + int queue_index = t; + address()[(unsigned)queue_index] = 0; + put(&header, &queue_index); +}