From patchwork Sun Sep 22 10:49:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1988282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=HVsDruiJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XBNFy4mdnz1xsM for ; Sun, 22 Sep 2024 20:51:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B49093858C39 for ; Sun, 22 Sep 2024 10:50:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id 232B13858D20 for ; Sun, 22 Sep 2024 10:50:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 232B13858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 232B13858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727002238; cv=none; b=lvDO59AZvuU2AMALE4dAEfYKyHKUsMyuqVo5Bq6jN8QHb5qFTPhR0zys7eNlsDoAxgoqKCG049rrOXEQNSqkU27DXqj98Npy8rov5BlODmIpqHmXl+5Gj4riAzQh1JCYwe/jj3S7nW+FxhzMW7qm/sDqFhlbTAnXh5KdduhRLwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727002238; c=relaxed/simple; bh=MZ3UFegFVV1MSfftMZGdD7Me8AJmqTrs0kNGieMelz8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hTybYC6355/yyC2tGlYyDbiP8huDr4cBHFluq5u6Lnm3bj9yRvYIXQF4WC7PCxJ8FmiGq19K8/uqsH9rY/BGWsEvdSE4EIOeDQBIbTDMCF/wROXcL+R55QpUGUuzrdTbZIQk+bi5sT75W1cPQWHoxSRAnB0qotMXGwRApUdh8PM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727002236; x=1758538236; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=MZ3UFegFVV1MSfftMZGdD7Me8AJmqTrs0kNGieMelz8=; b=HVsDruiJTx0NzkS7RIC69tCZFIT9zP3zHGAmuigQ7pHY3GGzQPD/ZyOr Tev1gqKCzyK/laPuhcJ1Zkmfo0fpofBjdsV6lY7AL2MuSpLIAnlS0Onny 7+xw0J9vlSZlVDUnWTj/uM2hMJv5be6rFfbFSB5usIa3iK1fuCHgMZK0Y kCBy23juhijXaYhF++sxfKvJonCCcpIVke2X6YlXeZnsMrGLSRbkr2Rwk DSr38yaDxT+V1W7hcd4OqQG9X82Z8pqv3MmodhdNlKp0o6fd56Tvp1WK/ xNN/wj6aQqkRMAy0c20yhUJiXXTpvkS3W+YT0cIkxeCV9P9SjYqddYEJk g==; X-CSE-ConnectionGUID: VCoQXcL9Qm2hUAkFnecGiw== X-CSE-MsgGUID: ab3zhSA5QH6gaygHQMBOBg== X-IronPort-AV: E=McAfee;i="6700,10204,11202"; a="43428681" X-IronPort-AV: E=Sophos;i="6.10,249,1719903600"; d="scan'208";a="43428681" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2024 03:50:34 -0700 X-CSE-ConnectionGUID: bRW1kkKcRWG2D+TY/392tw== X-CSE-MsgGUID: HrF2oFwAS4uqxenLQryhEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,249,1719903600"; d="scan'208";a="70359993" Received: from panli.sh.intel.com ([10.239.154.73]) by fmviesa007.fm.intel.com with ESMTP; 22 Sep 2024 03:50:32 -0700 From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, Tamar.Christina@arm.com, juzhe.zhong@rivai.ai, kito.cheng@gmail.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Pan Li Subject: [PATCH v1] Genmatch: Fix ICE for binary phi cfg mismatching [PR116795] Date: Sun, 22 Sep 2024 18:49:25 +0800 Message-ID: <20240922104925.2058537-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Pan Li This patch would like to fix one ICE when try to match the binary phi for below cfg. We check the first edge of the Phi block comes from b0, instead of check the only one edge of b1 comes from the b0 too. Thus, it will result in some code to be recog as .SAT_SUB but it is not, and finally result the verify_ssa failure. +------+ | b0: | | def | +-----+ | ... | | b1: | | cond |------>| def | +------+ | ... | | +-----+ | | | | v | +-----+ | | b2: | | | Phi |<----------+ +-----+ The below test suites are passed for this patch. * The rv64gcv fully regression test. * The x86 bootstrap test. * The x86 fully regression test. PR target/116795 gcc/ChangeLog: * gimple-match-head.cc (match_cond_with_binary_phi): Fix the incorrect cfg check as b0->b1 in above example. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr116795-1.c: New test. Signed-off-by: Pan Li --- gcc/gimple-match-head.cc | 2 +- gcc/testsuite/gcc.dg/torture/pr116795-1.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr116795-1.c diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc index b63b66e9485..b5d4a71ddc5 100644 --- a/gcc/gimple-match-head.cc +++ b/gcc/gimple-match-head.cc @@ -402,7 +402,7 @@ match_cond_with_binary_phi (gphi *phi, tree *true_arg, tree *false_arg) if (EDGE_COUNT (pred_b0->succs) == 2 && EDGE_COUNT (pred_b1->succs) == 1 && EDGE_COUNT (pred_b1->preds) == 1 - && pred_b0 == EDGE_PRED (gimple_bb (phi), 0)->src) + && pred_b0 == EDGE_PRED (pred_b1, 0)->src) /* * +------+ * | b0: | diff --git a/gcc/testsuite/gcc.dg/torture/pr116795-1.c b/gcc/testsuite/gcc.dg/torture/pr116795-1.c new file mode 100644 index 00000000000..629bdf4bacd --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr116795-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +volatile int a, b; +int c; +int main() { + unsigned e = 0; + for (; e < 2; e++) { + a && b; + if (c) + e = -(c ^ e); + } + return 0; +}