From patchwork Mon Jul 17 08:19:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 121115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp975429vqt; Mon, 17 Jul 2023 01:21:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlHD8JYH4AY2GCnIWDxUCXlYjOzyAgwYd/+NRwudXQRwXbJh6I8rs2RwJ3FLcQr4nOlPgmsW X-Received: by 2002:ac2:58ed:0:b0:4f8:7568:e94b with SMTP id v13-20020ac258ed000000b004f87568e94bmr6536444lfo.56.1689582079113; Mon, 17 Jul 2023 01:21:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689582079; cv=none; d=google.com; s=arc-20160816; b=ZQVqdWr7vYRCfxuaCbmCueR0pUXsaIR/C51hi3jAHDH1YgOupX9aO2I0qA9t88mmaa TluRszX+t0BxZH3TaDYWC536+KG79o5lQy/n/IFaqzwYOBpAknQypQD2Cao5Q8O5BMGp yzZSH5kcWnYYzW3WML5HH77hNmf7VaZepPRuIG90tR950b/TjjRYifmcLo/Y/tOYX07o CVcbJUsOvx6MCSMu94uBX0ctY+G51prMyG8q9iE8HeLXHBc4b70fv/m3RAlyvNOWs9d+ n6SZl8PyqSx8sgyRIwaZdpblCcu6wrcrwVhTsZYF7J5bxze06QGII/NnZJltzaEvU+KY VgNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=P/f1BzcPJwo+znPKTet4izLUiWKkgXs0s2aFEmDCQgg=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=HaF80qToUlEh+xKbtWCs85hRxNBGlGuCTxuxVSCI/ijoDJG3QV4keMzrIdvujsHdot 8BtkkvraTkft/UrW6Hjwc3M32BjemwpWI+fus29lg/vv8DYGD7hxbH8DqBUXy1gsFPl4 0KpekIumfv5b18lkSblJcTcKN1WTGTx3Me0miG+gU+jSXulM8ZfGZ2gkQLE2UbwWjWfJ r6BZUFNDotH6FzPCmOnKv5slFWj1rW1Q0qmUlQw49d3BqO7F73nKy3KoYuI9spHropv9 6bB63qbJtWElvGJ9y9XvKjUooYwEVzU00b7//HCqImUoeD3DcNquOcY9WJMZSp3w0HT6 QnIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rRrNm2aV; 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 s12-20020a056402164c00b0051e1b16a086si7552253edx.69.2023.07.17.01.21.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 01:21:19 -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=rRrNm2aV; 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 024683858D39 for ; Mon, 17 Jul 2023 08:20:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 024683858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689582039; bh=P/f1BzcPJwo+znPKTet4izLUiWKkgXs0s2aFEmDCQgg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rRrNm2aV62UwGU1/L02hJ9BBe9CzUqEK8FwLmIELp6L0Q29ir+5k3IaP3JOvtZeHJ hcR9TDjLF/IQ6z2gyqOx3b17dw0DoKFL5GuFU9EESQYUKgiyHe259tIfjRbsQgpH89 wc2qIQ3hKdDoMrTIJW7fYRBhIUq2JbAGeF3RKNAc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 72D713858D33 for ; Mon, 17 Jul 2023 08:19:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72D713858D33 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 685621FD9A for ; Mon, 17 Jul 2023 08:19:40 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 5D1202C142 for ; Mon, 17 Jul 2023 08:19:40 +0000 (UTC) Date: Mon, 17 Jul 2023 08:19:40 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/110669 - bogus matching of loop bitop User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230717082039.024683858D39@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771655218275102092 X-GMAIL-MSGID: 1771655218275102092 The matching code lacked a check that we end up with a PHI node in the loop header. This caused us to match a random PHI argument now catched by the extra PHI_ARG_DEF_FROM_EDGE checking. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/110669 * tree-scalar-evolution.cc (analyze_and_compute_bitop_with_inv_effect): Check we matched a header PHI. * gcc.dg/torture/pr110669.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr110669.c | 15 +++++++++++++++ gcc/tree-scalar-evolution.cc | 1 + 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr110669.c diff --git a/gcc/testsuite/gcc.dg/torture/pr110669.c b/gcc/testsuite/gcc.dg/torture/pr110669.c new file mode 100644 index 00000000000..b0a9ea448f4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110669.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +int g_29, func_47_p_48, func_47_p_51_l_129; +void func_47_p_51() +{ + for (;;) + { + func_47_p_51_l_129 = 0; + for (; func_47_p_51_l_129 <= 1; func_47_p_51_l_129 += 1) + { + short *l_160 = (short *)(__UINTPTR_TYPE__)(func_47_p_48 || *l_160); + *l_160 &= g_29; + } + } +} diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index ba47a684f4b..2abe8fa0b90 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3674,6 +3674,7 @@ analyze_and_compute_bitop_with_inv_effect (class loop* loop, tree phidef, if (TREE_CODE (match_op[1]) != SSA_NAME || !expr_invariant_in_loop_p (loop, match_op[0]) || !(header_phi = dyn_cast (SSA_NAME_DEF_STMT (match_op[1]))) + || gimple_bb (header_phi) != loop->header || gimple_phi_num_args (header_phi) != 2) return NULL_TREE;