From patchwork Sun Aug 4 11:47:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1968812 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=Z/v4KQ6j; 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 4WcHrN0ywCz1yYD for ; Sun, 4 Aug 2024 21:48:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6DFD0385841D for ; Sun, 4 Aug 2024 11:47:59 +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.16]) by sourceware.org (Postfix) with ESMTPS id 6BD6F3858D26 for ; Sun, 4 Aug 2024 11:47:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BD6F3858D26 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 6BD6F3858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722772061; cv=none; b=V8zQMLpsIUysIM6N4EVIuUfVgj9T2UVc+d9uFd3IpmvIN2QacR/XaVr+1sulUloZ5IeMSlVWJ3H0nTlDlJHs3AXup7q9aAjuvsKF+HtlD1RKkNeiVqEXB+r4D7OyybQ+0e2N4OnRH2oesniCxsim7YpVINsEIWI8QK8oDggC4Zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722772061; c=relaxed/simple; bh=22P5JA68H5NWxdpBx/TrGGbYgvt+WaWlmbVKTpDKEu0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NYpEdbPVa92bR3zM6F8vT54ZQFJ/2VZ7skdJIcB6mj0e7Qwmlc6/PpHlCbprCXkasLdmNjfRBng7aZbkF3mK2P1WAeKBMMU1O6Fx00HesJAw5l3tyM0TB4lhdPrTR16PSGePMGfwvbU1iaOLvDX0kCej6ufVvBgSdNdmnkYCabA= 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=1722772060; x=1754308060; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=22P5JA68H5NWxdpBx/TrGGbYgvt+WaWlmbVKTpDKEu0=; b=Z/v4KQ6jkPj7vxU9e/CYYToRZ9ZEQKF5zSU/kIK1e5SVB3zWzKjROKX0 H99q2ahilp/JH4urCpmL/qp6RPAPZNtHdzR/SLqVF8hHd2AlQVsJB8Dcb Te/ox/xHoKJeEkjlEkbYDZp2VjK9kauAHkHM3sstWkTXDboJI/YF3mOCv ucB9QKjiX929gJrI8RUscykLWNMuLqXYz4RjQwV2i3FRLJV1qv0zeWkK6 0rQSs/DKqFmG2t7XjlqaHv9oT41WZY1g0MbhJANs3XeN+tF7Hti8joNkN otvAU8u+HzkUQSVzf2ysp3yo7bcwPHI5wQcAG9z8qTpVi/ZPjYS47PIMS w==; X-CSE-ConnectionGUID: vjcqFG6zQxSLPu26gqKkTw== X-CSE-MsgGUID: szmcELdoTz65uUBzTIdzfw== X-IronPort-AV: E=McAfee;i="6700,10204,11153"; a="20894763" X-IronPort-AV: E=Sophos;i="6.09,262,1716274800"; d="scan'208";a="20894763" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2024 04:47:38 -0700 X-CSE-ConnectionGUID: LEeFRaPbSWuwnCNKCsJchw== X-CSE-MsgGUID: VA3d18/WQWOa16byGiEr2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,262,1716274800"; d="scan'208";a="86460089" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orviesa002.jf.intel.com with ESMTP; 04 Aug 2024 04:47:35 -0700 Received: from panli.sh.intel.com (panli.sh.intel.com [10.239.154.73]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 7F14B1005696; Sun, 4 Aug 2024 19:47:34 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, juzhe.zhong@rivai.ai, kito.cheng@gmail.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Pan Li Subject: [PATCH v1] Match: Add type_has_mode_precision_p check for SAT_TRUNC [PR116202] Date: Sun, 4 Aug 2024 11:47:29 +0000 Message-ID: <20240804114730.3423998-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 The .SAT_TRUNC matching can only perform the type has its mode precision. g_12 = (long unsigned int) _2; _13 = MIN_EXPR ; _3 = (_Bool) _13; The above pattern cannot be recog as .SAT_TRUNC (g_12) because the dest only has 1 bit precision but QImode. Aka the type doesn't have the mode precision. Thus, add the type_has_mode_precision_p for the dest to avoid such case. The below tests are passed for this patch. 1. The rv64gcv fully regression tests. 2. The x86 bootstrap tests. 3. The x86 fully regression tests. PR target/116202 gcc/ChangeLog: * match.pd: Add type_has_mode_precision_p for the dest type of the .SAT_TRUNC matching. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/pr116202-run-1.c: New test. Signed-off-by: Pan Li --- gcc/match.pd | 6 +++-- .../riscv/rvv/base/pr116202-run-1.c | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr116202-run-1.c diff --git a/gcc/match.pd b/gcc/match.pd index c9c8478d286..dfa0bba3908 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3283,7 +3283,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) wide_int trunc_max = wi::mask (otype_precision, false, itype_precision); wide_int int_cst = wi::to_wide (@1, itype_precision); } - (if (otype_precision < itype_precision && wi::eq_p (trunc_max, int_cst)))))) + (if (type_has_mode_precision_p (type) && otype_precision < itype_precision + && wi::eq_p (trunc_max, int_cst)))))) /* Unsigned saturation truncate, case 2, sizeof (WT) > sizeof (NT). SAT_U_TRUNC = (NT)(MIN_EXPR (X, 255)). */ @@ -3309,7 +3310,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) wide_int trunc_max = wi::mask (otype_precision, false, itype_precision); wide_int int_cst = wi::to_wide (@1, itype_precision); } - (if (otype_precision < itype_precision && wi::eq_p (trunc_max, int_cst)))))) + (if (type_has_mode_precision_p (type) && otype_precision < itype_precision + && wi::eq_p (trunc_max, int_cst)))))) /* x > y && x != XXX_MIN --> x > y x > y && x == XXX_MIN --> false . */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr116202-run-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr116202-run-1.c new file mode 100644 index 00000000000..d150f20b5d9 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr116202-run-1.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-options "-O3 -march=rv64gcv_zvl256b -fdump-rtl-expand-details" } */ + +int b[24]; +_Bool c[24]; + +int main() { + for (int f = 0; f < 4; ++f) + b[f] = 6; + + for (int f = 0; f < 24; f += 4) + c[f] = ({ + int g = ({ + unsigned long g = -b[f]; + 1 < g ? 1 : g; + }); + g; + }); + + if (c[0] != 1) + __builtin_abort (); +} + +/* { dg-final { scan-rtl-dump-not ".SAT_TRUNC " "expand" } } */