From patchwork Sun Jul 28 03:25:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1965700 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=Rqaiw9zT; 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 4WWn2m24MGz1ybX for ; Sun, 28 Jul 2024 13:26:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F18C3858416 for ; Sun, 28 Jul 2024 03:26:18 +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.18]) by sourceware.org (Postfix) with ESMTPS id D8E763858D28 for ; Sun, 28 Jul 2024 03:25:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8E763858D28 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 D8E763858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722137159; cv=none; b=KwLCXD4RKge1R6zlyC91vHZWsgmRn9SZ7Q6AKqNpFfmFLortIFd0SlpYQ+c3LXcR2P86t4ZnM1WHwds1XRV8usF6gh9oY6KSZY0I5yqxR2NLPhhAKw/vNWAi9ZuXX6RkLdCpp4hEZ50fQHRI9R+GQLI3xV53dr1gWuEQhXCPZxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722137159; c=relaxed/simple; bh=pRSo6xaE8IIdyYW5G1r5yBDNx9YoLAU3U8wki2+7K1s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=j+mSzsdTDoKWytX2EMTXd6mGVZpx0RjnJQnf0ypOu97h1fgwoE4OGwQMoeXn/ZTvqsrCoEqL1rz4h3q680WnkvlJ0f34vOWZ/dw4Oi69RbZfAj6MVr5EhSZ5FgNmwLtWEiG8fAXBGmF59BUO8EzrKkiJGU6OfwwlJRyMcl0mVjM= 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=1722137158; x=1753673158; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=pRSo6xaE8IIdyYW5G1r5yBDNx9YoLAU3U8wki2+7K1s=; b=Rqaiw9zTDKm6kaRMFMyntYvIk+N0KpfdY0q2O473FT6rY/euklBthUSS 6EkOiwp5DPncToa+KyC6GpPC1zpaBYtT6edqU8fFoobiAaqCOxUCYpHJ1 wIVg0J4Bxiv/cui0n5RPrOLK238BZgBMCcjTnL2nyBod0LEpB4wtOmf0V FRQndtBBRnu9mKC0Dzj7W2OalMmsYJf/+dxRBpQ5c0+ameSw5AY/FsVu7 wM0c60Q38lRMK6sCxyRVRNqRufOFwAe6rXnu+JrbfArweBiwl26XyXMaS IdfyS+XKiNOYA0nj6pFI+L/BuIUokkxUcj7dVzY85/840L8sTUYegq4EQ Q==; X-CSE-ConnectionGUID: x89cHzzpT+ukTYIghr+SPg== X-CSE-MsgGUID: nJ0OhXyxT7mQFjiV4jJMBg== X-IronPort-AV: E=McAfee;i="6700,10204,11146"; a="19500445" X-IronPort-AV: E=Sophos;i="6.09,243,1716274800"; d="scan'208";a="19500445" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2024 20:25:52 -0700 X-CSE-ConnectionGUID: q7itKiBYTeuym+6L4yi3cw== X-CSE-MsgGUID: jlc4ZpWvRP6tPsj6AZHnuA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,243,1716274800"; d="scan'208";a="54220724" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by orviesa007.jf.intel.com with ESMTP; 27 Jul 2024 20:25:50 -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 EEE0D10071F8; Sun, 28 Jul 2024 11:25:48 +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, tamar.christina@arm.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Pan Li Subject: [PATCH v1] Widening-Mul: Try .SAT_SUB for PLUS_EXPR when one op is IMM Date: Sun, 28 Jul 2024 11:25:47 +0800 Message-Id: <20240728032547.3426120-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 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 After add the matching for .SAT_SUB when one op is IMM, there will be a new root PLUS_EXPR for the .SAT_SUB pattern. For example, Form 3: #define DEF_SAT_U_SUB_IMM_FMT_3(T, IMM) \ T __attribute__((noinline)) \ sat_u_sub_imm##IMM##_##T##_fmt_3 (T x) \ { \ return x >= IMM ? x - IMM : 0; \ } DEF_SAT_U_SUB_IMM_FMT_3(uint64_t, 11) And then we will have gimple before widening-mul as below. Thus, try the .SAT_SUB for the PLUS_EXPR. 4 │ __attribute__((noinline)) 5 │ uint64_t sat_u_sub_imm11_uint64_t_fmt_3 (uint64_t x) 6 │ { 7 │ long unsigned int _1; 8 │ uint64_t _3; 9 │ 10 │ [local count: 1073741824]: 11 │ _1 = MAX_EXPR ; 12 │ _3 = _1 + 18446744073709551605; 13 │ return _3; 14 │ 15 │ } The below test suites are passed for this patch. 1. The rv64gcv fully regression tests. 2. The x86 bootstrap tests. 3. The x86 fully regression tests. gcc/ChangeLog: * tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children): Try .SAT_SUB for PLUS_EXPR case. Signed-off-by: Pan Li --- gcc/tree-ssa-math-opts.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc index ac86be8eb94..8d96a4c964b 100644 --- a/gcc/tree-ssa-math-opts.cc +++ b/gcc/tree-ssa-math-opts.cc @@ -6129,6 +6129,7 @@ math_opts_dom_walker::after_dom_children (basic_block bb) case PLUS_EXPR: match_unsigned_saturation_add (&gsi, as_a (stmt)); + match_unsigned_saturation_sub (&gsi, as_a (stmt)); /* fall-through */ case MINUS_EXPR: if (!convert_plusminus_to_widen (&gsi, stmt, code))