From patchwork Tue Oct 8 08:32:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1994054 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=VGAaKxbg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XN8XW18Qgz1xvB for ; Tue, 8 Oct 2024 19:37:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2CE53883020 for ; Tue, 8 Oct 2024 08:37:03 +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.12]) by sourceware.org (Postfix) with ESMTPS id DFECA3870C18 for ; Tue, 8 Oct 2024 08:36:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DFECA3870C18 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 DFECA3870C18 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728376588; cv=none; b=V0nZHXey5pm/aPpa2RpkO9Ef2/OHbsLsP0XSumpcyu4PNaqtxiMQph9Zy9SkxtseeRETszayA6k9yFSXTu9fG9lhq7EhbAlPIWYsgfxU6ucPtL9zOBnZbBKQjT2w0P7IJTUyzJ1pR1rojZx7xV2M52yoiI77j+HjUhtl+V2tVG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728376588; c=relaxed/simple; bh=VXEsRKbAZnbv24RIql66IWaUcTn5lGQQP7+kpo8DEVE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=u/eV/8hK0xeKgV6gVjhSjnFps3do3YzgEtdNrMXrfsXvvYs/la4zzPJ4llzWjNNO4yzGcFgAoWkW0JWBOdQPpx0sQf9F17WXW7k3tI+a2TYw1OdcCJz7QALeE39GRD1P15xJ1x3rTXCz2/BDqGeu58dM8XEDp6TNBduOpxRwYxo= 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=1728376581; x=1759912581; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=VXEsRKbAZnbv24RIql66IWaUcTn5lGQQP7+kpo8DEVE=; b=VGAaKxbgyEJsWQHIpp8Ab0FHwRp4egzEsT8DV1WZyGUyoIldHNgcJ/Bx HWBIhZl3IXx61fmA89kppJzEUNh2Qj8nVMEMWi3h/syNhG1aufiX7fw1A nZX4Uks1kx/qoddXkKmXk4tG3mzWLODspgv5mOj5XqQZbNa18uCfgiqdC 0XXwX4gj9waqz915MMWKtqYfGf9hDvxWDzWOtnRAnIejmGmSdl29QuPLu 8pb48ma3Gj55MHq6X7ja9XINy0kD/dm0MfPrdZNJi3eJHlNOyh4VfUTRL 1dHFfro7TUQSbxaYcNFJCgz6+8R5G+N4a+CJAS+jTmR/40uvv7dLMUcRr g==; X-CSE-ConnectionGUID: t/ZcWCI8SYaUzaNVxzq2fA== X-CSE-MsgGUID: BduVo1zzSLSi0WMNNQTrVg== X-IronPort-AV: E=McAfee;i="6700,10204,11218"; a="38946541" X-IronPort-AV: E=Sophos;i="6.11,186,1725346800"; d="scan'208";a="38946541" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2024 01:34:18 -0700 X-CSE-ConnectionGUID: /wYnA3pySE+EL2WbXKdq/A== X-CSE-MsgGUID: V1EbSWK4Q0GttXX/cKZpzA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,186,1725346800"; d="scan'208";a="80738433" Received: from panli.sh.intel.com ([10.239.154.73]) by orviesa004.jf.intel.com with ESMTP; 08 Oct 2024 01:34:14 -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 1/4] Match: Support form 1 for scalar signed integer SAT_TRUNC Date: Tue, 8 Oct 2024 16:32:48 +0800 Message-ID: <20241008083248.189092-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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 support the form 1 of the scalar signed integer SAT_TRUNC. Aka below example: Form 1: #define DEF_SAT_S_TRUNC_FMT_1(NT, WT, NT_MIN, NT_MAX) \ NT __attribute__((noinline)) \ sat_s_trunc_##WT##_to_##NT##_fmt_1 (WT x) \ { \ NT trunc = (NT)x; \ return (WT)NT_MIN <= x && x <= (WT)NT_MAX \ ? trunc \ : x < 0 ? NT_MIN : NT_MAX; \ } DEF_SAT_S_TRUNC_FMT_1(int64_t, int32_t, INT32_MIN, INT32_MAX) Before this patch: 4 │ __attribute__((noinline)) 5 │ int32_t sat_s_trunc_int64_t_to_int32_t_fmt_1 (int64_t x) 6 │ { 7 │ int32_t trunc; 8 │ unsigned long x.0_1; 9 │ unsigned long _2; 10 │ int32_t _3; 11 │ _Bool _7; 12 │ int _8; 13 │ int _9; 14 │ int _10; 15 │ 16 │ ;; basic block 2, loop depth 0 17 │ ;; pred: ENTRY 18 │ x.0_1 = (unsigned long) x_4(D); 19 │ _2 = x.0_1 + 2147483648; 20 │ if (_2 > 4294967295) 21 │ goto ; [50.00%] 22 │ else 23 │ goto ; [50.00%] 24 │ ;; succ: 4 25 │ ;; 3 26 │ 27 │ ;; basic block 3, loop depth 0 28 │ ;; pred: 2 29 │ trunc_5 = (int32_t) x_4(D); 30 │ goto ; [100.00%] 31 │ ;; succ: 5 32 │ 33 │ ;; basic block 4, loop depth 0 34 │ ;; pred: 2 35 │ _7 = x_4(D) < 0; 36 │ _8 = (int) _7; 37 │ _9 = -_8; 38 │ _10 = _9 ^ 2147483647; 39 │ ;; succ: 5 40 │ 41 │ ;; basic block 5, loop depth 0 42 │ ;; pred: 3 43 │ ;; 4 44 │ # _3 = PHI 45 │ return _3; 46 │ ;; succ: EXIT 47 │ 48 │ } After this patch: 4 │ __attribute__((noinline)) 5 │ int32_t sat_s_trunc_int64_t_to_int32_t_fmt_1 (int64_t x) 6 │ { 7 │ int32_t _3; 8 │ 9 │ ;; basic block 2, loop depth 0 10 │ ;; pred: ENTRY 11 │ _3 = .SAT_TRUNC (x_4(D)); [tail call] 12 │ return _3; 13 │ ;; succ: EXIT 14 │ 15 │ } The below test suites are passed for this patch. * The rv64gcv fully regression test with pr116861-1.c failed. * The x86 bootstrap test. * The x86 fully regression test. The failed pr116861-1.c ice will be fixed in underlying patch, as it just trigger one existing bug. gcc/ChangeLog: * match.pd: Add case 1 matching pattern for signed SAT_TRUNC. * tree-ssa-math-opts.cc (gimple_signed_integer_sat_trunc): Add new decl for signed SAT_TRUNC. (match_saturation_trunc): Add new func impl to try SAT_TRUNC pattern on phi node. (math_opts_dom_walker::after_dom_children): Add match_saturation_trunc for phi node iteration. Signed-off-by: Pan Li --- gcc/match.pd | 22 ++++++++++++++ gcc/tree-ssa-math-opts.cc | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index d50b732bc86..5108ce45357 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3461,6 +3461,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (if (wi::eq_p (trunc_max, int_cst_1) && wi::eq_p (max, int_cst_2)))))) +/* Signed saturation truncate, case 1, sizeof (WT) > sizeof (NT). + SAT_S_TRUNC(X) = (unsigned)X + NT_MAX + 1 > Unsigned_MAX ? (NT)X. */ +(match (signed_integer_sat_trunc @0) + (cond^ (gt (plus:c (convert@4 @0) INTEGER_CST@1) INTEGER_CST@2) + (bit_xor:c (negate (convert (lt @0 integer_zerop))) INTEGER_CST@3) + (convert @0)) + (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type) + && !TYPE_UNSIGNED (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@4))) + (with + { + unsigned itype_precision = TYPE_PRECISION (TREE_TYPE (@0)); + unsigned otype_precision = TYPE_PRECISION (type); + wide_int offset = wi::uhwi (1ull << (otype_precision - 1), itype_precision); + wide_int trunc_max = wi::mask (otype_precision, false, itype_precision); + wide_int max = wi::mask (otype_precision - 1, false, otype_precision); + wide_int int_cst_1 = wi::to_wide (@1); + wide_int int_cst_2 = wi::to_wide (@2); + wide_int int_cst_3 = wi::to_wide (@3); + } + (if (wi::eq_p (int_cst_1, offset) && wi::eq_p (int_cst_2, trunc_max) + && wi::eq_p (int_cst_3, max)))))) + /* x > y && x != XXX_MIN --> x > y x > y && x == XXX_MIN --> false . */ (for eqne (eq ne) diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc index a61559c52a9..831c244b23a 100644 --- a/gcc/tree-ssa-math-opts.cc +++ b/gcc/tree-ssa-math-opts.cc @@ -4025,6 +4025,7 @@ extern bool gimple_unsigned_integer_sat_trunc (tree, tree*, tree (*)(tree)); extern bool gimple_signed_integer_sat_add (tree, tree*, tree (*)(tree)); extern bool gimple_signed_integer_sat_sub (tree, tree*, tree (*)(tree)); +extern bool gimple_signed_integer_sat_trunc (tree, tree*, tree (*)(tree)); static void build_saturation_binary_arith_call (gimple_stmt_iterator *gsi, internal_fn fn, @@ -4207,6 +4208,65 @@ match_unsigned_saturation_trunc (gimple_stmt_iterator *gsi, gassign *stmt) } } +/* + * Try to match saturation truncate. + * Aka: + * x.0_1 = (unsigned long) x_4(D); + * _2 = x.0_1 + 2147483648; + * if (_2 > 4294967295) + * goto ; [50.00%] + * else + * goto ; [50.00%] + * ;; succ: 4 + * ;; 3 + * + * ;; basic block 3, loop depth 0 + * ;; pred: 2 + * trunc_5 = (int32_t) x_4(D); + * goto ; [100.00%] + * ;; succ: 5 + * + * ;; basic block 4, loop depth 0 + * ;; pred: 2 + * _7 = x_4(D) < 0; + * _8 = (int) _7; + * _9 = -_8; + * _10 = _9 ^ 2147483647; + * ;; succ: 5 + * + * ;; basic block 5, loop depth 0 + * ;; pred: 3 + * ;; 4 + * # _3 = PHI + * => + * _6 = .SAT_TRUNC (x_4(D)); + */ + +static void +match_saturation_trunc (gimple_stmt_iterator *gsi, gphi *phi) +{ + if (gimple_phi_num_args (phi) != 2) + return; + + tree ops[1]; + tree phi_result = gimple_phi_result (phi); + tree type = TREE_TYPE (phi_result); + + if ((gimple_unsigned_integer_sat_trunc (phi_result, ops, NULL) + || gimple_signed_integer_sat_trunc (phi_result, ops, NULL)) + && direct_internal_fn_supported_p (IFN_SAT_TRUNC, + tree_pair (type, TREE_TYPE (ops[0])), + OPTIMIZE_FOR_BOTH)) + { + gcall *call = gimple_build_call_internal (IFN_SAT_TRUNC, 1, ops[0]); + gimple_call_set_lhs (call, phi_result); + gsi_insert_before (gsi, call, GSI_SAME_STMT); + + gimple_stmt_iterator psi = gsi_for_stmt (phi); + remove_phi_node (&psi, /* release_lhs_p */ false); + } +} + /* Recognize for unsigned x x = y - z; if (x > y) @@ -6142,6 +6202,7 @@ math_opts_dom_walker::after_dom_children (basic_block bb) /* The match_* may remove phi node. */ match_saturation_add (&gsi, psi.phi ()); match_saturation_sub (&gsi, psi.phi ()); + match_saturation_trunc (&gsi, psi.phi ()); } for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi);) From patchwork Tue Oct 8 08:32:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1994055 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=XggaogNi; 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 4XN8Xc0mCpz1xvB for ; Tue, 8 Oct 2024 19:37:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A6C33870C12 for ; Tue, 8 Oct 2024 08:37:09 +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.12]) by sourceware.org (Postfix) with ESMTPS id DE83D3875471 for ; Tue, 8 Oct 2024 08:36:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE83D3875471 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 DE83D3875471 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728376596; cv=none; b=UcwGs/ZmK0Zpczl1XtMQhdGpQJGR+/+UIgobotEMv8qKeHzCGkyxEvQubAifgzTJeHq8V7cRJi/2rQJZ5xx99xesG5RapgpwVNShZWDFoP+IAqGNEAN3mMEoRTXHSMl4up1R0lBziQNhNMF+f73TAv1VzbOn80quwEgrqnfUc40= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728376596; c=relaxed/simple; bh=XAvk4V5PEonys5V0jpNnMLJBtr6SPbwzC/e6aXNY7o8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WjxQzkiEiRCuyC+FgqAzz/1akGdwXGOKTwjI4IDDf3WyKP6ziJNnwcup0aM6OCU5rq4O+AydKe210P7Zcr6VwqseD8CpYKzmBla2ElGvlrFQOaXaWvEKXOsCheypCeaI/PusPAypwrRPwjSWI4/d+bLUkpVW0bqBElU0TltVyOI= 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=1728376589; x=1759912589; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=XAvk4V5PEonys5V0jpNnMLJBtr6SPbwzC/e6aXNY7o8=; b=XggaogNi8WFvkb0hx9veHyjxYqs/MG3xGPMnGUKS28YnT5lSmzGkeYdr dpJTd9vLIsF2HKnDnt8rcmTUbNOzxbBbW30aZfl+CCNV8e4EUDIEmgz+e 8m48HCI9Tlxd0cNEEETOVeinqmEFhIFr0dx0Kk8miUddp14XigwZlLuAm qS0gnlx64kKeCBcDLfsKyMh0gOE1uiXcPak640yCy+g7sDofIBD34PBuu jxTZcGFhNjtGmlxvN8d61u7680xJXnvZllbqDM4pJYAyGemxq4j+1U9nP 3AGYfsyKXzWPw/Iv0M3Nov+AG00GD1VUa/83URmhXHatSnvm82HLSvq/S Q==; X-CSE-ConnectionGUID: pa7xO+dYRJCz0REjU807MQ== X-CSE-MsgGUID: C4dVmUUkQT+6vKkUfk84RQ== X-IronPort-AV: E=McAfee;i="6700,10204,11218"; a="38946594" X-IronPort-AV: E=Sophos;i="6.11,186,1725346800"; d="scan'208";a="38946594" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2024 01:34:28 -0700 X-CSE-ConnectionGUID: XrT0KglPT7K+98hpGDC2pw== X-CSE-MsgGUID: BPy1mL8+Q9aGHxwspjlFHw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,186,1725346800"; d="scan'208";a="80738624" Received: from panli.sh.intel.com ([10.239.154.73]) by orviesa004.jf.intel.com with ESMTP; 08 Oct 2024 01:34:25 -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 2/4] Widening-Mul: Fix one bug of consume after phi node released Date: Tue, 8 Oct 2024 16:32:59 +0800 Message-ID: <20241008083259.189445-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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 When try to matching saturation related pattern on PHI node, we may have to try each pattern for all phi node of bb. Aka: for each PHI node in bb: gphi *phi = xxx; try_match_sat_add (, phi); try_match_sat_sub (, phi); try_match_sat_trunc (, phi); The PHI node will be removed if one of the above 3 sat patterns are matched. There will be a problem that, for example, sat_add is matched and then the phi is removed(freed), and the next 2 sat_sub and sat_trunc will depend on the removed(freed) phi node. This patch would like to fix this consume after phi node released issue. To ensure at most one pattern of the above will be matched. The below test suites are passed for this patch. * The rv64gcv fully regression test. * The x86 bootstrap test. * The x86 fully regression test. gcc/ChangeLog: * tree-ssa-math-opts.cc (build_saturation_binary_arith_call): Rename to... (build_saturation_binary_arith_call_and_replace): ...this. (build_saturation_binary_arith_call_and_insert): ...this. (match_unsigned_saturation_add): Leverage renamed func. (match_unsigned_saturation_sub): Ditto. (match_saturation_add): Return bool on matched and leverage renamed func. (match_saturation_sub): Ditto. (match_saturation_trunc): Ditto. (math_opts_dom_walker::after_dom_children): Ensure at most one pattern will be matched for each phi node. Signed-off-by: Pan Li --- gcc/tree-ssa-math-opts.cc | 102 +++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 46 deletions(-) diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc index 831c244b23a..8e83eb15d91 100644 --- a/gcc/tree-ssa-math-opts.cc +++ b/gcc/tree-ssa-math-opts.cc @@ -4028,8 +4028,9 @@ extern bool gimple_signed_integer_sat_sub (tree, tree*, tree (*)(tree)); extern bool gimple_signed_integer_sat_trunc (tree, tree*, tree (*)(tree)); static void -build_saturation_binary_arith_call (gimple_stmt_iterator *gsi, internal_fn fn, - tree lhs, tree op_0, tree op_1) +build_saturation_binary_arith_call_and_replace (gimple_stmt_iterator *gsi, + internal_fn fn, tree lhs, + tree op_0, tree op_1) { if (direct_internal_fn_supported_p (fn, TREE_TYPE (lhs), OPTIMIZE_FOR_BOTH)) { @@ -4039,20 +4040,19 @@ build_saturation_binary_arith_call (gimple_stmt_iterator *gsi, internal_fn fn, } } -static void -build_saturation_binary_arith_call (gimple_stmt_iterator *gsi, gphi *phi, - internal_fn fn, tree lhs, tree op_0, - tree op_1) +static bool +build_saturation_binary_arith_call_and_insert (gimple_stmt_iterator *gsi, + internal_fn fn, tree lhs, + tree op_0, tree op_1) { - if (direct_internal_fn_supported_p (fn, TREE_TYPE (op_0), OPTIMIZE_FOR_BOTH)) - { - gcall *call = gimple_build_call_internal (fn, 2, op_0, op_1); - gimple_call_set_lhs (call, lhs); - gsi_insert_before (gsi, call, GSI_SAME_STMT); + if (!direct_internal_fn_supported_p (fn, TREE_TYPE (op_0), OPTIMIZE_FOR_BOTH)) + return false; - gimple_stmt_iterator psi = gsi_for_stmt (phi); - remove_phi_node (&psi, /* release_lhs_p */ false); - } + gcall *call = gimple_build_call_internal (fn, 2, op_0, op_1); + gimple_call_set_lhs (call, lhs); + gsi_insert_before (gsi, call, GSI_SAME_STMT); + + return true; } /* @@ -4072,7 +4072,8 @@ match_unsigned_saturation_add (gimple_stmt_iterator *gsi, gassign *stmt) tree lhs = gimple_assign_lhs (stmt); if (gimple_unsigned_integer_sat_add (lhs, ops, NULL)) - build_saturation_binary_arith_call (gsi, IFN_SAT_ADD, lhs, ops[0], ops[1]); + build_saturation_binary_arith_call_and_replace (gsi, IFN_SAT_ADD, lhs, + ops[0], ops[1]); } /* @@ -4114,19 +4115,22 @@ match_unsigned_saturation_add (gimple_stmt_iterator *gsi, gassign *stmt) * => * _6 = .SAT_ADD (x_5(D), y_6(D)); [tail call] */ -static void +static bool match_saturation_add (gimple_stmt_iterator *gsi, gphi *phi) { if (gimple_phi_num_args (phi) != 2) - return; + return false; tree ops[2]; tree phi_result = gimple_phi_result (phi); - if (gimple_unsigned_integer_sat_add (phi_result, ops, NULL) - || gimple_signed_integer_sat_add (phi_result, ops, NULL)) - build_saturation_binary_arith_call (gsi, phi, IFN_SAT_ADD, phi_result, - ops[0], ops[1]); + if (!gimple_unsigned_integer_sat_add (phi_result, ops, NULL) + && !gimple_signed_integer_sat_add (phi_result, ops, NULL)) + return false; + + return build_saturation_binary_arith_call_and_insert (gsi, IFN_SAT_ADD, + phi_result, ops[0], + ops[1]); } /* @@ -4144,7 +4148,8 @@ match_unsigned_saturation_sub (gimple_stmt_iterator *gsi, gassign *stmt) tree lhs = gimple_assign_lhs (stmt); if (gimple_unsigned_integer_sat_sub (lhs, ops, NULL)) - build_saturation_binary_arith_call (gsi, IFN_SAT_SUB, lhs, ops[0], ops[1]); + build_saturation_binary_arith_call_and_replace (gsi, IFN_SAT_SUB, lhs, + ops[0], ops[1]); } /* @@ -4163,19 +4168,22 @@ match_unsigned_saturation_sub (gimple_stmt_iterator *gsi, gassign *stmt) * => * [local count: 1073741824]: * _1 = .SAT_SUB (x_2(D), y_3(D)); */ -static void +static bool match_saturation_sub (gimple_stmt_iterator *gsi, gphi *phi) { if (gimple_phi_num_args (phi) != 2) - return; + return false; tree ops[2]; tree phi_result = gimple_phi_result (phi); - if (gimple_unsigned_integer_sat_sub (phi_result, ops, NULL) - || gimple_signed_integer_sat_sub (phi_result, ops, NULL)) - build_saturation_binary_arith_call (gsi, phi, IFN_SAT_SUB, phi_result, - ops[0], ops[1]); + if (!gimple_unsigned_integer_sat_sub (phi_result, ops, NULL) + && !gimple_signed_integer_sat_sub (phi_result, ops, NULL)) + return false; + + return build_saturation_binary_arith_call_and_insert (gsi, IFN_SAT_SUB, + phi_result, ops[0], + ops[1]); } /* @@ -4242,29 +4250,30 @@ match_unsigned_saturation_trunc (gimple_stmt_iterator *gsi, gassign *stmt) * _6 = .SAT_TRUNC (x_4(D)); */ -static void +static bool match_saturation_trunc (gimple_stmt_iterator *gsi, gphi *phi) { if (gimple_phi_num_args (phi) != 2) - return; + return false; tree ops[1]; tree phi_result = gimple_phi_result (phi); tree type = TREE_TYPE (phi_result); - if ((gimple_unsigned_integer_sat_trunc (phi_result, ops, NULL) - || gimple_signed_integer_sat_trunc (phi_result, ops, NULL)) - && direct_internal_fn_supported_p (IFN_SAT_TRUNC, - tree_pair (type, TREE_TYPE (ops[0])), - OPTIMIZE_FOR_BOTH)) - { - gcall *call = gimple_build_call_internal (IFN_SAT_TRUNC, 1, ops[0]); - gimple_call_set_lhs (call, phi_result); - gsi_insert_before (gsi, call, GSI_SAME_STMT); + if (!gimple_unsigned_integer_sat_trunc (phi_result, ops, NULL) + && !gimple_signed_integer_sat_trunc (phi_result, ops, NULL)) + return false; - gimple_stmt_iterator psi = gsi_for_stmt (phi); - remove_phi_node (&psi, /* release_lhs_p */ false); - } + if (!direct_internal_fn_supported_p (IFN_SAT_TRUNC, + tree_pair (type, TREE_TYPE (ops[0])), + OPTIMIZE_FOR_BOTH)) + return false; + + gcall *call = gimple_build_call_internal (IFN_SAT_TRUNC, 1, ops[0]); + gimple_call_set_lhs (call, phi_result); + gsi_insert_before (gsi, call, GSI_SAME_STMT); + + return true; } /* Recognize for unsigned x @@ -6198,11 +6207,12 @@ math_opts_dom_walker::after_dom_children (basic_block bb) gsi_next (&psi_next); gimple_stmt_iterator gsi = gsi_after_labels (bb); + gphi *phi = psi.phi (); - /* The match_* may remove phi node. */ - match_saturation_add (&gsi, psi.phi ()); - match_saturation_sub (&gsi, psi.phi ()); - match_saturation_trunc (&gsi, psi.phi ()); + if (match_saturation_add (&gsi, phi) + || match_saturation_sub (&gsi, phi) + || match_saturation_trunc (&gsi, phi)) + remove_phi_node (&psi, /* release_lhs_p */ false); } for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi);) From patchwork Tue Oct 8 08:33:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1994056 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=KcLZrevH; 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 4XN8Xh4DvTz1xvB for ; Tue, 8 Oct 2024 19:37:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5CF323842423 for ; Tue, 8 Oct 2024 08:37:13 +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.12]) by sourceware.org (Postfix) with ESMTPS id 81A0E3842FEB for ; Tue, 8 Oct 2024 08:36:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81A0E3842FEB 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 81A0E3842FEB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728376596; cv=none; b=TJ4SRhEapCRIHGEKCjrxt4ngeNxnu0Qb4E95Zfij8J05+1NXaKU1Fg5sOm0kHvwT2cBmE8QwIDqQ1N/h3hc/uv4aN25GBBqXqmDkosYUMRbD+UYFFiIj1r53xwBIKlf0H70uyvusG+WnGYYswFXM7RRL67MQHnYjXOICdOTesCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728376596; c=relaxed/simple; bh=iySokgMm4MN2x4MMJF0amoN0HCGYCI9I2G8isQLuTW4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VnT3ZZJggFR0Z9lBqZLveHDZqVsQSoJMQYUOVCSzmYnqd8JtQc60vZo2rJieKRLUyh7gJM5KWxOA3r+cGArTxMiULKDeKcMQWVLWG3XwDlUyC6sT0WsW/ROxAt7q9NrYmEtxgCGA/d/WtCBiYZ/gMaPmEETf6ZGekQpXelZvW6M= 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=1728376590; x=1759912590; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=iySokgMm4MN2x4MMJF0amoN0HCGYCI9I2G8isQLuTW4=; b=KcLZrevHR3pcjQyIHuWdQ28uE+GprqeSFPKq2X2BoNGx2yd3r6ns526G qrZpo4jt6FZLHbidqvFfBrNf3L02YXZWY+WgTHNO5AKsjew0R0H9I2RLk fji6gME3mHWRcnnLe9dOfnXWHYp5pGJjZpwPb6T8CBQaQiqKJz3c4gdKU 5jAo5wA36Pfqtfo4CMZFjomedNOYQqCnBBezlu+WON76ZEJWdzi0Fp1xy 6cqspqfO5HZb8lAZZlCrD9iZb3BMhv6RO3Uwq0dJw62acQkiMdzrjGODq ygdGYmv9qlrSm92VdMcedC9LSvoOKCIhO1/6stm9oDi2dcpgDxoTMKRmM g==; X-CSE-ConnectionGUID: veoIOt9RSqKS2EjZez2N0A== X-CSE-MsgGUID: TjPfAAlgS/KDGXNw8+f3Fg== X-IronPort-AV: E=McAfee;i="6700,10204,11218"; a="38946643" X-IronPort-AV: E=Sophos;i="6.11,186,1725346800"; d="scan'208";a="38946643" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2024 01:34:44 -0700 X-CSE-ConnectionGUID: yxk6kwSTTi6Mf1NuXDsHKA== X-CSE-MsgGUID: 3M2/A3rFSsC+0+zXvUJJBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,186,1725346800"; d="scan'208";a="80738744" Received: from panli.sh.intel.com ([10.239.154.73]) by orviesa004.jf.intel.com with ESMTP; 08 Oct 2024 01:34:41 -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 3/4] RISC-V: Implement scalar SAT_TRUNC for signed integer Date: Tue, 8 Oct 2024 16:33:15 +0800 Message-ID: <20241008083315.190027-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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 implement the sstrunc for scalar signed integer. Form 1: #define DEF_SAT_S_TRUNC_FMT_1(WT, NT, NT_MIN, NT_MAX) \ NT __attribute__((noinline)) \ sat_s_trunc_##WT##_to_##NT##_fmt_1 (WT x) \ { \ NT trunc = (NT)x; \ return (WT)NT_MIN <= x && x <= (WT)NT_MAX \ ? trunc \ : x < 0 ? NT_MIN : NT_MAX; \ } DEF_SAT_S_TRUNC_FMT_1(int64_t, int32_t, INT32_MIN, INT32_MAX) Before this patch: 10 │ sat_s_trunc_int64_t_to_int32_t_fmt_1: 11 │ li a5,1 12 │ slli a5,a5,31 13 │ li a4,-1 14 │ add a5,a0,a5 15 │ srli a4,a4,32 16 │ bgtu a5,a4,.L2 17 │ sext.w a0,a0 18 │ ret 19 │ .L2: 20 │ srai a5,a0,63 21 │ li a0,-2147483648 22 │ xor a0,a0,a5 23 │ not a0,a0 24 │ ret After this patch: 10 │ sat_s_trunc_int64_t_to_int32_t_fmt_1: 11 │ li a5,-2147483648 12 │ xori a3,a5,-1 13 │ slt a4,a0,a3 14 │ slt a5,a5,a0 15 │ and a5,a4,a5 16 │ srai a4,a0,63 17 │ xor a4,a4,a3 18 │ addi a3,a5,-1 19 │ neg a5,a5 20 │ and a4,a4,a3 21 │ and a0,a0,a5 22 │ or a0,a0,a4 23 │ sext.w a0,a0 24 │ ret The below test suites are passed for this patch. * The rv64gcv fully regression test. gcc/ChangeLog: * config/riscv/riscv-protos.h (riscv_expand_sstrunc): Add new func decl to expand SAT_TRUNC. * config/riscv/riscv.cc (riscv_expand_sstrunc): Add new func impl to expand SAT_TRUNC. * config/riscv/riscv.md (sstrunc2): Add new pattern for double truncation. (sstrunc2): Ditto but for quad. (sstrunc2): Ditto but for oct. Signed-off-by: Pan Li --- gcc/config/riscv/riscv-protos.h | 1 + gcc/config/riscv/riscv.cc | 61 +++++++++++++++++++++++++++++++++ gcc/config/riscv/riscv.md | 30 ++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 3d8775e582d..1e6d10a1402 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -138,6 +138,7 @@ extern void riscv_expand_ssadd (rtx, rtx, rtx); extern void riscv_expand_ussub (rtx, rtx, rtx); extern void riscv_expand_sssub (rtx, rtx, rtx); extern void riscv_expand_ustrunc (rtx, rtx); +extern void riscv_expand_sstrunc (rtx, rtx); #ifdef RTX_CODE extern void riscv_expand_int_scc (rtx, enum rtx_code, rtx, rtx, bool *invert_ptr = 0); diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 8708a7b42c6..57f2554d491 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -12438,6 +12438,67 @@ riscv_expand_ustrunc (rtx dest, rtx src) emit_move_insn (dest, gen_lowpart (mode, xmode_dest)); } +/* Implement the signed saturation truncation for int mode. + + b = SAT_TRUNC (a); + => + 1. lt = a < max + 2. gt = min < a + 3. mask = lt & gt + 4. trunc_mask = -mask + 5. sat_mask = mask - 1 + 6. lt = a < 0 + 7. neg = -lt + 8. sat = neg ^ max + 9. trunc = src & trunc_mask + 10. sat = sat & sat_mask + 11. dest = trunc | sat */ + +void +riscv_expand_sstrunc (rtx dest, rtx src) +{ + machine_mode mode = GET_MODE (dest); + unsigned narrow_prec = GET_MODE_PRECISION (mode).to_constant (); + HOST_WIDE_INT narrow_max = ((int64_t)1 << (narrow_prec - 1)) - 1; // 127 + HOST_WIDE_INT narrow_min = -narrow_max - 1; // -128 + + rtx xmode_narrow_max = gen_reg_rtx (Xmode); + rtx xmode_narrow_min = gen_reg_rtx (Xmode); + rtx xmode_lt = gen_reg_rtx (Xmode); + rtx xmode_gt = gen_reg_rtx (Xmode); + rtx xmode_src = gen_lowpart (Xmode, src); + rtx xmode_dest = gen_reg_rtx (Xmode); + rtx xmode_mask = gen_reg_rtx (Xmode); + rtx xmode_sat = gen_reg_rtx (Xmode); + rtx xmode_trunc = gen_reg_rtx (Xmode); + rtx xmode_sat_mask = gen_reg_rtx (Xmode); + rtx xmode_trunc_mask = gen_reg_rtx (Xmode); + + /* Step-1: lt = src < max, gt = min < src, mask = lt & gt */ + emit_move_insn (xmode_narrow_min, gen_int_mode (narrow_min, Xmode)); + emit_move_insn (xmode_narrow_max, gen_int_mode (narrow_max, Xmode)); + riscv_emit_binary (LT, xmode_lt, xmode_src, xmode_narrow_max); + riscv_emit_binary (LT, xmode_gt, xmode_narrow_min, xmode_src); + riscv_emit_binary (AND, xmode_mask, xmode_lt, xmode_gt); + + /* Step-2: sat_mask = mask - 1, trunc_mask = ~mask */ + riscv_emit_binary (PLUS, xmode_sat_mask, xmode_mask, CONSTM1_RTX (Xmode)); + riscv_emit_unary (NEG, xmode_trunc_mask, xmode_mask); + + /* Step-3: lt = src < 0, lt = -lt, sat = lt ^ narrow_max */ + riscv_emit_binary (LT, xmode_lt, xmode_src, CONST0_RTX (Xmode)); + riscv_emit_unary (NEG, xmode_lt, xmode_lt); + riscv_emit_binary (XOR, xmode_sat, xmode_lt, xmode_narrow_max); + + /* Step-4: xmode_dest = (src & trunc_mask) | (sat & sat_mask) */ + riscv_emit_binary (AND, xmode_trunc, xmode_src, xmode_trunc_mask); + riscv_emit_binary (AND, xmode_sat, xmode_sat, xmode_sat_mask); + riscv_emit_binary (IOR, xmode_dest, xmode_trunc, xmode_sat); + + /* Step-5: dest = xmode_dest */ + emit_move_insn (dest, gen_lowpart (mode, xmode_dest)); +} + /* Implement TARGET_C_MODE_FOR_FLOATING_TYPE. Return TFmode for TI_LONG_DOUBLE_TYPE which is for long double type, go with the default one for the others. */ diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 067c2415db1..688c07df46c 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -4413,6 +4413,16 @@ (define_expand "ustrunc2" } ) +(define_expand "sstrunc2" + [(match_operand: 0 "register_operand") + (match_operand:ANYI_DOUBLE_TRUNC 1 "register_operand")] + "" + { + riscv_expand_sstrunc (operands[0], operands[1]); + DONE; + } +) + (define_expand "ustrunc2" [(match_operand: 0 "register_operand") (match_operand:ANYI_QUAD_TRUNC 1 "register_operand")] @@ -4423,6 +4433,16 @@ (define_expand "ustrunc2" } ) +(define_expand "sstrunc2" + [(match_operand: 0 "register_operand") + (match_operand:ANYI_QUAD_TRUNC 1 "register_operand")] + "" + { + riscv_expand_sstrunc (operands[0], operands[1]); + DONE; + } +) + (define_expand "ustrunc2" [(match_operand: 0 "register_operand") (match_operand:ANYI_OCT_TRUNC 1 "register_operand")] @@ -4433,6 +4453,16 @@ (define_expand "ustrunc2" } ) +(define_expand "sstrunc2" + [(match_operand: 0 "register_operand") + (match_operand:ANYI_OCT_TRUNC 1 "register_operand")] + "" + { + riscv_expand_sstrunc (operands[0], operands[1]); + DONE; + } +) + ;; These are forms of (x << C1) + C2, potentially canonicalized from ;; ((x + C2') << C1. Depending on the cost to load C2 vs C2' we may ;; want to go ahead and recognize this form as C2 may be cheaper to From patchwork Tue Oct 8 08:33: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: 1994053 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=UPWkc66U; 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 4XN8Vz27nHz1xvB for ; Tue, 8 Oct 2024 19:36:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 840183894C3C for ; Tue, 8 Oct 2024 08:35:29 +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 [192.198.163.7]) by sourceware.org (Postfix) with ESMTPS id 827253885C25 for ; Tue, 8 Oct 2024 08:34:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 827253885C25 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 827253885C25 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728376503; cv=none; b=ZkjPNX4ce3GPmINmE804OSsHnLoPVg7dnn54AX4A9qzTc/cGpj6yTQ34WuV1D5mvVR7rPSGioHdfmfiBdCXVVuNmpL1j/3YXiuZUeG+kY+FjCFtGIzMrtc10O/X/bcTZeDNvK2qmcROzNfaI1h3Q/j3Mvr8dTlcddl9GuSbdESo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728376503; c=relaxed/simple; bh=kQtbDwmFwz6p353lEB6M9IpGd7CDSG62v1W4WDTqvtY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hyhQPZIIhsL3rm97XPBGCrOX5KpbIuI+tHylYuT61AG4djkNJ/hSvj6T1d/EfyiuH+qKa7vMNo3xceZSpOIUN1rHgJySzG+b+J6NvbFgBFE9yB4q7dVy7D9LUryPjQs0VYWvMnWpcZ3HCwAut8vFmEDIqqHMU0DxEtLb0v6gLkc= 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=1728376495; x=1759912495; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=kQtbDwmFwz6p353lEB6M9IpGd7CDSG62v1W4WDTqvtY=; b=UPWkc66UVdjnuTweyxfBlJgvEpylT8ZgMKMJeJwlXRUYt4hBQDwCehwN o8VOE44bT5XP7zSI0jpEvXqIjCOpSTjk+ypHwGg+32uklcbL50xAiMjXv Q4I2virPlP20uBGBSxX/RllkzRBXEZZroC6dKwlLoK/FmLNr9qVWTis9F 6MJXxVTixIvFVpOZ0gb6q3urOYQ0/vKcvUDNgLwiWPlu08neS3ZxFL+yT dwIvgTBGu7MP4kOg0iIjI9TuyXz9doVsFZajBTA+sLsKLcrBmAX/0uMlD e4GmrJVuOrrK4Jrvx4BOSIL/Cy0+WNCR0JBVIzzxFoS/BulsgjzH0HgBu A==; X-CSE-ConnectionGUID: k6woPXf9QuWrDrZMU+gxQg== X-CSE-MsgGUID: KxYuADdOTmKLjwTxBIq9fA== X-IronPort-AV: E=McAfee;i="6700,10204,11218"; a="52961343" X-IronPort-AV: E=Sophos;i="6.11,186,1725346800"; d="scan'208";a="52961343" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2024 01:34:54 -0700 X-CSE-ConnectionGUID: AXpNSZtvQ1G6CyMtvoe15w== X-CSE-MsgGUID: jaPKxKxGSvGberkOszW2XQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,186,1725346800"; d="scan'208";a="80593124" Received: from panli.sh.intel.com ([10.239.154.73]) by orviesa003.jf.intel.com with ESMTP; 08 Oct 2024 01:34:51 -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 4/4] RISC-V: Add testcases for form 1 of scalar signed SAT_TRUNC Date: Tue, 8 Oct 2024 16:33:25 +0800 Message-ID: <20241008083325.190374-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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 Form 1: #define DEF_SAT_S_TRUNC_FMT_1(WT, NT, NT_MIN, NT_MAX) \ NT __attribute__((noinline)) \ sat_s_trunc_##WT##_to_##NT##_fmt_1 (WT x) \ { \ NT trunc = (NT)x; \ return (WT)NT_MIN <= x && x <= (WT)NT_MAX \ ? trunc \ : x < 0 ? NT_MIN : NT_MAX; \ } The below test are passed for this patch. * The rv64gcv fully regression test. It is test only patch and obvious up to a point, will commit it directly if no comments in next 48H. gcc/testsuite/ChangeLog: * gcc.target/riscv/sat_arith.h: Add test helper macros. * gcc.target/riscv/sat_arith_data.h: Add test data for SAT_TRUNC. * gcc.target/riscv/sat_s_trunc-1-i16-to-i8.c: New test. * gcc.target/riscv/sat_s_trunc-1-i32-to-i16.c: New test. * gcc.target/riscv/sat_s_trunc-1-i32-to-i8.c: New test. * gcc.target/riscv/sat_s_trunc-1-i64-to-i16.c: New test. * gcc.target/riscv/sat_s_trunc-1-i64-to-i32.c: New test. * gcc.target/riscv/sat_s_trunc-1-i64-to-i8.c: New test. * gcc.target/riscv/sat_s_trunc-run-1-i16-to-i8.c: New test. * gcc.target/riscv/sat_s_trunc-run-1-i32-to-i16.c: New test. * gcc.target/riscv/sat_s_trunc-run-1-i32-to-i8.c: New test. * gcc.target/riscv/sat_s_trunc-run-1-i64-to-i16.c: New test. * gcc.target/riscv/sat_s_trunc-run-1-i64-to-i32.c: New test. * gcc.target/riscv/sat_s_trunc-run-1-i64-to-i8.c: New test. Signed-off-by: Pan Li --- gcc/testsuite/gcc.target/riscv/sat_arith.h | 15 +++ .../gcc.target/riscv/sat_arith_data.h | 110 ++++++++++++++++++ .../riscv/sat_s_trunc-1-i16-to-i8.c | 26 +++++ .../riscv/sat_s_trunc-1-i32-to-i16.c | 28 +++++ .../riscv/sat_s_trunc-1-i32-to-i8.c | 26 +++++ .../riscv/sat_s_trunc-1-i64-to-i16.c | 28 +++++ .../riscv/sat_s_trunc-1-i64-to-i32.c | 26 +++++ .../riscv/sat_s_trunc-1-i64-to-i8.c | 26 +++++ .../riscv/sat_s_trunc-run-1-i16-to-i8.c | 16 +++ .../riscv/sat_s_trunc-run-1-i32-to-i16.c | 16 +++ .../riscv/sat_s_trunc-run-1-i32-to-i8.c | 16 +++ .../riscv/sat_s_trunc-run-1-i64-to-i16.c | 16 +++ .../riscv/sat_s_trunc-run-1-i64-to-i32.c | 16 +++ .../riscv/sat_s_trunc-run-1-i64-to-i8.c | 16 +++ 14 files changed, 381 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i16-to-i8.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i32-to-i16.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i32-to-i8.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i16.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i32.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i8.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i16-to-i8.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i32-to-i16.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i32-to-i8.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i16.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i32.c create mode 100644 gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i8.c diff --git a/gcc/testsuite/gcc.target/riscv/sat_arith.h b/gcc/testsuite/gcc.target/riscv/sat_arith.h index 7c3859cc183..80d7a69e7d9 100644 --- a/gcc/testsuite/gcc.target/riscv/sat_arith.h +++ b/gcc/testsuite/gcc.target/riscv/sat_arith.h @@ -465,4 +465,19 @@ sat_u_trunc_##WT##_to_##NT##_fmt_4 (WT x) \ #define RUN_SAT_U_TRUNC_FMT_4(NT, WT, x) sat_u_trunc_##WT##_to_##NT##_fmt_4 (x) #define RUN_SAT_U_TRUNC_FMT_4_WRAP(NT, WT, x) RUN_SAT_U_TRUNC_FMT_4(NT, WT, x) +#define DEF_SAT_S_TRUNC_FMT_1(NT, WT, NT_MIN, NT_MAX) \ +NT __attribute__((noinline)) \ +sat_s_trunc_##WT##_to_##NT##_fmt_1 (WT x) \ +{ \ + NT trunc = (NT)x; \ + return (WT)NT_MIN <= x && x <= (WT)NT_MAX \ + ? trunc \ + : x < 0 ? NT_MIN : NT_MAX; \ +} +#define DEF_SAT_S_TRUNC_FMT_1_WRAP(NT, WT, NT_MIN, NT_MAX) \ + DEF_SAT_S_TRUNC_FMT_1(NT, WT, NT_MIN, NT_MAX) + +#define RUN_SAT_S_TRUNC_FMT_1(NT, WT, x) sat_s_trunc_##WT##_to_##NT##_fmt_1 (x) +#define RUN_SAT_S_TRUNC_FMT_1_WRAP(NT, WT, x) RUN_SAT_S_TRUNC_FMT_1(NT, WT, x) + #endif diff --git a/gcc/testsuite/gcc.target/riscv/sat_arith_data.h b/gcc/testsuite/gcc.target/riscv/sat_arith_data.h index 39a1e17cd3d..9f9f7d0bcd1 100644 --- a/gcc/testsuite/gcc.target/riscv/sat_arith_data.h +++ b/gcc/testsuite/gcc.target/riscv/sat_arith_data.h @@ -42,6 +42,13 @@ TEST_BINARY_STRUCT (int16_t, sssub) TEST_BINARY_STRUCT (int32_t, sssub) TEST_BINARY_STRUCT (int64_t, sssub) +TEST_UNARY_STRUCT (int8_t, int16_t) +TEST_UNARY_STRUCT (int8_t, int32_t) +TEST_UNARY_STRUCT (int8_t, int64_t) +TEST_UNARY_STRUCT (int16_t, int32_t) +TEST_UNARY_STRUCT (int16_t, int64_t) +TEST_UNARY_STRUCT (int32_t, int64_t) + TEST_UNARY_STRUCT_DECL(uint8_t, uint16_t) \ TEST_UNARY_DATA(uint8_t, uint16_t)[] = { @@ -126,6 +133,109 @@ TEST_UNARY_STRUCT_DECL(uint32_t, uint64_t) \ {4294967295, 18446744073709551615u}, }; +TEST_UNARY_STRUCT_DECL(int8_t, int16_t) \ + TEST_UNARY_DATA(int8_t, int16_t)[] = +{ + { 0, 0}, + { -2, -2}, + { 127, 128}, + { 127, 258}, + {-128, -128}, + {-128, -129}, + {-128, -257}, + { 127, 32767}, + {-128, -32768}, +}; + +TEST_UNARY_STRUCT_DECL(int8_t, int32_t) \ + TEST_UNARY_DATA(int8_t, int32_t)[] = +{ + { 0, 0}, + { -2, -2}, + { 127, 128}, + { 127, 258}, + {-128, -128}, + {-128, -129}, + {-128, -257}, + { 127, 32767}, + {-128, -32768}, + { 127, 65536}, + {-128, -65537}, + { 127, 2147483647}, + {-128, -2147483648}, +}; + +TEST_UNARY_STRUCT_DECL(int8_t, int64_t) \ + TEST_UNARY_DATA(int8_t, int64_t)[] = +{ + { 0, 0}, + { -2, -2}, + { 127, 128}, + { 127, 258}, + {-128, -128}, + {-128, -129}, + {-128, -257}, + { 127, 32767}, + {-128, -32768}, + { 127, 65536}, + {-128, -65537}, + { 127, 2147483647}, + {-128, -2147483648}, + { 127, 2147483648ll}, + {-128, -2147483649ll}, + { 127, 9223372036854775807ll}, + {-128, -9223372036854775808ull}, +}; + +TEST_UNARY_STRUCT_DECL(int16_t, int32_t) \ + TEST_UNARY_DATA(int16_t, int32_t)[] = +{ + { 0, 0}, + { -2, -2}, + { 32767, 32768}, + { 32767, 65538}, + {-32768, -32768}, + {-32768, -32769}, + {-32768, -65539}, + { 32767, 32767}, + {-32768, -32768}, + { 32767, 65536}, + {-32768, -65537}, + { 32767, 2147483647}, + {-32768, -2147483648}, +}; + +TEST_UNARY_STRUCT_DECL(int16_t, int64_t) \ + TEST_UNARY_DATA(int16_t, int64_t)[] = +{ + { 0, 0}, + { -2, -2}, + { 32767, 32768}, + { 32767, 65538}, + {-32768, -32768}, + {-32768, -32769}, + {-32768, -65539}, + { 32767, 32767}, + {-32768, -32768}, + { 32767, 65536}, + {-32768, -65537}, + { 32767, 2147483647}, + {-32768, -2147483648}, +}; + +TEST_UNARY_STRUCT_DECL(int32_t, int64_t) \ + TEST_UNARY_DATA(int32_t, int64_t)[] = +{ + { 0, 0}, + { -2, -2}, + { 2147483647, 2147483648ll}, + {-2147483648, -2147483648}, + { 2147483647, 2147483648}, + {-2147483648, -2147483649ll}, + { 2147483647, 9223372036854775807ll}, + {-2147483648, -9223372036854775808ull}, +}; + TEST_BINARY_STRUCT_DECL(int8_t, ssadd) TEST_BINARY_DATA(int8_t, ssadd)[] = { { 0, 0, 0}, diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i16-to-i8.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i16-to-i8.c new file mode 100644 index 00000000000..9c14a26a727 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i16-to-i8.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include "sat_arith.h" + +/* +** sat_s_trunc_int16_t_to_int8_t_fmt_1: +** slti\s+[atx][0-9]+,\s*[atx][0-9]+,\s*127 +** li\s+[atx][0-9]+,\s*-128 +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** neg\s+[atx][0-9]+,\s*[atx][0-9]+ +** srai\s+[atx][0-9]+,\s*[atx][0-9]+,\s*63 +** xori\s+[atx][0-9]+,\s*[atx][0-9]+,\s*127 +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** or\s+a0,\s*[atx][0-9]+,\s*[atx][0-9]+ +** slliw\s+a0,\s*a0,\s*24 +** sraiw\s+a0,\s*a0,\s*24 +** ret +*/ +DEF_SAT_S_TRUNC_FMT_1(int8_t, int16_t, INT8_MIN, INT8_MAX) + +/* { dg-final { scan-rtl-dump-times ".SAT_TRUNC " 2 "expand" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i32-to-i16.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i32-to-i16.c new file mode 100644 index 00000000000..41c121762d9 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i32-to-i16.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include "sat_arith.h" + +/* +** sat_s_trunc_int32_t_to_int16_t_fmt_1: +** li\s+[atx][0-9]+,\s*32768 +** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** li\s+[atx][0-9]+,\s*-32768 +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** neg\s+[atx][0-9]+,\s*[atx][0-9]+ +** srai\s+[atx][0-9]+,\s*[atx][0-9]+,\s*63 +** xor\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** or\s+a0,\s*[atx][0-9]+,\s*[atx][0-9]+ +** slliw\s+a0,\s*a0,\s*16 +** sraiw\s+a0,\s*a0,\s*16 +** ret +*/ +DEF_SAT_S_TRUNC_FMT_1(int16_t, int32_t, INT16_MIN, INT16_MAX) + +/* { dg-final { scan-rtl-dump-times ".SAT_TRUNC " 2 "expand" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i32-to-i8.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i32-to-i8.c new file mode 100644 index 00000000000..e2f50971407 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i32-to-i8.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include "sat_arith.h" + +/* +** sat_s_trunc_int32_t_to_int8_t_fmt_1: +** slti\s+[atx][0-9]+,\s*[atx][0-9]+,\s*127 +** li\s+[atx][0-9]+,\s*-128 +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** neg\s+[atx][0-9]+,\s*[atx][0-9]+ +** srai\s+[atx][0-9]+,\s*[atx][0-9]+,\s*63 +** xori\s+[atx][0-9]+,\s*[atx][0-9]+,\s*127 +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** or\s+a0,\s*[atx][0-9]+,\s*[atx][0-9]+ +** slliw\s+a0,\s*a0,\s*24 +** sraiw\s+a0,\s*a0,\s*24 +** ret +*/ +DEF_SAT_S_TRUNC_FMT_1(int8_t, int32_t, INT8_MIN, INT8_MAX) + +/* { dg-final { scan-rtl-dump-times ".SAT_TRUNC " 2 "expand" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i16.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i16.c new file mode 100644 index 00000000000..794f13406d3 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i16.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include "sat_arith.h" + +/* +** sat_s_trunc_int64_t_to_int16_t_fmt_1: +** li\s+[atx][0-9]+,\s*32768 +** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** li\s+[atx][0-9]+,\s*-32768 +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** neg\s+[atx][0-9]+,\s*[atx][0-9]+ +** srai\s+[atx][0-9]+,\s*[atx][0-9]+,\s*63 +** xor\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** or\s+a0,\s*[atx][0-9]+,\s*[atx][0-9]+ +** slliw\s+a0,\s*a0,\s*16 +** sraiw\s+a0,\s*a0,\s*16 +** ret +*/ +DEF_SAT_S_TRUNC_FMT_1(int16_t, int64_t, INT16_MIN, INT16_MAX) + +/* { dg-final { scan-rtl-dump-times ".SAT_TRUNC " 2 "expand" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i32.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i32.c new file mode 100644 index 00000000000..742ac17ba72 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i32.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include "sat_arith.h" + +/* +** sat_s_trunc_int64_t_to_int32_t_fmt_1: +** li\s+[atx][0-9]+,\s*-2147483648 +** xori\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** neg\s+[atx][0-9]+,\s*[atx][0-9]+ +** srai\s+[atx][0-9]+,\s*[atx][0-9]+,\s*63 +** xor\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** or\s+a0,\s*[atx][0-9]+,\s*[atx][0-9]+ +** sext\.w\s+a0,\s*a0 +** ret +*/ +DEF_SAT_S_TRUNC_FMT_1(int32_t, int64_t, INT32_MIN, INT32_MAX) + +/* { dg-final { scan-rtl-dump-times ".SAT_TRUNC " 2 "expand" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i8.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i8.c new file mode 100644 index 00000000000..16139ef336f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-1-i64-to-i8.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include "sat_arith.h" + +/* +** sat_s_trunc_int64_t_to_int8_t_fmt_1: +** slti\s+[atx][0-9]+,\s*[atx][0-9]+,\s*127 +** li\s+[atx][0-9]+,\s*-128 +** slt\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1 +** neg\s+[atx][0-9]+,\s*[atx][0-9]+ +** srai\s+[atx][0-9]+,\s*[atx][0-9]+,\s*63 +** xori\s+[atx][0-9]+,\s*[atx][0-9]+,\s*127 +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+ +** or\s+a0,\s*[atx][0-9]+,\s*[atx][0-9]+ +** slliw\s+a0,\s*a0,\s*24 +** sraiw\s+a0,\s*a0,\s*24 +** ret +*/ +DEF_SAT_S_TRUNC_FMT_1(int8_t, int64_t, INT8_MIN, INT8_MAX) + +/* { dg-final { scan-rtl-dump-times ".SAT_TRUNC " 2 "expand" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i16-to-i8.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i16-to-i8.c new file mode 100644 index 00000000000..1f230c592a8 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i16-to-i8.c @@ -0,0 +1,16 @@ +/* { dg-do run { target { riscv_v } } } */ +/* { dg-additional-options "-std=c99" } */ + +#include "sat_arith.h" +#include "sat_arith_data.h" + +#define T1 int8_t +#define T2 int16_t + +DEF_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, INT8_MIN, INT8_MAX) + +#define DATA TEST_UNARY_DATA_WRAP(T1, T2) +#define T TEST_UNARY_STRUCT_DECL(T1, T2) +#define RUN_UNARY(x) RUN_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, x) + +#include "scalar_sat_unary.h" diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i32-to-i16.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i32-to-i16.c new file mode 100644 index 00000000000..563760beff5 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i32-to-i16.c @@ -0,0 +1,16 @@ +/* { dg-do run { target { riscv_v } } } */ +/* { dg-additional-options "-std=c99" } */ + +#include "sat_arith.h" +#include "sat_arith_data.h" + +#define T1 int16_t +#define T2 int32_t + +DEF_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, INT16_MIN, INT16_MAX) + +#define DATA TEST_UNARY_DATA_WRAP(T1, T2) +#define T TEST_UNARY_STRUCT_DECL(T1, T2) +#define RUN_UNARY(x) RUN_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, x) + +#include "scalar_sat_unary.h" diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i32-to-i8.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i32-to-i8.c new file mode 100644 index 00000000000..af50d3e9990 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i32-to-i8.c @@ -0,0 +1,16 @@ +/* { dg-do run { target { riscv_v } } } */ +/* { dg-additional-options "-std=c99" } */ + +#include "sat_arith.h" +#include "sat_arith_data.h" + +#define T1 int8_t +#define T2 int32_t + +DEF_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, INT8_MIN, INT8_MAX) + +#define DATA TEST_UNARY_DATA_WRAP(T1, T2) +#define T TEST_UNARY_STRUCT_DECL(T1, T2) +#define RUN_UNARY(x) RUN_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, x) + +#include "scalar_sat_unary.h" diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i16.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i16.c new file mode 100644 index 00000000000..4ac7025fa94 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i16.c @@ -0,0 +1,16 @@ +/* { dg-do run { target { riscv_v } } } */ +/* { dg-additional-options "-std=c99" } */ + +#include "sat_arith.h" +#include "sat_arith_data.h" + +#define T1 int16_t +#define T2 int64_t + +DEF_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, INT16_MIN, INT16_MAX) + +#define DATA TEST_UNARY_DATA_WRAP(T1, T2) +#define T TEST_UNARY_STRUCT_DECL(T1, T2) +#define RUN_UNARY(x) RUN_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, x) + +#include "scalar_sat_unary.h" diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i32.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i32.c new file mode 100644 index 00000000000..ca6d31cadfc --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i32.c @@ -0,0 +1,16 @@ +/* { dg-do run { target { riscv_v } } } */ +/* { dg-additional-options "-std=c99" } */ + +#include "sat_arith.h" +#include "sat_arith_data.h" + +#define T1 int32_t +#define T2 int64_t + +DEF_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, INT32_MIN, INT32_MAX) + +#define DATA TEST_UNARY_DATA_WRAP(T1, T2) +#define T TEST_UNARY_STRUCT_DECL(T1, T2) +#define RUN_UNARY(x) RUN_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, x) + +#include "scalar_sat_unary.h" diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i8.c b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i8.c new file mode 100644 index 00000000000..697e1bce404 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/sat_s_trunc-run-1-i64-to-i8.c @@ -0,0 +1,16 @@ +/* { dg-do run { target { riscv_v } } } */ +/* { dg-additional-options "-std=c99" } */ + +#include "sat_arith.h" +#include "sat_arith_data.h" + +#define T1 int8_t +#define T2 int64_t + +DEF_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, INT8_MIN, INT8_MAX) + +#define DATA TEST_UNARY_DATA_WRAP(T1, T2) +#define T TEST_UNARY_STRUCT_DECL(T1, T2) +#define RUN_UNARY(x) RUN_SAT_S_TRUNC_FMT_1_WRAP(T1, T2, x) + +#include "scalar_sat_unary.h"