From patchwork Thu May 18 08:39:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 95707 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp333178vqo; Thu, 18 May 2023 01:40:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48nlSgdATT8kzyFUM0lAuSxZFiiFj85RVa0W9XgRv/1g44s1sUvBtmumsXDccq/4AFI3Rx X-Received: by 2002:a17:907:6090:b0:96a:4ea0:a1e7 with SMTP id ht16-20020a170907609000b0096a4ea0a1e7mr28866596ejc.50.1684399237092; Thu, 18 May 2023 01:40:37 -0700 (PDT) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g18-20020a1709067c5200b0096700e71066si914332ejp.1003.2023.05.18.01.40.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 01:40:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VwJbKiMo; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A24FA383906F for ; Thu, 18 May 2023 08:40:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A24FA383906F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684399235; bh=aicGFzSmoKFoeWx12bheKG7tcFRrDOsbB8or6wcV0gw=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=VwJbKiMoWt90zWSdko0EmlgNsc16s14oqIAy9p7y58C7OSi6xMVsoCOXmP1uEjJEX 0wKMYQHwLba6svygNhD/1n5FpDHBww/OGcAZXFE2R1O4jSKRPFvZL97HuAKWX81IRc 94Gbjgf2RZzdSUpeLOXvCWQLNGnrZSHeCFmvRVZ0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2055.outbound.protection.outlook.com [40.107.8.55]) by sourceware.org (Postfix) with ESMTPS id D144B3858401 for ; Thu, 18 May 2023 08:39:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D144B3858401 Received: from DU2PR04CA0315.eurprd04.prod.outlook.com (2603:10a6:10:2b5::20) by DB9PR08MB9491.eurprd08.prod.outlook.com (2603:10a6:10:45a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Thu, 18 May 2023 08:39:32 +0000 Received: from DBAEUR03FT006.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2b5:cafe::59) by DU2PR04CA0315.outlook.office365.com (2603:10a6:10:2b5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 08:39:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT006.mail.protection.outlook.com (100.127.142.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17 via Frontend Transport; Thu, 18 May 2023 08:39:32 +0000 Received: ("Tessian outbound e13c2446394c:v136"); Thu, 18 May 2023 08:39:32 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 924a311d227b5a83 X-CR-MTA-TID: 64aa7808 Received: from f868e3039312.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A65F4EE4-F0EE-46F3-9C4E-2374E3A5AF79.1; Thu, 18 May 2023 08:39:26 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f868e3039312.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 18 May 2023 08:39:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=adTvPANxj3G6SvkkoT4oWpPpjHX5FgREWTmbpKc7/6lVmNgmeL/QJPrwuqRt0Y/sI0ACk34iTOjgOvTisR5ZA7x3vrlPIlZ+nK15dWDYx9L3FdokmelkgB6TlOQ6aa5PurviFHNkCI9bBdQKdS4A+NG2Zz6PWJwmMk3PKIMhjl9NKtVivX8KGbEh3tmSEwS6gxdnb3eeJ7aulDPowmu66y9+9hwrO54bv0tKaOCotBOW5UjlYC+SKBqyOlq46xpnIpYXwFJD0CTW5FaXhOWLJQLOsKzKAAbwsvg6ROBSzbTf0vSmj3REdsajJGZUq8a6+LR9g1Au/+U3s+c/6dYhcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aicGFzSmoKFoeWx12bheKG7tcFRrDOsbB8or6wcV0gw=; b=HNlApAk9i4eLzSfil//5V2yhdZnqrhZMmFK7AVpwltqZyH8Kz52u3lOJ4bcQ2cqGi/TxWKMqIyV6NhPF/gT5VBkWYM+0brvp2PmOyw8zNcnLdj6qzI0GjpoDYhk+eIG6TTSK+RL3B1MHUGwEWtq2FhUNbIyu2gwAuwPHNaM7VUB4a5mjKzMJwbVr8cDMzny+Dj1GuFuEnUuegoAhj3zPXjw3KAJmiSS+mTBBmvlDj4BJM0oAtCM9ioHYRzLjiyXL7W4c1EIjfAcsrgSCmgSY5r2cvMfpPEClkQ/nI/efGVyKHvzsCbiCj80b5KpgXBsQxMwhTZx6sxtc+sk1ZGCtaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=armh.onmicrosoft.com smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from AS4PR10CA0028.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5d8::13) by GV1PR08MB7361.eurprd08.prod.outlook.com (2603:10a6:150:20::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19; Thu, 18 May 2023 08:39:22 +0000 Received: from AM7EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:5d8:cafe::33) by AS4PR10CA0028.outlook.office365.com (2603:10a6:20b:5d8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 08:39:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT044.mail.protection.outlook.com (100.127.140.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 08:39:22 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 18 May 2023 08:39:21 +0000 Received: from e119885.cambridge.arm.com (10.2.78.64) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Thu, 18 May 2023 08:39:21 +0000 To: CC: , , Subject: [PATCH 1/4] Missed opportunity to use [SU]ABD Date: Thu, 18 May 2023 09:39:09 +0100 Message-ID: <20230518083909.15739-1-Oluwatamilore.Adebayo@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230517122155.531-1-oluwatamilore.adebayo@arm.com> References: <20230517122155.531-1-oluwatamilore.adebayo@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT044:EE_|GV1PR08MB7361:EE_|DBAEUR03FT006:EE_|DB9PR08MB9491:EE_ X-MS-Office365-Filtering-Correlation-Id: 4704f352-a668-4f15-5f7b-08db577b6731 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 3rtsH3KthYOdTO73rUcIt5XfTnRRV2Xv41fVkL7oVlZKkBnXoPHRUrtot9inltzXh4h3Y5ecKCCktT3klvUOvpb5wAlLJTQSCdvUSxZLyaK0awAG0VQAp+PDl2dxdH0JSqPcs1grj76crVHqhkH9aKcjoqvtSQly/FMiupvxV8ubI5PnBHd8Ngq3rzkUBHthIctrQPeaVxkpfLxSixjhtdKSqLbBRsaRM6UfzWA8IrsjEpHTtHDZQ7LPPRPyrt9xtarANpcQghaT23liowC+QrYPW8wbjtWpJK/1hPEOnmCDXtvt5MRXBqJIg22A0/XbvIhAx5S4YBLchGQM00z6+s84wQfSh86mRmELUG71ivDOwvlAYQClRhCYPMez8aGUZ/w8HsrcEtaNDazKJ2foC1JNVHVd49Cyr9daeYjG7XWgm8dnD0IONJoZgaEqzFUvgfCGChZw4QV/PzLBxPc6+rN/YHgiNe1NBQbiY/JYnkmX4iwVKsftpwOVSVpN/Rpe+AlNP0/qXhf2fTFLJzC2iZwqBQJgsrTogXHeBrSWKs/23XGq/qqTBnbXH4umFuJUmiYw2kL/JpvAjAf7OdXMUtePmlTpfZFx2TDGJ3YuwAEWMtAMYqDI4MsQxzZePAKyF5J1reI5ENn+TgY1VYPVK5MWAKl9JaDqe0czB1PJ+QopSodKLmvk8PtWUSKrDD9vMn4aiauzAj0AwOXoy9ezjrK58gNc5HcY3NIwBcO1Heqn3CjbH89Gx0jN+dlB4l4I173o/ckijIaTGIgCbKVHCg== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(396003)(346002)(136003)(376002)(451199021)(46966006)(36840700001)(40470700004)(26005)(40460700003)(1076003)(6200100001)(36756003)(36860700001)(47076005)(83380400001)(336012)(426003)(40480700001)(2616005)(82310400005)(81166007)(86362001)(356005)(82740400003)(186003)(37006003)(54906003)(478600001)(30864003)(2906002)(8676002)(8936002)(316002)(6862004)(41300700001)(5660300002)(4326008)(70586007)(70206006)(2876002)(7696005)(6666004)(45080400002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB7361 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT006.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 17e976c5-4636-4020-c745-08db577b6122 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TUw0+dFcrTu5FtNFeOGdTNKVcBWpfw6C4vhA+YRfx1guiU5WPn2f1bYkPzd3tZS4Kxj4FZhYCh5nyzcFMGObtLOYPZzXB3PL54aNFewUT/x3iV+3bIjb34WEtjfyZUyxOecYzjz96EoEASUYC/mWfZSe2qxnqPP7FxIWQvoa1kMMAjhYSHOlJ4JsvQu+1bseHELkg8wds2A1ARptPYKv+cL1r7to/lgX1wJijEgK9izFDHMIJi5OMZn1SVdwktXO2zVFjAt+XacMVUCP6UlNxtbiciJGsI7Zl1LARc5STQz/8YZhZiZCCHysp1fOzwRwRnhl4bmH1zAMYH0iAqSkz5yooz01pWiNPSi3g6PS58sDmgZqn/WwKGSziLVlfCUn1eLmSYSKqPcruA8xQuA7wDutyXQIj6q942oDuZiR79elIoGt1XwoShs9aV/uCTrR8dpC2OmD21q0DEcK3Q8mF4IMbprxgBIbpj82cytS5pHXJAbZWcc6TB2ekV2rPJtWpWfutapjLGLPPe0aTbQ8a6RLNOXji48o3/Pw9KAJ9cLUYUUoeDn5Kl3AEOtMlCe/iRF2SVrFEZoS9ay0nm4nCtUkSZZzCOG9cFfLRL4TAg87H9nSe82gFuAkYRvRb8ghbPvePAyl/AQ6Ivf/R/WS6yAZSeD0ycPzmk0OxyTe4VlXxQb/zSlqikvETg37xuoamoVNH00SJOH+NfxU2X9FDamS+64adcZwwUgJxrtzRKFUXbAbh08lV2ojwULyxEY/ X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(376002)(396003)(136003)(346002)(451199021)(46966006)(40470700004)(36840700001)(86362001)(70586007)(70206006)(45080400002)(7696005)(6666004)(37006003)(4326008)(316002)(478600001)(54906003)(41300700001)(5660300002)(40460700003)(186003)(26005)(1076003)(8936002)(8676002)(6862004)(40480700001)(83380400001)(2876002)(30864003)(2906002)(336012)(36860700001)(36756003)(2616005)(47076005)(6200100001)(426003)(82740400003)(81166007)(82310400005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 08:39:32.6940 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4704f352-a668-4f15-5f7b-08db577b6731 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT006.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB9491 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Oluwatamilore Adebayo via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Oluwatamilore.Adebayo@arm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766220614048342165?= X-GMAIL-MSGID: =?utf-8?q?1766220614048342165?= From: oluade01 This adds a recognition pattern for the non-widening absolute difference (ABD). gcc/ChangeLog: * doc/md.texi (sabd, uabd): Document them. * internal-fn.def (ABD): Use new optab. * optabs.def (sabd_optab, uabd_optab): New optabs, * tree-vect-patterns.cc (vect_recog_absolute_difference): Recognize the following idiom abs (a - b). (vect_recog_sad_pattern): Refactor to use vect_recog_absolute_difference. (vect_recog_abd_pattern): Use patterns found by vect_recog_absolute_difference to build a new ABD internal call. --- gcc/doc/md.texi | 10 ++ gcc/internal-fn.def | 3 + gcc/optabs.def | 2 + gcc/tree-vect-patterns.cc | 255 +++++++++++++++++++++++++++++++++----- 4 files changed, 239 insertions(+), 31 deletions(-) diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi index 07bf8bdebffb2e523f25a41f2b57e43c0276b745..3e65584d7efcd301f2c96a40edd82d30b84462b8 100644 --- a/gcc/doc/md.texi +++ b/gcc/doc/md.texi @@ -5778,6 +5778,16 @@ Other shift and rotate instructions, analogous to the Vector shift and rotate instructions that take vectors as operand 2 instead of a scalar type. +@cindex @code{uabd@var{m}} instruction pattern +@cindex @code{sabd@var{m}} instruction pattern +@item @samp{uabd@var{m}}, @samp{sabd@var{m}} +Signed and unsigned absolute difference instructions. These +instructions find the difference between operands 1 and 2 +then return the absolute value. A C code equivalent would be: +@smallexample +op0 = op0 > op1 ? op0 - op1 : op1 - op0; +@end smallexample + @cindex @code{avg@var{m}3_floor} instruction pattern @cindex @code{uavg@var{m}3_floor} instruction pattern @item @samp{avg@var{m}3_floor} diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index 7fe742c2ae713e7152ab05cfdfba86e4e0aa3456..0f1724ecf37a31c231572edf90b5577e2d82f468 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -167,6 +167,9 @@ DEF_INTERNAL_OPTAB_FN (FMS, ECF_CONST, fms, ternary) DEF_INTERNAL_OPTAB_FN (FNMA, ECF_CONST, fnma, ternary) DEF_INTERNAL_OPTAB_FN (FNMS, ECF_CONST, fnms, ternary) +DEF_INTERNAL_SIGNED_OPTAB_FN (ABD, ECF_CONST | ECF_NOTHROW, first, + sabd, uabd, binary) + DEF_INTERNAL_SIGNED_OPTAB_FN (AVG_FLOOR, ECF_CONST | ECF_NOTHROW, first, savg_floor, uavg_floor, binary) DEF_INTERNAL_SIGNED_OPTAB_FN (AVG_CEIL, ECF_CONST | ECF_NOTHROW, first, diff --git a/gcc/optabs.def b/gcc/optabs.def index 695f5911b300c9ca5737de9be809fa01aabe5e01..29bc92281a2175f898634cbe6af63c18021e5268 100644 --- a/gcc/optabs.def +++ b/gcc/optabs.def @@ -359,6 +359,8 @@ OPTAB_D (mask_fold_left_plus_optab, "mask_fold_left_plus_$a") OPTAB_D (extract_last_optab, "extract_last_$a") OPTAB_D (fold_extract_last_optab, "fold_extract_last_$a") +OPTAB_D (uabd_optab, "uabd$a3") +OPTAB_D (sabd_optab, "sabd$a3") OPTAB_D (savg_floor_optab, "avg$a3_floor") OPTAB_D (uavg_floor_optab, "uavg$a3_floor") OPTAB_D (savg_ceil_optab, "avg$a3_ceil") diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index a49b09539776c0056e77f99b10365d0a8747fbc5..50f1822f220c023027f4b0f777965f3757842fa2 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -770,6 +770,93 @@ vect_split_statement (vec_info *vinfo, stmt_vec_info stmt2_info, tree new_rhs, } } +/* Look for the following pattern + X = x[i] + Y = y[i] + DIFF = X - Y + DAD = ABS_EXPR + + ABS_STMT should point to a statement of code ABS_EXPR or ABSU_EXPR. + If REJECT_UNSIGNED is true it aborts if the type of ABS_STMT is unsigned. + HALF_TYPE and UNPROM will be set should the statement be found to + be a widened operation. + DIFF_OPRNDS will be set to the two inputs of the MINUS_EXPR preceding + ABS_STMT, otherwise it will be set the operations found by + vect_widened_op_tree. + */ +static bool +vect_recog_absolute_difference (vec_info *vinfo, gassign *abs_stmt, + tree *half_type, bool reject_unsigned, + vect_unpromoted_value unprom[2], + tree diff_oprnds[2]) +{ + if (!abs_stmt) + return false; + + /* FORNOW. Can continue analyzing the def-use chain when this stmt in a phi + inside the loop (in case we are analyzing an outer-loop). */ + enum tree_code code = gimple_assign_rhs_code (abs_stmt); + if (code != ABS_EXPR && code != ABSU_EXPR) + return false; + + tree abs_oprnd = gimple_assign_rhs1 (abs_stmt); + tree abs_type = TREE_TYPE (abs_oprnd); + if (!abs_oprnd) + return false; + if (reject_unsigned && TYPE_UNSIGNED (abs_type)) + return false; + if (!ANY_INTEGRAL_TYPE_P (abs_type) || TYPE_OVERFLOW_WRAPS (abs_type)) + return false; + + /* Peel off conversions from the ABS input. This can involve sign + changes (e.g. from an unsigned subtraction to a signed ABS input) + or signed promotion, but it can't include unsigned promotion. + (Note that ABS of an unsigned promotion should have been folded + away before now anyway.) */ + vect_unpromoted_value unprom_diff; + abs_oprnd = vect_look_through_possible_promotion (vinfo, abs_oprnd, + &unprom_diff); + if (!abs_oprnd) + return false; + if (TYPE_PRECISION (unprom_diff.type) != TYPE_PRECISION (abs_type) + && TYPE_UNSIGNED (unprom_diff.type) + && TYPE_UNSIGNED (abs_type)) + return false; + + /* We then detect if the operand of abs_expr is defined by a minus_expr. */ + stmt_vec_info diff_stmt_vinfo = vect_get_internal_def (vinfo, abs_oprnd); + if (!diff_stmt_vinfo) + return false; + + /* FORNOW. Can continue analyzing the def-use chain when this stmt in a phi + inside the loop (in case we are analyzing an outer-loop). */ + if (vect_widened_op_tree (vinfo, diff_stmt_vinfo, MINUS_EXPR, + WIDEN_MINUS_EXPR, + false, 2, unprom, half_type)) + { + if (diff_oprnds) + { + diff_oprnds[0] = unprom[0].op; + diff_oprnds[1] = unprom[1].op; + } + return true; + } + + // Failed to find a widen operation so we check for a regular MINUS_EXPR + gassign *diff = dyn_cast (STMT_VINFO_STMT (diff_stmt_vinfo)); + if (diff_oprnds && diff && gimple_assign_rhs_code (diff) == MINUS_EXPR) + { + diff_oprnds[0] = gimple_assign_rhs1 (diff); + diff_oprnds[1] = gimple_assign_rhs2 (diff); + } + else + return false; + + *half_type = NULL_TREE; + + return true; +} + /* Convert UNPROM to TYPE and return the result, adding new statements to STMT_INFO's pattern definition statements if no better way is available. VECTYPE is the vector form of TYPE. @@ -1308,40 +1395,13 @@ vect_recog_sad_pattern (vec_info *vinfo, /* FORNOW. Can continue analyzing the def-use chain when this stmt in a phi inside the loop (in case we are analyzing an outer-loop). */ gassign *abs_stmt = dyn_cast (abs_stmt_vinfo->stmt); - if (!abs_stmt - || (gimple_assign_rhs_code (abs_stmt) != ABS_EXPR - && gimple_assign_rhs_code (abs_stmt) != ABSU_EXPR)) - return NULL; - tree abs_oprnd = gimple_assign_rhs1 (abs_stmt); - tree abs_type = TREE_TYPE (abs_oprnd); - if (TYPE_UNSIGNED (abs_type)) - return NULL; - - /* Peel off conversions from the ABS input. This can involve sign - changes (e.g. from an unsigned subtraction to a signed ABS input) - or signed promotion, but it can't include unsigned promotion. - (Note that ABS of an unsigned promotion should have been folded - away before now anyway.) */ - vect_unpromoted_value unprom_diff; - abs_oprnd = vect_look_through_possible_promotion (vinfo, abs_oprnd, - &unprom_diff); - if (!abs_oprnd) - return NULL; - if (TYPE_PRECISION (unprom_diff.type) != TYPE_PRECISION (abs_type) - && TYPE_UNSIGNED (unprom_diff.type)) - return NULL; - - /* We then detect if the operand of abs_expr is defined by a minus_expr. */ - stmt_vec_info diff_stmt_vinfo = vect_get_internal_def (vinfo, abs_oprnd); - if (!diff_stmt_vinfo) + vect_unpromoted_value unprom[2]; + if (!vect_recog_absolute_difference (vinfo, abs_stmt, &half_type, + true, unprom, NULL)) return NULL; - /* FORNOW. Can continue analyzing the def-use chain when this stmt in a phi - inside the loop (in case we are analyzing an outer-loop). */ - vect_unpromoted_value unprom[2]; - if (!vect_widened_op_tree (vinfo, diff_stmt_vinfo, MINUS_EXPR, WIDEN_MINUS_EXPR, - false, 2, unprom, &half_type)) + if (!half_type) return NULL; vect_pattern_detected ("vect_recog_sad_pattern", last_stmt); @@ -1363,6 +1423,138 @@ vect_recog_sad_pattern (vec_info *vinfo, return pattern_stmt; } +/* Function vect_recog_abd_pattern + + Try to find the following ABsolute Difference (ABD) pattern: + + VTYPE x, y, out; + type diff; + loop i in range: + S1 diff = x[i] - y[i] + S2 out[i] = ABS_EXPR ; + + where 'type' is a integer and 'VTYPE' is a vector of integers + the same size as 'type' + + Input: + + * STMT_VINFO: The stmt from which the pattern search begins + + Output: + + * TYPE_out: The type of the output of this pattern + + * Return value: A new stmt that will be used to replace the sequence of + stmts that constitute the pattern; either SABD or UABD: + SABD_EXPR + UABD_EXPR + + UABD expressions are used when the input types are + narrower than the output types or the output type is narrower + than 32 bits + */ + +static gimple * +vect_recog_abd_pattern (vec_info *vinfo, + stmt_vec_info stmt_vinfo, tree *type_out) +{ + /* Look for the following patterns + X = x[i] + Y = y[i] + DIFF = X - Y + DAD = ABS_EXPR + out[i] = DAD + + In which + - X, Y, DIFF, DAD all have the same type + - x, y, out are all vectors of the same type + */ + gassign *last_stmt = dyn_cast (STMT_VINFO_STMT (stmt_vinfo)); + if (!last_stmt) + return NULL; + + tree out_type = TREE_TYPE (gimple_assign_lhs (last_stmt)); + + gassign *abs_stmt = last_stmt; + if (gimple_assign_cast_p (last_stmt)) + { + tree last_rhs = gimple_assign_rhs1 (last_stmt); + if (!SSA_VAR_P (last_rhs)) + return NULL; + + abs_stmt = dyn_cast (SSA_NAME_DEF_STMT (last_rhs)); + if (!abs_stmt) + return NULL; + } + + vect_unpromoted_value unprom[2]; + tree diff_oprnds[2]; + tree half_type; + if (!vect_recog_absolute_difference (vinfo, abs_stmt, &half_type, + false, unprom, diff_oprnds)) + return NULL; + +#define SAME_TYPE(A, B) (TYPE_PRECISION (A) == TYPE_PRECISION (B)) + + tree abd_oprnds[2]; + if (half_type) + { + if (!SAME_TYPE (unprom[0].type, unprom[1].type)) + return NULL; + + tree diff_type = TREE_TYPE (diff_oprnds[0]); + if (TYPE_PRECISION (out_type) != TYPE_PRECISION (diff_type)) + { + tree vectype = get_vectype_for_scalar_type (vinfo, half_type); + vect_convert_inputs (vinfo, stmt_vinfo, 2, abd_oprnds, + half_type, unprom, vectype); + } + else + { + abd_oprnds[0] = diff_oprnds[0]; + abd_oprnds[1] = diff_oprnds[1]; + } + } + else + { + if (unprom[0].op && unprom[1].op + && (!SAME_TYPE (unprom[0].type, unprom[1].type) + || !SAME_TYPE (unprom[0].type, out_type))) + return NULL; + + unprom[0].op = diff_oprnds[0]; + unprom[1].op = diff_oprnds[1]; + tree signed_out = signed_type_for (out_type); + tree signed_out_vectype = get_vectype_for_scalar_type (vinfo, signed_out); + vect_convert_inputs (vinfo, stmt_vinfo, 2, abd_oprnds, + signed_out, unprom, signed_out_vectype); + + if (!SAME_TYPE (TREE_TYPE (diff_oprnds[0]), TREE_TYPE (abd_oprnds[0]))) + return NULL; + } + + if (!SAME_TYPE (TREE_TYPE (abd_oprnds[0]), TREE_TYPE (abd_oprnds[1])) + || !SAME_TYPE (TREE_TYPE (abd_oprnds[0]), out_type)) + return NULL; + + vect_pattern_detected ("vect_recog_abd_pattern", last_stmt); + + tree vectype = get_vectype_for_scalar_type (vinfo, out_type); + if (!vectype + || !direct_internal_fn_supported_p (IFN_ABD, vectype, + OPTIMIZE_FOR_SPEED)) + return NULL; + + *type_out = STMT_VINFO_VECTYPE (stmt_vinfo); + + tree var = vect_recog_temp_ssa_var (out_type, NULL); + gcall *abd_stmt = gimple_build_call_internal (IFN_ABD, 2, + abd_oprnds[0], abd_oprnds[1]); + gimple_call_set_lhs (abd_stmt, var); + gimple_set_location (abd_stmt, gimple_location (last_stmt)); + return abd_stmt; +} + /* Recognize an operation that performs ORIG_CODE on widened inputs, so that it can be treated as though it had the form: @@ -6439,6 +6631,7 @@ struct vect_recog_func static vect_recog_func vect_vect_recog_func_ptrs[] = { { vect_recog_bitfield_ref_pattern, "bitfield_ref" }, { vect_recog_bit_insert_pattern, "bit_insert" }, + { vect_recog_abd_pattern, "abd" }, { vect_recog_over_widening_pattern, "over_widening" }, /* Must come after over_widening, which narrows the shift as much as possible beforehand. */