From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689581980; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=P/f1BzcPJwo+znPKTet4izLUiWKkgXs0s2aFEmDCQgg=; b=ur0mmK9mTRwvVuDp2iWo97yqVj3Bxb/gq6DGyq1sf5a+GRvxkzVHk1cerEhzC2JHKGZboE rkyWroI26EU3U4aScQDqcy9IaAUzOhI0kVjMOpCNQUrcPXdyXQXkt63sgh+l8Qq0U+wAnh 0aHkvTievma4IR79l3FvSyv+oP1jRf4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689581980; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=P/f1BzcPJwo+znPKTet4izLUiWKkgXs0s2aFEmDCQgg=; b=bAKyei/xswEsysl+hFqd9ZIAwjfBZzbNuJpuIhw0lJLkNRMf+c1duxaWCwPt2+zFZfof8T jFESklRqOHCFJlCw== 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) From: Richard Biener 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 Content-Type: text/plain; charset=US-ASCII 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 List-Id: Message-ID: <20230717081940.OqSo02Hi5J-46JCiDxV5U8Q-hby-nO2PjANkvsN3LoI@z> 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; -- 2.35.3