From patchwork Thu Aug 3 02:34:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 130261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp864545vqx; Wed, 2 Aug 2023 19:34:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlHw5y1Z1fCahiM18Tp3rGrD0hTBQzJNfNgIy1csN3680D4x1JMlEbFl+9BE/xMJda+qEgUl X-Received: by 2002:aa7:df18:0:b0:522:289d:8dcd with SMTP id c24-20020aa7df18000000b00522289d8dcdmr5674572edy.35.1691030096393; Wed, 02 Aug 2023 19:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691030096; cv=none; d=google.com; s=arc-20160816; b=gH3kkMCq63UVy0PhGqv8nVEohHdxZhA8bUSWpJbUqb3pE++feOvIVpGmDOqGJTdIH6 Ov56Wj+uFXXXiN9h7t++RSKv+Rbw0mg4o4xH7ol1Dhe4lW41LFAKBp59bv0ThLAAneaO ymsLI66BRFXlNxus6Pc8Ppl5hPGt5NREWmzfEK2JnMiUeKe6JkPg0jVsyv4ZbOZoCpBx S1/81GaBCI4ZNs4Fm2NnaIHtxbPore1HnlKptzWwG38fojowRxbjRoma331WMqoUQ8o+ yRpJH2SxzTl/N2IsZmn9aHkMLdtCk5zONwbD8ZGQWKFL6B6bRSLyt/ryhYDoE/81nmEL 5LJg== 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=Uvwrohe2FAN90Ktrk7JlMzgYbPcaeQVtkCmbbBIJPnU=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=MEK87OJbmVMrZxSVkMn6cuWEfijuOeVvYaK6LPefYzDgMdbgf9O9ujvgPoBU+98UMu z1OTbDI2w79XdDymRccqUghUsuOV/l++JGkr2qx5f7pMWNTPlaIwHxI/dyZexsqGUJap w49iC5kgkaYZ6b2GLol4WWlV0yAGq/DdysREGofK4xfvPGj8wLgEoplqMBieEV1qSTYC JLa05UPwq0NY+uAbrfs97VmR8kc7FWHXd7z7pfHFB+Sm/J6m4Fa3bVms5+XcwF+ZZj1v K3au+vbGXXrQmlyqcGjb0Gjl6JDEFmKZKlnevBJq967YI9Lgtm7GpPw+Yi9zRM8lpXRo K2zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ik16pk8q; 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 j4-20020a50ed04000000b005222968fc70si11343440eds.194.2023.08.02.19.34.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 19:34:56 -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=Ik16pk8q; 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 29FC23857705 for ; Thu, 3 Aug 2023 02:34:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29FC23857705 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691030095; bh=Uvwrohe2FAN90Ktrk7JlMzgYbPcaeQVtkCmbbBIJPnU=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Ik16pk8q6KoyR2L+vIk7nTz6KWMmNRCbhgpTXUjJmmhgrEzq1Q1pS3gtaHBTgevbF hmvagU5jL8zS3vpaqVDuG2au9aJenYS9QdxlPUBPYQ3JGwDWW+vRz8wMzSTDlOrLnU lkhelcdhEERgiprum1XaDxmh7TeKpU2iZyq8dMrs= 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 B487F3858C2A for ; Thu, 3 Aug 2023 02:34:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B487F3858C2A 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 372Kc0Jl012048 for ; Wed, 2 Aug 2023 19:34:11 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3s7xbc8v16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 02 Aug 2023 19:34:11 -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; Wed, 2 Aug 2023 19:34:09 -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; Wed, 2 Aug 2023 19:34:09 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 24D805C68E4; Wed, 2 Aug 2023 19:34:09 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] Fix PR 110874: infinite loop in gimple_bitwise_inverted_equal_p with fre Date: Wed, 2 Aug 2023 19:34:04 -0700 Message-ID: <20230803023404.2271442-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: EEKNG6f0tfF1JtFKT5-uvdFXmnM7xbKW X-Proofpoint-ORIG-GUID: EEKNG6f0tfF1JtFKT5-uvdFXmnM7xbKW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-02_21,2023-08-01_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, 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.29 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: 1773173574005407199 X-GMAIL-MSGID: 1773173574005407199 So I didn't expect valueization to cause calling gimple_nop_convert to iterate between 2 different SSA names causing an infinite loop in gimple_bitwise_inverted_equal_p. So we should cause a bound on gimple_bitwise_inverted_equal_p calling gimple_nop_convert and only look through one rather than always. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/110874 * gimple-match-head.cc (gimple_bitwise_inverted_equal_p): Add new argument, again with default value of true. Don't try gimple_nop_convert if again is false. Update call to gimple_bitwise_inverted_equal_p for new argument. gcc/testsuite/ChangeLog: PR tree-optimization/110874 * gcc.c-torture/compile/pr110874-a.c: New test. --- gcc/gimple-match-head.cc | 14 +++++++++----- .../gcc.c-torture/compile/pr110874-a.c | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr110874-a.c diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc index b1e96304d7c..e91aaab86dd 100644 --- a/gcc/gimple-match-head.cc +++ b/gcc/gimple-match-head.cc @@ -273,7 +273,7 @@ gimple_bitwise_equal_p (tree expr1, tree expr2, tree (*valueize) (tree)) /* Helper function for bitwise_equal_p macro. */ static inline bool -gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize) (tree)) +gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize) (tree), bool again = true) { if (expr1 == expr2) return false; @@ -285,12 +285,16 @@ gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize) (tree) return false; tree other; - if (gimple_nop_convert (expr1, &other, valueize) - && gimple_bitwise_inverted_equal_p (other, expr2, valueize)) + if (again + && gimple_nop_convert (expr1, &other, valueize) + && other != expr1 + && gimple_bitwise_inverted_equal_p (other, expr2, valueize, false)) return true; - if (gimple_nop_convert (expr2, &other, valueize) - && gimple_bitwise_inverted_equal_p (expr1, other, valueize)) + if (again + && gimple_nop_convert (expr2, &other, valueize) + && other != expr2 + && gimple_bitwise_inverted_equal_p (expr1, other, valueize, false)) return true; if (TREE_CODE (expr1) != SSA_NAME diff --git a/gcc/testsuite/gcc.c-torture/compile/pr110874-a.c b/gcc/testsuite/gcc.c-torture/compile/pr110874-a.c new file mode 100644 index 00000000000..b314410a892 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr110874-a.c @@ -0,0 +1,17 @@ +struct S1 { + unsigned f0; +}; +static int g_161; +void func_109(unsigned g_227, unsigned t) { + struct S1 l_178; + int l_160 = 0x1FAE99D5L; + int *l_230[] = {&l_160}; + if (l_160) { + for (l_178.f0 = -7; l_178.f0;) { + ++g_227; + break; + } + (g_161) = g_227; + } + (g_161) &= t; +}