From patchwork Thu Jun 9 07:52:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 54975 Return-Path: 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 201B5384B128 for ; Thu, 9 Jun 2022 07:53:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 201B5384B128 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654761208; bh=GbK2pFA6ica4oqjP4an6577VosBOvXHPbwnA0KrslEU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=W4urbpFRNPkKPXXHEss1OCbL0dP95adGTskwehVlwoW7+7Rx1y12ZXCH8FeDfyjRb FkQF0HxTXGIiEzUgJ8FAL+bcI19/L0/VIKH0KlSbIm0/kqCsHfIQKNkhw0mIs3HsZu GJ6HYOvygdaaTINeavCMQx2To3+WFFQK9LV5GKms= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2063.outbound.protection.outlook.com [40.107.21.63]) by sourceware.org (Postfix) with ESMTPS id ACB5338582AA for ; Thu, 9 Jun 2022 07:52:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ACB5338582AA ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=CfYLFdaneidwiFQqmVdHO89Aq/gZmCrULyxUIw9cLukQ2umEStug9jSH66sv7tQy/BkrlvmnERbWklPvLfAnRaxJLIjwsfzkICETERqXRWp4lGn+bFMLrH8Xp5gJDgAqWFu29Z18JxiPv14OBRbA3DZujoBa2yh8ZJ6NyI9GzkPMrShTm7+sHKaepKX48zfwOrjzaHsfR2VTK5QWWAtMBfA7Um+xDWTTk0E9Ma/pm+3TJYrWjnWuUPRgYk6AarJneP9raaDppr8JWGXkAiLLA2I8kDegTIMrJ6wJFKC8VY4504+h4txard7dlVU1yG90qsQf30mQ2bfTLfspkUK3wA== ARC-Message-Signature: i=2; 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=GbK2pFA6ica4oqjP4an6577VosBOvXHPbwnA0KrslEU=; b=VqRo+ezc8rF2JiPxnZgir15MVLJzSXsKlU+BhkOjPxYh4hDs8nM8ybCSDoLDMAtbPm26ylSohPk29hva94d63eCuDtBTkpud2KqhuP/kKi7X5Z4vlGkvbnaG00LbrNbZjieY/i+/ynEikRVajT5rH2mTtaEgxuIhlwKH/3/LcLf7r0xpZtUQfyP3Dyeyp4eJVWkhs3RAdvWj3w3tZXr9B7/WsUP3k+xfor73JECKIe9e6SZPs9KbMznJAxZknojZZPh49o+wk96ToXtj8ugfTkPO9sbzSSkIwJaEW3w7vK/0RCEDRKmTfDm6qL9rA3mlfseK67twgGAZqTU/q2yjYQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AS8P251CA0017.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:2f2::30) by AS8PR08MB8040.eurprd08.prod.outlook.com (2603:10a6:20b:54a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.19; Thu, 9 Jun 2022 07:52:52 +0000 Received: from AM5EUR03FT026.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2f2:cafe::24) by AS8P251CA0017.outlook.office365.com (2603:10a6:20b:2f2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.13 via Frontend Transport; Thu, 9 Jun 2022 07:52:52 +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 AM5EUR03FT026.mail.protection.outlook.com (10.152.16.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12 via Frontend Transport; Thu, 9 Jun 2022 07:52:51 +0000 Received: ("Tessian outbound 01afcf8ccfad:v120"); Thu, 09 Jun 2022 07:52:51 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 9e6622388a6ebb3c X-CR-MTA-TID: 64aa7808 Received: from 438f6683859d.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 54DC8FF9-2113-47A0-8027-DC04C5601F16.1; Thu, 09 Jun 2022 07:52:44 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 438f6683859d.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 09 Jun 2022 07:52:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TXs2+r/zSmYSs3TfuDH2Nlk2NInevEWU+FPEDCIIBHCkjh8miIV/Q/dTyRTT6rmr7yClRzBDU6b4/0neCHg/14kTmVrEaOIuno8SqzyY4Odb202ba3eS8faN73eTeaMbYX0iVF4jYgmLOh40zIEQ3b17RRCCT4m4DpCa8dn3UaJ7aIHBi3CGR/d/f8IT1ciQsBNyqQkfhLMBsJNkX7bdsMhTtxabS/X4aO/rwbPjyMSCelKYZi3ogl8ws3Lh1GYHi7VepCg+3sGd+UDNhl8LlNISxyw6p75KbZz7xp1wK41LM/jX6QtCXhX4bQCvtTbKZuosE4refatox2oEZ05CyQ== 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=GbK2pFA6ica4oqjP4an6577VosBOvXHPbwnA0KrslEU=; b=eA6hc4UEuXmkdyKY/Lcxo/rfsb9+KgGTUXufsFQ896b016TIIugLAHAIMIAQMkla//Z83xtS13xni6LlEUQgIWUNaT7EKXjbS/+fLB3QR/DBiWzvm3o2w83zC8ivyUXkOszovBxCeQMugowOplN8EmpSOd3XHA3oZMl2GSAEftur5gCFJDmWbrw3efmWy1opEKskjG9iREVbfjWxjoPnV3PzfHRFJk3MTRTMbZQJ7uRghesjFd54UcGVBaoQSgwdcBT2YewgHBTgyk7uv0J6Oem/V/nZ2MeqbQ9yrfj46BfCI84NwheqpZYnNE7utfaIibgsIbkj1V7ZcblhfsdhzA== 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: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) by HE1PR0802MB2619.eurprd08.prod.outlook.com (2603:10a6:3:d9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.18; Thu, 9 Jun 2022 07:52:43 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::54e5:594b:e5fd:a9b4]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::54e5:594b:e5fd:a9b4%7]) with mapi id 15.20.5314.019; Thu, 9 Jun 2022 07:52:42 +0000 Date: Thu, 9 Jun 2022 08:52:35 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH]middle-end Use subregs to expand COMPLEX_EXPR to set the lowpart. Message-ID: Content-Disposition: inline X-ClientProxiedBy: SN7PR18CA0018.namprd18.prod.outlook.com (2603:10b6:806:f3::10) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 3f10ca44-1698-4456-2b27-08da49ed0e29 X-MS-TrafficTypeDiagnostic: HE1PR0802MB2619:EE_|AM5EUR03FT026:EE_|AS8PR08MB8040:EE_ X-Microsoft-Antispam-PRVS: 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: NB11E8kmvD1DwybtY1DDfBYiNfl3EXerDreP24TQUSYkjOXDyjYlHCC46qwotxbAlCAaTcK2YxU7nLicSalyYbhIoHHKP+8nwoev3pH9SlwQxFH5NoPfkmuLc1kyZxPJ+y5Itv2/0mLJ6ecW6fQm8ONKeiEfMwfVJGOcElgNj2NCiNF0J4YrZptqupqC6tQGE8XXVaBGbY07Z9GCXHDbSVsoGc8eOh2ctEmq/0SyowVePAXX6KOfKIKcM9x7BtIuZN4ek1ga8mIP2WU0/d4f10EuXxXsyYxAWgJhO0rEH2nREXyP6X7uQqsoQlKNTObgtcbrD+md3rKwttry7SqFFaWBeM/GqVLqRecmuNYbS5pxSEUKgQRZbNJ5FV1ZjBs8i4Zfwvc5gkM7mSrkgQkU8ZTgl62aWTuVgdNbKiB9gEY34DbnsFCqPfwrceT13hrgT2OEW/jpRl76XTAyDAR635guLH1WZXM8s8YsZRmjEH35CuZfesbf2TzqlO4lMcF6I+U7Lx64DLDnIOtlCuC5faLdEkwLUOueAenUFcMCATgFLISfVfxJjyLbe/nrP97rYikvPQr9cvC2bmx6RrWAYgStJ/dKIx0svO/1So57aFpMhlpvield0N6/7OrhRU4xIpiGBrnp5+EDtiCqNz+0iMF6tb6HC2KhTMVIxe+zLJ5E55PsH8kvYYg9PRgh70cnP9cnuUHQEvBElxll0GCwSk8btra6o8kypPOKKUKvUsc= 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:(13230001)(4636009)(366004)(66476007)(66556008)(83380400001)(8936002)(66946007)(6506007)(6486002)(6916009)(508600001)(2616005)(38100700002)(186003)(6666004)(36756003)(33964004)(44144004)(6512007)(26005)(44832011)(2906002)(5660300002)(235185007)(4326008)(86362001)(8676002)(316002)(4216001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2619 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 69c0646e-6c79-4e4b-2ff6-08da49ed0856 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7sa+615StZyDBymR9ol0pJCOJvUmvxYq8sLxaGx6sB+WqiydjKBBMp84pXJhkm91YxBypgpngB+EK+qXdwI7SLxfVlYW9qqsSQgYkZ8gmqEhAUshDan/s8gAEAAZM62RtgJ8ik4nm0S6LXs4TA5+Uo0jA42LCMqPKEtH5HGFhTqtp02wPmy6ipJH3CHM/v0Rf4bxXRVrq3DGyl9DODloq3SQhUxXcin8nXRLZ3/YEQjm3KlF73qnLS4Z6PPH9ZyVdfgJzDaQ+tFcyBEI9l4ZZOZxGvNM45GCZ7deVKFQIwmk2AKv0Mt06KjucLYIkLSGBo6dFse7gGu9NtxLbPTnk7eqMJj9Mf3Grgl6AdFeNcBSrprddrWbCUQEfYTMO14OVgUzO1KapcAUSwaaX86i0vZy7kx+5oCUd6dazCKpK0CRTdVTLlTsaYXv/4hkIMKoMu4KvpVz3cmiHiH0fygNfc+Z30H2h+0XEkrWOHe24tfNRsFBX6T0+qB+bm8x/2gvTvS755zmqyCOH79nT9wpnsopnKL2ZBRT1/OwDJz9Fu39jQ1uNU7NQ1t/0fUqb6jvdaWg6cmqVumxf1Gy83jfQcmYRWpLoa3F2pYl3ARCrsN57pcBzDxz4kJjCgXRBGe9kZ4Q9MVzMeJKWigpzRQHNY6NAyOs+4ZjOXbDGKexfVrzXHyErI5YOo1sjo8WhlolchmrzYjxHrqj6q1OG4JxeYVfCzUBHaiPpBrzRhJp2Ek= 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(70206006)(2906002)(316002)(26005)(2616005)(82310400005)(33964004)(44144004)(6916009)(6666004)(6506007)(107886003)(6512007)(40460700003)(47076005)(36756003)(70586007)(5660300002)(6486002)(36860700001)(8676002)(336012)(186003)(4326008)(81166007)(86362001)(83380400001)(356005)(235185007)(508600001)(44832011)(8936002)(4216001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2022 07:52:51.9083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f10ca44-1698-4456-2b27-08da49ed0e29 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: AM5EUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8040 X-Spam-Status: No, score=-12.7 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: Tamar Christina via Gcc-patches From: Tamar Christina Reply-To: Tamar Christina Cc: richard.sandiford@arm.com, nd@arm.com, rguenther@suse.de Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi All, When lowering COMPLEX_EXPR we currently emit two VEC_EXTRACTs. One for the lowpart and one for the highpart. The problem with this is that in RTL the lvalue of the RTX is the only thing tying the two instructions together. This means that e.g. combine is unable to try to combine the two instructions for setting the lowpart and highpart. For ISAs that have bit extract instructions we can eliminate one of the extracts if, and only if we're setting the entire complex number. This change changes the expand code when we're setting the entire complex number to generate a subreg for the lowpart instead of a vec_extract. This allows us to optimize sequences such as: _Complex int f(int a, int b) { _Complex int t = a + b * 1i; return t; } from: f: bfi x2, x0, 0, 32 bfi x2, x1, 32, 32 mov x0, x2 ret into: f: bfi x0, x1, 32, 32 ret I have also confirmed the codegen for x86_64 did not change. Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: * emit-rtl.cc (validate_subreg): Accept subregs of complex modes. * expr.cc (emit_move_complex_parts): Emit subreg of lowpart if possible. gcc/testsuite/ChangeLog: * g++.target/aarch64/complex-init.C: New test. --- inline copy of patch -- diff --git a/gcc/emit-rtl.cc b/gcc/emit-rtl.cc index f4404d7abe33b565358b7f609a91114c75ecf4e7..15ffca2ffe986bca56c1fae9381bd33f5d6b012d 100644 --- diff --git a/gcc/emit-rtl.cc b/gcc/emit-rtl.cc index f4404d7abe33b565358b7f609a91114c75ecf4e7..15ffca2ffe986bca56c1fae9381bd33f5d6b012d 100644 --- a/gcc/emit-rtl.cc +++ b/gcc/emit-rtl.cc @@ -947,9 +947,11 @@ validate_subreg (machine_mode omode, machine_mode imode, && GET_MODE_INNER (omode) == GET_MODE_INNER (imode)) ; /* Subregs involving floating point modes are not allowed to - change size. Therefore (subreg:DI (reg:DF) 0) is fine, but + change size unless it's an insert into a complex mode. + Therefore (subreg:DI (reg:DF) 0) and (subreg:CS (reg:SF) 0) are fine, but (subreg:SI (reg:DF) 0) isn't. */ - else if (FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode)) + else if ((FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode)) + && !COMPLEX_MODE_P (omode)) { if (! (known_eq (isize, osize) /* LRA can use subreg to store a floating point value in diff --git a/gcc/expr.cc b/gcc/expr.cc index 5f7142b975ada2cd8b00663d35ba1e0004b8e28d..fce672c236fdbc4d40adb6e2614c234c02a61933 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -3740,7 +3740,17 @@ emit_move_complex_parts (rtx x, rtx y) && REG_P (x) && !reg_overlap_mentioned_p (x, y)) emit_clobber (x); - write_complex_part (x, read_complex_part (y, false), false); + /* If we're writing the entire value using a concat into a register + then emit the lower part as a simple mov followed by an insert + into the top part. */ + if (GET_CODE (y) == CONCAT && !reload_completed && REG_P (x)) + { + rtx val = XEXP (y, false); + rtx dest = lowpart_subreg (GET_MODE (val), x, GET_MODE (x)); + emit_move_insn (dest, val); + } + else + write_complex_part (x, read_complex_part (y, false), false); write_complex_part (x, read_complex_part (y, true), true); return get_last_insn (); diff --git a/gcc/testsuite/g++.target/aarch64/complex-init.C b/gcc/testsuite/g++.target/aarch64/complex-init.C new file mode 100644 index 0000000000000000000000000000000000000000..497cc4bca3e2c59da95c871ceb5cc96216fc302d --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/complex-init.C @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { check-function-bodies "**" "" "" { target { le } } } } */ + +/* +** _Z1fii: +** ... +** bfi x0, x1, 32, 32 +** ret +** ... +*/ +_Complex int f(int a, int b) { + _Complex int t = a + b * 1i; + return t; +} + +/* +** _Z2f2ii: +** ... +** bfi x0, x1, 32, 32 +** ret +** ... +*/ +_Complex int f2(int a, int b) { + _Complex int t = {a, b}; + return t; +} + +/* +** _Z12f_convolutedii: +** ... +** bfi x0, x1, 32, 32 +** ret +** ... +*/ +_Complex int f_convoluted(int a, int b) { + _Complex int t = (_Complex int)a; + __imag__ t = b; + return t; +} --- a/gcc/emit-rtl.cc +++ b/gcc/emit-rtl.cc @@ -947,9 +947,11 @@ validate_subreg (machine_mode omode, machine_mode imode, && GET_MODE_INNER (omode) == GET_MODE_INNER (imode)) ; /* Subregs involving floating point modes are not allowed to - change size. Therefore (subreg:DI (reg:DF) 0) is fine, but + change size unless it's an insert into a complex mode. + Therefore (subreg:DI (reg:DF) 0) and (subreg:CS (reg:SF) 0) are fine, but (subreg:SI (reg:DF) 0) isn't. */ - else if (FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode)) + else if ((FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode)) + && !COMPLEX_MODE_P (omode)) { if (! (known_eq (isize, osize) /* LRA can use subreg to store a floating point value in diff --git a/gcc/expr.cc b/gcc/expr.cc index 5f7142b975ada2cd8b00663d35ba1e0004b8e28d..fce672c236fdbc4d40adb6e2614c234c02a61933 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -3740,7 +3740,17 @@ emit_move_complex_parts (rtx x, rtx y) && REG_P (x) && !reg_overlap_mentioned_p (x, y)) emit_clobber (x); - write_complex_part (x, read_complex_part (y, false), false); + /* If we're writing the entire value using a concat into a register + then emit the lower part as a simple mov followed by an insert + into the top part. */ + if (GET_CODE (y) == CONCAT && !reload_completed && REG_P (x)) + { + rtx val = XEXP (y, false); + rtx dest = lowpart_subreg (GET_MODE (val), x, GET_MODE (x)); + emit_move_insn (dest, val); + } + else + write_complex_part (x, read_complex_part (y, false), false); write_complex_part (x, read_complex_part (y, true), true); return get_last_insn (); diff --git a/gcc/testsuite/g++.target/aarch64/complex-init.C b/gcc/testsuite/g++.target/aarch64/complex-init.C new file mode 100644 index 0000000000000000000000000000000000000000..497cc4bca3e2c59da95c871ceb5cc96216fc302d --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/complex-init.C @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { check-function-bodies "**" "" "" { target { le } } } } */ + +/* +** _Z1fii: +** ... +** bfi x0, x1, 32, 32 +** ret +** ... +*/ +_Complex int f(int a, int b) { + _Complex int t = a + b * 1i; + return t; +} + +/* +** _Z2f2ii: +** ... +** bfi x0, x1, 32, 32 +** ret +** ... +*/ +_Complex int f2(int a, int b) { + _Complex int t = {a, b}; + return t; +} + +/* +** _Z12f_convolutedii: +** ... +** bfi x0, x1, 32, 32 +** ret +** ... +*/ +_Complex int f_convoluted(int a, int b) { + _Complex int t = (_Complex int)a; + __imag__ t = b; + return t; +}