From patchwork Mon Jun 17 01:41:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1948346 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=hKgIm5lT; 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 4W2Xfq1Qb2z20Wb for ; Mon, 17 Jun 2024 11:41:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FE693858433 for ; Mon, 17 Jun 2024 01:41:33 +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.15]) by sourceware.org (Postfix) with ESMTPS id 6D1D93858D29 for ; Mon, 17 Jun 2024 01:41:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D1D93858D29 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 6D1D93858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718588475; cv=none; b=A0AVPiSlUXr+afZHwl4EZ444pySNEqdb3G8iroe0u5JaO1aed/k797fac8lw/Q7cfzs07MuN1pNbMPJNcLYnCPigrmLX9S0pfv+xGdhalXmro5nVTLYtS8DdEBiMC5cX9Qo5aIEoMOP0Kc7ofwPgZLp38qT2YlPz75Xl7ZEMijE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718588475; c=relaxed/simple; bh=O8qpMdLpYZdMDaXkwtn+c0F1rpge2T1kCabt+63JRdg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=oD6c8LLtAhb6s8uOQ5oqTRCvwm6vJ5HxvnwkFL5HmEQWb8UC+9E3YJSVoIArrNw6vB5RMnuvfDQNQiacLY3n/9foQDJs2ELRFLPwI8U5VPoNBB62XwxidxAe0wo2o+N5pQrSKF4xPkN67LkwGJIFTTbwjsacfkVYa/DZq6ERSAA= 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=1718588474; x=1750124474; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=O8qpMdLpYZdMDaXkwtn+c0F1rpge2T1kCabt+63JRdg=; b=hKgIm5lTTQcoomUvsQAHbhebiVwvS5LFD3/Ty/zZOvZQbycdOv4Kxwvq CXdrdLgNPivTCwB+j03lKIowtIjk4XjqPEsERBRLPqlh/o38FpHbp1TAt pUYdp0bCJAYk33AvikEHEQQlOSBOlPj+IhnUuS452YKaC7vXyyk5e11zm /XxxlgWdh7pABJ8WgjnzxBG6edFhuFE+4wPmpUBf+74+mInDr5khHdyNk WyRTEXSSkrUDSOYvpiou8JxFjbPlXcBABMPt70JA3WlfndqVKeNwUyk3U kHXm0DtqlLZHRavF2syB0W6j7bQ05IOvzNs1ivHEVjl9GDmMFTckTzwmb A==; X-CSE-ConnectionGUID: Om7VZvmNQ2WwnvnMuFrQwA== X-CSE-MsgGUID: 4aDtN5qYS5WYSlVb7qlhtQ== X-IronPort-AV: E=McAfee;i="6700,10204,11105"; a="15560563" X-IronPort-AV: E=Sophos;i="6.08,243,1712646000"; d="scan'208";a="15560563" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2024 18:41:12 -0700 X-CSE-ConnectionGUID: 7GNiJ4d3SC2BzXb3GZNghg== X-CSE-MsgGUID: 2N7gK44BQEWZAxeuDkwr3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,243,1712646000"; d="scan'208";a="40931011" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by fmviesa006.fm.intel.com with ESMTP; 16 Jun 2024 18:41:10 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail02.sh.intel.com (Postfix) with ESMTP id AAF1310083C3; Mon, 17 Jun 2024 09:41:09 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@gmail.com, richard.guenther@gmail.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Pan Li Subject: [PATCH v1] Match: Support forms 7 and 8 for the unsigned .SAT_ADD Date: Mon, 17 Jun 2024 09:41:08 +0800 Message-Id: <20240617014108.2831124-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 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, 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.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 investigate the vectorization of .SAT_ADD, we notice there are additional 2 forms, aka form 7 and 8 for .SAT_ADD. Form 7: #define DEF_SAT_U_ADD_FMT_7(T) \ T __attribute__((noinline)) \ sat_u_add_##T##_fmt_7 (T x, T y) \ { \ return x > (T)(x + y) ? -1 : (x + y); \ } Form 8: #define DEF_SAT_U_ADD_FMT_8(T) \ T __attribute__((noinline)) \ sat_u_add_##T##_fmt_8 (T x, T y) \ { \ return x <= (T)(x + y) ? (x + y) : -1; \ } Thus, add above 2 forms to the match gimple_unsigned_integer_sat_add, and then the vectorizer can try to recog the pattern like form 7 and form 8. The below test suites are passed for this patch: 1. The rv64gcv fully regression test with newlib. 2. The rv64gcv build with glibc. 3. The x86 bootstrap test. 4. The x86 fully regression test. gcc/ChangeLog: * match.pd: Add form 7 and 8 for the unsigned .SAT_ADD match. Signed-off-by: Pan Li --- gcc/match.pd | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index 99968d316ed..aae6d30a5e4 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3144,6 +3144,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cond^ (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1)) integer_zerop) integer_minus_onep (usadd_left_part_2 @0 @1))) +/* Unsigned saturation add, case 7 (branch with le): + SAT_ADD = x <= (X + Y) ? (X + Y) : -1. */ +(match (unsigned_integer_sat_add @0 @1) + (cond^ (le @0 (usadd_left_part_1@2 @0 @1)) @2 integer_minus_onep)) + +/* Unsigned saturation add, case 8 (branch with gt): + SAT_ADD = x > (X + Y) ? -1 : (X + Y). */ +(match (unsigned_integer_sat_add @0 @1) + (cond^ (gt @0 (usadd_left_part_1@2 @0 @1)) integer_minus_onep @2)) + /* Unsigned saturation sub, case 1 (branch with gt): SAT_U_SUB = X > Y ? X - Y : 0 */ (match (unsigned_integer_sat_sub @0 @1)