Message ID | 20210929162129.GA9709@arm.com |
---|---|
State | Committed |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EEF33858406 for <patchwork@sourceware.org>; Wed, 29 Sep 2021 16:26:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EEF33858406 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632932807; bh=DogPRINw7uQduMs0hJgi+6CrpDkROZRPkHXJWR6mrEE=; h=Date:To:Subject:In-Reply-To:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gpWcJEEPDfKGZ1ah3Y8nGG2Rxk4+H2wRY6dolADAdV0NqTNwxRrdP5JcIvkN0SwTM KpxxPgntXO9YJrhrSxXk3yGg+3W/V1tSPQZNwDrBYCVfH/wG8NWNd/Vd2h2UZsxo8j jtJhEfu4B0vosRKyZnAIPelr8XqO7FRZkPwOGzwQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150084.outbound.protection.outlook.com [40.107.15.84]) by sourceware.org (Postfix) with ESMTPS id D48AA3857C51 for <gcc-patches@gcc.gnu.org>; Wed, 29 Sep 2021 16:21:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D48AA3857C51 Received: from DB6PR0202CA0026.eurprd02.prod.outlook.com (2603:10a6:4:a5::12) by AS8PR08MB5877.eurprd08.prod.outlook.com (2603:10a6:20b:291::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.13; Wed, 29 Sep 2021 16:21:45 +0000 Received: from DB5EUR03FT040.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:a5:cafe::17) by DB6PR0202CA0026.outlook.office365.com (2603:10a6:4:a5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Wed, 29 Sep 2021 16:21:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT040.mail.protection.outlook.com (10.152.20.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Wed, 29 Sep 2021 16:21:45 +0000 Received: ("Tessian outbound ab2dc3678fa9:v103"); Wed, 29 Sep 2021 16:21:45 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 00a541aad4122a5a X-CR-MTA-TID: 64aa7808 Received: from 7450dcf15dd1.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0BDDBC24-C6FF-474D-BE9C-920C218D2EBE.1; Wed, 29 Sep 2021 16:21:34 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 7450dcf15dd1.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 29 Sep 2021 16:21:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=auDWIxVYy/Esgj9p79qrtKLDqsOxlFjyMoDSRtzK5rrC7zXPCbgj1935f4jk/8q+BvYiLEegB3VmZSbrTQYHRFr7+QoprWoKfMUIprMUvz/1XO//d4NuYXBs6Ys8sHqlmQr+opQ7NMwmPTjpBbUO9qqJeE4sEjXIy70ltMbmamB86UW6QLFvbYBjmPN36n3PrFIoHeoMvlusRrBPM+zGaFErFF5/j5I3sgQcl0+NV24vxc+Qy3lxokeUGfY/fHD7yTI4QWJwemm5YYyIgWIlSRQ6UoztbkoYJ8WvRYu/glZks/loaDYGNxsYYNIPnfXdJ6ktYg/fI+wbUhsogocmfw== 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; bh=DogPRINw7uQduMs0hJgi+6CrpDkROZRPkHXJWR6mrEE=; b=Bcaz2mHoB/VGuZ1JSp5HGRQC9scEltg8DGfX/rp40cDjvND57AQSyNQO/7vIfZFCijxlnOlpyepdJgqb8ejvk/pxXS5uBrYzGHh76Mo/8s1cp3TJrNpyKS5apu2vu6DLLEyDjRXwSgvmv+utLsqgOz/xDmCug/5WHQmK40O5dZmZhcyHJMFNG6sGM7IVXwdbe6eJLVt5vWNz407s41/ALXqmsem48LOQNUsEbUAJu5GgGYPSVmE6Z2WmpJ2otU/u43V4nGm6/oPV+MjrVP26xM5UNinCN0t88uw1xsADdOh/sQ3nJ+WLrFYbmPhrsRKYp1v7CpPOUK8FbzXJvFe6HQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) by VI1PR08MB3437.eurprd08.prod.outlook.com (2603:10a6:803:7e::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.13; Wed, 29 Sep 2021 16:21:33 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::bd45:5ad5:f666:272a]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::bd45:5ad5:f666:272a%5]) with mapi id 15.20.4544.022; Wed, 29 Sep 2021 16:21:33 +0000 Date: Wed, 29 Sep 2021 17:21:31 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH 6/7]AArch64 Add neg + cmle into cmgt Message-ID: <20210929162129.GA9709@arm.com> Content-Type: multipart/mixed; boundary="3MwIy2ne0vdjdPXF" Content-Disposition: inline In-Reply-To: <patch-14899-tamar@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-ClientProxiedBy: LO4P265CA0021.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ae::22) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 Received: from arm.com (217.140.106.55) by LO4P265CA0021.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ae::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.13 via Frontend Transport; Wed, 29 Sep 2021 16:21:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5af209d3-5466-4819-426f-08d983653b04 X-MS-TrafficTypeDiagnostic: VI1PR08MB3437:|AS8PR08MB5877: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: <AS8PR08MB5877EEB45BD4776E8FA9E29FFFA99@AS8PR08MB5877.eurprd08.prod.outlook.com> x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:4714;OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 9uDWQwBhNgvC96WDs0upXzRfCFG3VprMqRvFQpbKe/Sg5ZIHgA2dJ2COQizTRjFdGf7aEjPtpAjhXiLuzhsugA85vsCXPT882DtQO7oYedfb197oJZX0Xdze5MbTjDlei8korNmoCRCm9+XTPmwW2SxhgnUJAW+e0M23VC1PXCpOdGfMfnCuyTezZrFVMkrRsOuux2hnHFG78lhjulq4cQa4OMEl4h5zn7fgBJsM+cfrbfZ+oJeAbi5TaIkzWUPB2vVldDwZoA4ZZ4/tyefk6DBkjKb0VTfrG+0JHdeHnGHET3lzlH34p8GtDA8sBkyCjz67BoMeC2NcbXNs+qz54HLvfeKZoFuKfbRHOgwZc4yodHM6woJcu/+LPV6DkOZ+UGsirGgr8KlAMvIMI6hc4ixBRWKv5yhEY2hw80hz2PC28ni/aVf8eBONar0+B5JQVd2zU8G7kBnUTB30EqVk/YiFXRbYLSusclBKPREPFar+uGTz18gK3gUHV87yCqxuiS3+ytkUFKmZac+8/g5AOCSqKrqKRuJPvWLs2NCIs8Wyzs8wV3nHtw7CqcnkfB0KagtSJzt3s18Y9Dd2tsc7TBkAgyyvjfN+OLj5milIUvxwoFkpMfuxMpsHlVk8OAmeNNUGg9f4CICiWzB/KkWX8q4nFU6rfcn0DB9lwo/5X6HUTrTyUBo7qjOx6IicXBczOGIJQ8Cs05qVLsPmT9VEnWiDOH/AEWweW7QHq//GTy7nxFmVAnfCbDGFXVdQahap8iq9AdvTwZ2MPEFQEjmupPxhZXQOB16F4BaBLPqoTXaDmmOVpHZjyhjpsfjXLSi6 X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB5325.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8936002)(8886007)(8676002)(36756003)(86362001)(2906002)(4743002)(66556008)(66476007)(66616009)(55016002)(33656002)(316002)(38350700002)(38100700002)(1076003)(26005)(235185007)(5660300002)(33964004)(508600001)(52116002)(66946007)(44832011)(44144004)(7696005)(6916009)(956004)(2616005)(4326008)(186003)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3437 Original-Authentication-Results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT040.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: e6ac3b31-3ce3-41b7-a0a9-08d983653392 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ru08qi/s45+rw/4p4MwZNU06GCnqgmOKh2ZHeg8YIeKEW7S+MHjCrrt9x8IgsHCOI6OBM4R/MyjGjhbBri3tfdXXP+rryIJaw23p4tvt5D+/76sMmRVilFPM1kv0DQJ1ClNxCnZinqpD04/57UeQZODULDyjmirKKMDO7x9AdDap6slKKLMr1tc8grsKFn1d9ivOeSFJ6F6MJRuqZ5uJS2urSh8xY+V/X2xduex+mmVjpeqw5+3O1zIhvjkq4VOFKvPNDLOuxsYQlr9Oe1kK5WrvollJEpK0/zJlxqujjQYxWqfXU+DUZLTrKOcDuUQ3rBRQK+kiWKa6UJpQ38cKoCDU4fDSeQq01STzyVyVVap6Phe/AHBfkcuT2Qx7yuG/eHvKULTXqqalFT85qnfFvO4UuUVEv87wNL+7vLk2bmGFzRbI1hALZ6q28bVK0K4WTZRWp2apHmgHsZlDrd4YPEuJRF1Y8YLsZxME1lblv7PpllouugatbkwvOempEzafSf1dODEQKgsDNxxHeIB256eQErdAV1gxLavvBnVSCMfS7hY51z18/8TSNUqodZG4jPdq1EeTRjytEj+U//nGsYDv82Fuq1JRSR87reRZUwlW+0kQ2kfMPazyyPHA53iIokkgiryoofCMaupMeVPqjAl1X/DMOv4y91hjwAH3ryb3WLfQ7L57/DGaH/7L0FuZaX/X2CyVf/7QoJeiBwUxWmNQY+gN6dJrCCZhRGWKsd0X1mHZQi5OyT4PJETIh2NKXIcaeQLknBcn1LVEp4PALD6ZhnYFuV3UHoVaWojNxQbEsFZ2oCRWujaawxO7IItS 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:(4636009)(46966006)(36840700001)(26005)(47076005)(8886007)(8676002)(86362001)(1076003)(508600001)(36860700001)(316002)(356005)(81166007)(44832011)(235185007)(33964004)(956004)(6916009)(2906002)(82310400003)(36756003)(70206006)(8936002)(44144004)(2616005)(4326008)(336012)(70586007)(5660300002)(7696005)(55016002)(4743002)(33656002)(186003)(66616009)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2021 16:21:45.4626 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5af209d3-5466-4819-426f-08d983653b04 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: DB5EUR03FT040.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5877 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Tamar Christina via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Tamar Christina <tamar.christina@arm.com> Cc: Richard.Earnshaw@arm.com, nd@arm.com, richard.sandiford@arm.com, Marcus.Shawcroft@arm.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
AArch64 Optimize truncation, shifts and bitmask comparisons
|
|
Commit Message
Tamar Christina
Sept. 29, 2021, 4:21 p.m. UTC
Hi All, This turns an inversion of the sign bit + arithmetic right shift into a comparison with 0. i.e. void fun1(int32_t *x, int n) { for (int i = 0; i < (n & -16); i++) x[i] = (-x[i]) >> 31; } now generates: .L3: ldr q0, [x0] cmgt v0.4s, v0.4s, #0 str q0, [x0], 16 cmp x0, x1 bne .L3 instead of: .L3: ldr q0, [x0] neg v0.4s, v0.4s sshr v0.4s, v0.4s, 31 str q0, [x0], 16 cmp x0, x1 bne .L3 Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: * config/aarch64/aarch64-simd.md (*aarch64_simd_neg_ashr<mode>): New. * config/aarch64/predicates.md (aarch64_simd_shift_imm_vec_signbit): New. gcc/testsuite/ChangeLog: * gcc.target/aarch64/signbit-1.c: New test. --- inline copy of patch -- diff --git a/gcc/config/aarch64/aarch64-simd.md b/gcc/config/aarch64/aarch64-simd.md index 0045b100c6af1c007293ee26506199868be90e9f..9d936428b438c95b56614c94081d7e2ebc47d89f 100644 --
Comments
> -----Original Message----- > From: Tamar Christina <Tamar.Christina@arm.com> > Sent: Wednesday, September 29, 2021 5:22 PM > To: gcc-patches@gcc.gnu.org > Cc: nd <nd@arm.com>; Richard Earnshaw <Richard.Earnshaw@arm.com>; > Marcus Shawcroft <Marcus.Shawcroft@arm.com>; Kyrylo Tkachov > <Kyrylo.Tkachov@arm.com>; Richard Sandiford > <Richard.Sandiford@arm.com> > Subject: [PATCH 6/7]AArch64 Add neg + cmle into cmgt > > Hi All, > > This turns an inversion of the sign bit + arithmetic right shift into a > comparison with 0. > > i.e. > > void fun1(int32_t *x, int n) > { > for (int i = 0; i < (n & -16); i++) > x[i] = (-x[i]) >> 31; > } > > now generates: > > .L3: > ldr q0, [x0] > cmgt v0.4s, v0.4s, #0 > str q0, [x0], 16 > cmp x0, x1 > bne .L3 > > instead of: > > .L3: > ldr q0, [x0] > neg v0.4s, v0.4s > sshr v0.4s, v0.4s, 31 > str q0, [x0], 16 > cmp x0, x1 > bne .L3 > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master? > > Thanks, > Tamar > > gcc/ChangeLog: > > * config/aarch64/aarch64-simd.md > (*aarch64_simd_neg_ashr<mode>): New. > * config/aarch64/predicates.md > (aarch64_simd_shift_imm_vec_signbit): New. > > gcc/testsuite/ChangeLog: > > * gcc.target/aarch64/signbit-1.c: New test. > > --- inline copy of patch -- > diff --git a/gcc/config/aarch64/aarch64-simd.md > b/gcc/config/aarch64/aarch64-simd.md > index > 0045b100c6af1c007293ee26506199868be90e9f..9d936428b438c95b56614c94 > 081d7e2ebc47d89f 100644 > --- a/gcc/config/aarch64/aarch64-simd.md > +++ b/gcc/config/aarch64/aarch64-simd.md > @@ -1137,6 +1137,18 @@ (define_insn "aarch64_simd_ashr<mode>" > [(set_attr "type" "neon_compare<q>,neon_shift_imm<q>")] > ) > > +;; Additional opt when we negate the sign bit and then shift right > +(define_insn "*aarch64_simd_neg_ashr<mode>" > + [(set (match_operand:VDQ_I 0 "register_operand" "=w") > + (ashiftrt:VDQ_I > + (neg:VDQ_I > + (match_operand:VDQ_I 1 "register_operand" "w")) > + (match_operand:VDQ_I 2 "aarch64_simd_shift_imm_vec_signbit" > "D1")))] > + "TARGET_SIMD" > + "cmgt\t%0.<Vtype>, %1.<Vtype>, #0" > + [(set_attr "type" "neon_compare_zero<q>")] > +) > + > (define_insn "*aarch64_simd_sra<mode>" > [(set (match_operand:VDQ_I 0 "register_operand" "=w") > (plus:VDQ_I > diff --git a/gcc/config/aarch64/predicates.md > b/gcc/config/aarch64/predicates.md > index > 7fd4f9e7d06d3082d6f3047290f0446789e1d0d2..12e7d35da154b10f0190274 > d0279cab313563455 100644 > --- a/gcc/config/aarch64/predicates.md > +++ b/gcc/config/aarch64/predicates.md > @@ -545,6 +545,12 @@ (define_predicate > "aarch64_simd_shift_imm_offset_di" > (and (match_code "const_int") > (match_test "IN_RANGE (INTVAL (op), 1, 64)"))) > > +(define_predicate "aarch64_simd_shift_imm_vec_signbit" > + (and (match_code "const_vector") > + (match_test "aarch64_const_vec_all_same_in_range_p (op, > + GET_MODE_UNIT_BITSIZE (mode) - 1, > + GET_MODE_UNIT_BITSIZE (mode) - 1)"))) > + > (define_predicate "aarch64_simd_shift_imm_vec_exact_top" > (and (match_code "const_vector") > (match_test "aarch64_const_vec_all_same_in_range_p (op, Ok but.... > diff --git a/gcc/testsuite/gcc.target/aarch64/signbit-1.c > b/gcc/testsuite/gcc.target/aarch64/signbit-1.c > new file mode 100644 > index > 0000000000000000000000000000000000000000..3ebfb0586f37de29cf58635 > b27fe48503714447e > --- /dev/null > +++ b/gcc/testsuite/gcc.target/aarch64/signbit-1.c > @@ -0,0 +1,18 @@ > +/* { dg-do assemble } */ > +/* { dg-options "-O3 --save-temps" } */ > + > +#include <stdint.h> > + > +void fun1(int32_t *x, int n) > +{ > + for (int i = 0; i < (n & -16); i++) > + x[i] = (-x[i]) >> 31; > +} > + > +void fun2(int32_t *x, int n) > +{ > + for (int i = 0; i < (n & -16); i++) > + x[i] = (-x[i]) >> 30; > +} > + > +/* { dg-final { scan-assembler-times {\tcmgt\t} 1 } } */ ... as discussed offline can we also add test coverage for the other modes used in the iterators in this patch series. The extra tests can be added as separate follow up patches. Also, I'd appreciate a comment in the test for why only one of the functions is expected to generate a cmgt here (or remove the one that's irrelevant here) Thanks, Kyrill > > > --
diff --git a/gcc/config/aarch64/aarch64-simd.md b/gcc/config/aarch64/aarch64-simd.md index 0045b100c6af1c007293ee26506199868be90e9f..9d936428b438c95b56614c94081d7e2ebc47d89f 100644 --- a/gcc/config/aarch64/aarch64-simd.md +++ b/gcc/config/aarch64/aarch64-simd.md @@ -1137,6 +1137,18 @@ (define_insn "aarch64_simd_ashr<mode>" [(set_attr "type" "neon_compare<q>,neon_shift_imm<q>")] ) +;; Additional opt when we negate the sign bit and then shift right +(define_insn "*aarch64_simd_neg_ashr<mode>" + [(set (match_operand:VDQ_I 0 "register_operand" "=w") + (ashiftrt:VDQ_I + (neg:VDQ_I + (match_operand:VDQ_I 1 "register_operand" "w")) + (match_operand:VDQ_I 2 "aarch64_simd_shift_imm_vec_signbit" "D1")))] + "TARGET_SIMD" + "cmgt\t%0.<Vtype>, %1.<Vtype>, #0" + [(set_attr "type" "neon_compare_zero<q>")] +) + (define_insn "*aarch64_simd_sra<mode>" [(set (match_operand:VDQ_I 0 "register_operand" "=w") (plus:VDQ_I diff --git a/gcc/config/aarch64/predicates.md b/gcc/config/aarch64/predicates.md index 7fd4f9e7d06d3082d6f3047290f0446789e1d0d2..12e7d35da154b10f0190274d0279cab313563455 100644 --- a/gcc/config/aarch64/predicates.md +++ b/gcc/config/aarch64/predicates.md @@ -545,6 +545,12 @@ (define_predicate "aarch64_simd_shift_imm_offset_di" (and (match_code "const_int") (match_test "IN_RANGE (INTVAL (op), 1, 64)"))) +(define_predicate "aarch64_simd_shift_imm_vec_signbit" + (and (match_code "const_vector") + (match_test "aarch64_const_vec_all_same_in_range_p (op, + GET_MODE_UNIT_BITSIZE (mode) - 1, + GET_MODE_UNIT_BITSIZE (mode) - 1)"))) + (define_predicate "aarch64_simd_shift_imm_vec_exact_top" (and (match_code "const_vector") (match_test "aarch64_const_vec_all_same_in_range_p (op, diff --git a/gcc/testsuite/gcc.target/aarch64/signbit-1.c b/gcc/testsuite/gcc.target/aarch64/signbit-1.c new file mode 100644 index 0000000000000000000000000000000000000000..3ebfb0586f37de29cf58635b27fe48503714447e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/signbit-1.c @@ -0,0 +1,18 @@ +/* { dg-do assemble } */ +/* { dg-options "-O3 --save-temps" } */ + +#include <stdint.h> + +void fun1(int32_t *x, int n) +{ + for (int i = 0; i < (n & -16); i++) + x[i] = (-x[i]) >> 31; +} + +void fun2(int32_t *x, int n) +{ + for (int i = 0; i < (n & -16); i++) + x[i] = (-x[i]) >> 30; +} + +/* { dg-final { scan-assembler-times {\tcmgt\t} 1 } } */