From patchwork Sat Feb 11 02:51:18 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: 55677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1299644wrn; Fri, 10 Feb 2023 18:52:30 -0800 (PST) X-Google-Smtp-Source: AK7set/jMo6BSQiEWsZWO1N8q48BlYRGxUsaDQ1GO+RXaolDQgOUvQ28dWzdrjXfww5GpLQhL6aZ X-Received: by 2002:a17:906:6a1b:b0:8af:b63:b4bf with SMTP id qw27-20020a1709066a1b00b008af0b63b4bfmr13882962ejc.27.1676083950143; Fri, 10 Feb 2023 18:52:30 -0800 (PST) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id aa5-20020a170907354500b0088fa4de4edcsi7063409ejc.438.2023.02.10.18.52.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 18:52:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AyyOFBqc; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 AE3D93858C5F for ; Sat, 11 Feb 2023 02:52:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE3D93858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676083948; bh=s05FFhfuv7c/oyCZUx57b4k2GWCFMDIxsglf8tzc8Ag=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=AyyOFBqcKOvIAo/WGztFf4Hqbjv2BU//tXAPZ0GyGwJW1U/p+yAEIB8Thb3CoFgpr LoRAKwwAkNnO+AT2davfEgD77Dypu51tNTAmYc0xB0PoeeRU0fVltYJpFnMT76emiY 077pfPbyo1jLTjVec/VFsI1AsQk7fg16xCO5R+jQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12olkn2060.outbound.protection.outlook.com [40.92.22.60]) by sourceware.org (Postfix) with ESMTPS id 919973858C62 for ; Sat, 11 Feb 2023 02:51:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 919973858C62 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PokdoStPcFZtXlLtAS2EC0ZnFf12AhbUjDTT7Wsfxsgb+0Fgf0A+Sd1P3zaRTSBHHU+1sp2T2/YTgjOYgAuP+ac/dvmScRGW3sYuWM47nblaq1RWLxh4ZLqWL5ChsaivkBHvqWicyQY+o/a4ov/zUjzQG7WKXV7uiWn1XRuLqlC6gmD+RzXM8s9drgFcKr3NudL1mKZE4/Hoh/nGSM+QZdURF85hjPd5cUH3xW8TBZAkdD9FEngz/S/5xicCt8UV5aa6PLFg9RrCK5WDW3Goi3dx9oG8EgqpP6JPoDKsFeZF9KMVZZDNhW+Z4xqqjm4FUleDw8PUrHmr3SwekUfudw== 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=s05FFhfuv7c/oyCZUx57b4k2GWCFMDIxsglf8tzc8Ag=; b=Sa/fdDE1aI9zWgFvbpX6HdmTacxzgmzArHCWoowVhSTeeT/nF+pJBorhhHxcaT53C4hLszVvNO+EnxuffWa3IiDbXqoWDjTPRg3en4lkryJhkhepxm1qd3yz24iYhOuR+rzWvrE88ODEiHcadSCC2+x57tPxZ3kMaouWZqAIJabNCVvsKCyQ5mKerjXT1v/3KCgo8Me97IHwhhibOxJ9VV+YFL+7M3sEgLs+in9Z2tTd89CnaXc2BlmP8ifYaOlw/QR6iQLb9MwYWzVkaE2Ti+yfFtzFE+7Yq2NBDb9dzXOk2lzDqI2LYsRlGxEbe/HFbO0AifLVjMo0re1Mxn4Svg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from BYAPR04MB4824.namprd04.prod.outlook.com (2603:10b6:a03:5e::19) by BN8PR04MB6035.namprd04.prod.outlook.com (2603:10b6:408:5e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.36; Sat, 11 Feb 2023 02:51:34 +0000 Received: from BYAPR04MB4824.namprd04.prod.outlook.com ([fe80::3a96:d832:ac44:1c25]) by BYAPR04MB4824.namprd04.prod.outlook.com ([fe80::3a96:d832:ac44:1c25%7]) with mapi id 15.20.6064.031; Sat, 11 Feb 2023 02:51:34 +0000 To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@sifive.com, rguenther@suse.de, Pan Li Subject: [PATCH] RISC-V: Optimize the code gen of VLM/VSM. Date: Sat, 11 Feb 2023 10:51:18 +0800 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [5udf4IS/HuxF4wN6fTJrbvlwEmg5tUoS] X-ClientProxiedBy: SG2P153CA0003.APCP153.PROD.OUTLOOK.COM (2603:1096::13) To BYAPR04MB4824.namprd04.prod.outlook.com (2603:10b6:a03:5e::19) X-Microsoft-Original-Message-ID: <20230211025118.153473-1-incarnation.p.lee@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR04MB4824:EE_|BN8PR04MB6035:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d748748-16ff-4baa-6489-08db0bdae28a X-MS-Exchange-SLBlob-MailProps: QG/aTLqFmeg26sHb/aqVwlLfTJ2DMXG72lzv4K7N0KWswJtv2k0pisJyT7lbMhhT2/FxaPpnqEPz8/wC9+PXlCZmmQlxA9REw3dv2I+2IqPhzgdFwvt8kCkN6XksekOQR0wNZY9Z+niCNF/l4UHmXLVcUmAQKHV3LJbEdcu8RgI32xGKpRoEk1OuL+aqNVJ7LpxB1/iZ/au8L8lE8H7jSUm+9Dv1WNjXTYcajCJpN+zkyhShQ6iXq7ZhQW78wpwTxf/HUry73Jr9wU0ADU2+wOBghJDt7McTV63MmTWNTo5Tt1bLvwd6o4pNz3dFhw6kHaMjdjyTgdkquovL2bsEC+o67l4npCp6kDc/yYmtBMBYn0/ogUuLHBktNneX6lVrQPi+jvO+bhagjyCekxfQRJulg3RKxpRiW9sK15c62Zfj5ds5l2+U0emXr4uBAqI6nMY1J9M5f8NIzvFzPjZWYWaZ8fPpJavIggR314I7HzFc1XV+K8B69qRYlSmoBorRPm6wDV567AdbKsIqY9a5EH9+6rJB7eYd6GA/85PFiZ7FrdgRgKfnKCxrneWpSMSH6+ldb2Ffz//e9zZMFaSMvC0CBb7Xc66/Zr2cHBCinbeN2PYf4nAGTzjVvglhP8H/gWXDzCy7L6nPSRKgOf7NaDrP8l8lyxTh X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OL3nwGt3xXhpIGNg7boOcCAti/lTpmkCn27RVFxKQhjAQvQizVxog+dDXWTS9ipDMEmNrg53zILqRhB1paB1mA0Qji3MK7D+Abg7JvYgqdnbeH7WFGFAt6uf6KbIGpvdepoAgb9Y3/AyPs8PSZcdwm76Z9qEQe84c3fQS29YOQbaLLuYLTNciiCIdiF2Lg7A5LDTbebFIxCYniWRSkYrvXciw8TriNP0V10oAPHrpC9Q4fegC9UEtAewVR9RUx74afW2odZDylbC6nKLaBTaEhGCAQHfQfxKPtuGZo3L1NKhHpIyh9EeYLGbICk3KTqDUN5e0GT9SmU13yVtBzhzk/kFxnz8irnEKPQF4XOw/XfoW3WI5vLTW2kQrfg+/fGEtPqodlOR26x9fu9rNjxBZasRc6H/O2Mff3un/PChEgvUg5cAbTp2OOpssuTGNl0uQ5zXO0dYa4yNPC2FHrfnbK78CwxhPngeAi/Z7UkrXoU+figtvlJewLzH5SiNEE7vH8faWOSFU1ISxmuCgUhuX10vDcGFbl9eylrXpvuAe0MMClXA8khNtgAptErB6W4MZohUTy04SafP2vwiVzFAPuh2lov/AijEvbN/fw29pOoqCCPwmNrp4fdKh5NKTyCm2O1FGPaLEcKP/WJpwQI6BA== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YeDsIKpPwEXdbTm2ei9Je6Sz4jEI/Yrqf/I623D6eLzp77iTtLQa9ZSE8ALNvY1eFSZ27DXAb+7lqc7I8h5Z6iDLbFX+w3OCXkY06arOTrISvrmI0j5tkwj6G3W1+5Vg6YiTEPVxLXCFi5suJVQLABC35+9l0BwIYbwG5ncWIhxp226m+dPnd+4M8/ULtOPkxD79dsc9ztaA52CCrnqc9zdcuiif4DfE0kNDTvtq5d5gkzatHEfiMRLjnAML4uCHujVBxd2nupFloM+Nj1t3N2VSb1Q4MrMEN90vPUa0oAqsX0KgY0s9dtk+nJvsVgX6P8Cj81hwxquW3EI7GXK+VYwpSYx1hLyTaf8tz4Ps4LZqfZeYyfim420Hht7Bo99knqPE5j9P9MHuafSMcZCgV0wHuE+qLXizyigc20jZJ8EexXza1Myv2dL+ylf2P11eTTUE9iyandz2ZGBTBjNp6mV3MFDoTWLKs7iMzBmAgPFb4Ru1DFqRd6Fjig9hlxUXeVQ7zZ0NQDlgEpi9wnniOxNltOwi7gvjU4RRpj8wO/8gJjwRhSredtKnHt0VqEONjUItPcl7V2SiUCumEG5x2Hz6utBInBJUuxrx/jt6sKZWuaSiA/+AIBB1tx+GVBCXqFI7RGR0ufErv1rv9TVlTSWJ/xA0GYmDHBE5YHEVEucfz3lEv77mCtWQapm62+bcql9rt2s8hASjMKW/IO3m4v46c5ilOYsddaPfF2AQuCd4+ebqb8gwX5drbj+4q3Uqb82OQNdvUI2uzTImSzmsmJmpYnoVJ+SHYGeZp6Vj1KbcRi4NaK70FsIwEC4TNaYYVHE9ks228pr4yl60hB0CLioZuycNX/ibMWAFJGCc86weCJnnZMZokIKly6xNkuWY/45lEbyYKODpPPiD9BDNjST9EYXw2HLFw+SWYN/mVOiFF7Dvxkw225T0pVNQbY9g7nnWP7Fx2bQ/RuR54lLe95zC6mvmpDhIKvJCAuRuqhCxydmBYSUp8KgRhAszzKwpfO8CI+JWxBMrQnOgZ0jTELs06VFIxY4/s5a+3b2+ri3A3G6XhNUYfiCtzepbjUTgJgwplYGlJAQTm1mkwsaDl2KehNypkHL8l3dIKoWYA4+iojeWAlnGBeVB02NQ0q/vkevNMrvpFfq7266vzi34DaoJPFH8b2MnhMkI6lv8Og3gHUErBAcmHIopmFdZz3QmkXJ351ojG/OlqZPyvkg49UYy+CClB3GDFpDbIy3iPUY3gl9vpQj1IP900mTxMsslOhQzvxyrSuj0YpIJrNmsxzThPaAKJojhcQAznRllp+k= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d748748-16ff-4baa-6489-08db0bdae28a X-MS-Exchange-CrossTenant-AuthSource: BYAPR04MB4824.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2023 02:51:33.9240 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR04MB6035 X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_PASS, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "incarnation.p.lee--- via Gcc-patches" From: "Li, Pan2 via Gcc-patches" Reply-To: incarnation.p.lee@outlook.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?1757501404250053025?= X-GMAIL-MSGID: =?utf-8?q?1757501404250053025?= From: Pan Li PR 108185 PR 108654 The bytesize of the vbool*_t isn't well defined. This patch adjust the rvv bool modes with actually mode size in bytes. However, only allow mode tieable when exactly equal for the rvv bool types, aka vbool1_t, vbool2_t, vbool4_t, vbool8_t, vbool16_t, vbool32_t, and vbool64_t. gcc/ChangeLog: * config/riscv/riscv-modes.def (ADJUST_BYTESIZE): * config/riscv/riscv.cc (riscv_v_adjust_bytesize): (riscv_modes_tieable_p): * config/riscv/riscv.h (riscv_v_adjust_bytesize): * machmode.h (VECTOR_BOOL_MODE_P): * tree-ssa-sccvn.cc (visit_reference_op_load): gcc/testsuite/ChangeLog: * gcc.target/riscv/pr108185-1.c: New test. * gcc.target/riscv/pr108185-2.c: New test. * gcc.target/riscv/pr108185-3.c: New test. * gcc.target/riscv/pr108185-4.c: New test. * gcc.target/riscv/pr108185-5.c: New test. * gcc.target/riscv/pr108185-6.c: New test. * gcc.target/riscv/pr108185-7.c: New test. * gcc.target/riscv/pr108185-8.c: New test. --- gcc/config/riscv/riscv-modes.def | 14 ++-- gcc/config/riscv/riscv.cc | 34 ++++++++- gcc/config/riscv/riscv.h | 2 + gcc/machmode.h | 3 + gcc/testsuite/gcc.target/riscv/pr108185-1.c | 68 ++++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr108185-2.c | 68 ++++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr108185-3.c | 68 ++++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr108185-4.c | 68 ++++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr108185-5.c | 68 ++++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr108185-6.c | 68 ++++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr108185-7.c | 68 ++++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr108185-8.c | 77 +++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 13 +++- 13 files changed, 608 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/pr108185-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr108185-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr108185-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr108185-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr108185-5.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr108185-6.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr108185-7.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr108185-8.c diff --git a/gcc/config/riscv/riscv-modes.def b/gcc/config/riscv/riscv-modes.def index d5305efa8a6..cc21d3c83a2 100644 --- a/gcc/config/riscv/riscv-modes.def +++ b/gcc/config/riscv/riscv-modes.def @@ -64,13 +64,13 @@ ADJUST_ALIGNMENT (VNx16BI, 1); ADJUST_ALIGNMENT (VNx32BI, 1); ADJUST_ALIGNMENT (VNx64BI, 1); -ADJUST_BYTESIZE (VNx1BI, riscv_vector_chunks * riscv_bytes_per_vector_chunk); -ADJUST_BYTESIZE (VNx2BI, riscv_vector_chunks * riscv_bytes_per_vector_chunk); -ADJUST_BYTESIZE (VNx4BI, riscv_vector_chunks * riscv_bytes_per_vector_chunk); -ADJUST_BYTESIZE (VNx8BI, riscv_vector_chunks * riscv_bytes_per_vector_chunk); -ADJUST_BYTESIZE (VNx16BI, riscv_vector_chunks * riscv_bytes_per_vector_chunk); -ADJUST_BYTESIZE (VNx32BI, riscv_vector_chunks * riscv_bytes_per_vector_chunk); -ADJUST_BYTESIZE (VNx64BI, riscv_v_adjust_nunits (VNx64BImode, 8)); +ADJUST_BYTESIZE (VNx1BI, riscv_v_adjust_bytesize (VNx1BImode, 1)); +ADJUST_BYTESIZE (VNx2BI, riscv_v_adjust_bytesize (VNx2BImode, 1)); +ADJUST_BYTESIZE (VNx4BI, riscv_v_adjust_bytesize (VNx4BImode, 1)); +ADJUST_BYTESIZE (VNx8BI, riscv_v_adjust_bytesize (VNx8BImode, 1)); +ADJUST_BYTESIZE (VNx16BI, riscv_v_adjust_bytesize (VNx16BImode, 2)); +ADJUST_BYTESIZE (VNx32BI, riscv_v_adjust_bytesize (VNx32BImode, 4)); +ADJUST_BYTESIZE (VNx64BI, riscv_v_adjust_bytesize (VNx64BImode, 8)); /* | Mode | MIN_VLEN=32 | MIN_VLEN=32 | MIN_VLEN=64 | MIN_VLEN=64 | diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 3b7804b7501..995cdab108f 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -1003,6 +1003,27 @@ riscv_v_adjust_nunits (machine_mode mode, int scale) return scale; } +/* Call from ADJUST_BYTESIZE in riscv-modes.def. Return the correct + BYTES size for corresponding machine_mode. */ + +poly_int64 +riscv_v_adjust_bytesize (machine_mode mode, int scale) +{ + gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL); + + if (riscv_v_ext_vector_mode_p (mode)) + { + poly_uint16 mode_size = GET_MODE_SIZE (mode); + + if (known_lt (mode_size, BYTES_PER_RISCV_VECTOR)) + return mode_size; + else + return BYTES_PER_RISCV_VECTOR; + } + + return scale; +} + /* Return true if X is a valid address for machine mode MODE. If it is, fill in INFO appropriately. STRICT_P is true if REG_OK_STRICT is in effect. */ @@ -5807,11 +5828,22 @@ riscv_hard_regno_mode_ok (unsigned int regno, machine_mode mode) /* Implement TARGET_MODES_TIEABLE_P. Don't allow floating-point modes to be tied, since type punning of - single-precision and double-precision is implementation defined. */ + single-precision and double-precision is implementation defined. + + Don't allow different vbool*_t modes to be tied, since the type + size is determinated by vl. */ static bool riscv_modes_tieable_p (machine_mode mode1, machine_mode mode2) { + if (riscv_v_ext_vector_mode_p (mode1) && riscv_v_ext_vector_mode_p (mode2)) + { + if (VECTOR_BOOL_MODE_P (mode1) || VECTOR_BOOL_MODE_P (mode2)) + return mode1 == mode2; + + return known_eq (GET_MODE_SIZE (mode1), GET_MODE_SIZE (mode2)); + } + return (mode1 == mode2 || !(GET_MODE_CLASS (mode1) == MODE_FLOAT && GET_MODE_CLASS (mode2) == MODE_FLOAT)); diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index faffd5a77fe..f857223338c 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -1028,6 +1028,8 @@ extern unsigned riscv_stack_boundary; extern unsigned riscv_bytes_per_vector_chunk; extern poly_uint16 riscv_vector_chunks; extern poly_int64 riscv_v_adjust_nunits (enum machine_mode, int); +extern poly_int64 riscv_v_adjust_bytesize (machine_mode mode, int scale); + /* The number of bits and bytes in a RVV vector. */ #define BITS_PER_RISCV_VECTOR (poly_uint16 (riscv_vector_chunks * riscv_bytes_per_vector_chunk * 8)) #define BYTES_PER_RISCV_VECTOR (poly_uint16 (riscv_vector_chunks * riscv_bytes_per_vector_chunk)) diff --git a/gcc/machmode.h b/gcc/machmode.h index f1865c1ef42..6720472f2c9 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -242,6 +242,9 @@ extern const unsigned char mode_class[NUM_MACHINE_MODES]; || CLASS == MODE_ACCUM \ || CLASS == MODE_UACCUM) +/* Nonzero if MODE is an vector bool mode. */ +#define VECTOR_BOOL_MODE_P(MODE) (GET_MODE_CLASS(MODE) == MODE_VECTOR_BOOL) + /* An optional T (i.e. a T or nothing), where T is some form of mode class. */ template class opt_mode diff --git a/gcc/testsuite/gcc.target/riscv/pr108185-1.c b/gcc/testsuite/gcc.target/riscv/pr108185-1.c new file mode 100644 index 00000000000..c3d0b10271a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr108185-1.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +#include "riscv_vector.h" + +void +test_vbool1_then_vbool2(int8_t * restrict in, int8_t * restrict out) { + vbool1_t v1 = *(vbool1_t*)in; + vbool2_t v2 = *(vbool2_t*)in; + + *(vbool1_t*)(out + 100) = v1; + *(vbool2_t*)(out + 200) = v2; +} + +void +test_vbool1_then_vbool4(int8_t * restrict in, int8_t * restrict out) { + vbool1_t v1 = *(vbool1_t*)in; + vbool4_t v2 = *(vbool4_t*)in; + + *(vbool1_t*)(out + 100) = v1; + *(vbool4_t*)(out + 200) = v2; +} + +void +test_vbool1_then_vbool8(int8_t * restrict in, int8_t * restrict out) { + vbool1_t v1 = *(vbool1_t*)in; + vbool8_t v2 = *(vbool8_t*)in; + + *(vbool1_t*)(out + 100) = v1; + *(vbool8_t*)(out + 200) = v2; +} + +void +test_vbool1_then_vbool16(int8_t * restrict in, int8_t * restrict out) { + vbool1_t v1 = *(vbool1_t*)in; + vbool16_t v2 = *(vbool16_t*)in; + + *(vbool1_t*)(out + 100) = v1; + *(vbool16_t*)(out + 200) = v2; +} + +void +test_vbool1_then_vbool32(int8_t * restrict in, int8_t * restrict out) { + vbool1_t v1 = *(vbool1_t*)in; + vbool32_t v2 = *(vbool32_t*)in; + + *(vbool1_t*)(out + 100) = v1; + *(vbool32_t*)(out + 200) = v2; +} + +void +test_vbool1_then_vbool64(int8_t * restrict in, int8_t * restrict out) { + vbool1_t v1 = *(vbool1_t*)in; + vbool64_t v2 = *(vbool64_t*)in; + + *(vbool1_t*)(out + 100) = v1; + *(vbool64_t*)(out + 200) = v2; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m8,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m1,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vlm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ +/* { dg-final { scan-assembler-times {vsm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/pr108185-2.c b/gcc/testsuite/gcc.target/riscv/pr108185-2.c new file mode 100644 index 00000000000..bd13ba916da --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr108185-2.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +#include "riscv_vector.h" + +void +test_vbool2_then_vbool1(int8_t * restrict in, int8_t * restrict out) { + vbool2_t v1 = *(vbool2_t*)in; + vbool1_t v2 = *(vbool1_t*)in; + + *(vbool2_t*)(out + 100) = v1; + *(vbool1_t*)(out + 200) = v2; +} + +void +test_vbool2_then_vbool4(int8_t * restrict in, int8_t * restrict out) { + vbool2_t v1 = *(vbool2_t*)in; + vbool4_t v2 = *(vbool4_t*)in; + + *(vbool2_t*)(out + 100) = v1; + *(vbool4_t*)(out + 200) = v2; +} + +void +test_vbool2_then_vbool8(int8_t * restrict in, int8_t * restrict out) { + vbool2_t v1 = *(vbool2_t*)in; + vbool8_t v2 = *(vbool8_t*)in; + + *(vbool2_t*)(out + 100) = v1; + *(vbool8_t*)(out + 200) = v2; +} + +void +test_vbool2_then_vbool16(int8_t * restrict in, int8_t * restrict out) { + vbool2_t v1 = *(vbool2_t*)in; + vbool16_t v2 = *(vbool16_t*)in; + + *(vbool2_t*)(out + 100) = v1; + *(vbool16_t*)(out + 200) = v2; +} + +void +test_vbool2_then_vbool32(int8_t * restrict in, int8_t * restrict out) { + vbool2_t v1 = *(vbool2_t*)in; + vbool32_t v2 = *(vbool32_t*)in; + + *(vbool2_t*)(out + 100) = v1; + *(vbool32_t*)(out + 200) = v2; +} + +void +test_vbool2_then_vbool64(int8_t * restrict in, int8_t * restrict out) { + vbool2_t v1 = *(vbool2_t*)in; + vbool64_t v2 = *(vbool64_t*)in; + + *(vbool2_t*)(out + 100) = v1; + *(vbool64_t*)(out + 200) = v2; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m4,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m1,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vlm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ +/* { dg-final { scan-assembler-times {vsm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/pr108185-3.c b/gcc/testsuite/gcc.target/riscv/pr108185-3.c new file mode 100644 index 00000000000..99928f7b1cc --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr108185-3.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +#include "riscv_vector.h" + +void +test_vbool4_then_vbool1(int8_t * restrict in, int8_t * restrict out) { + vbool4_t v1 = *(vbool4_t*)in; + vbool1_t v2 = *(vbool1_t*)in; + + *(vbool4_t*)(out + 100) = v1; + *(vbool1_t*)(out + 200) = v2; +} + +void +test_vbool4_then_vbool2(int8_t * restrict in, int8_t * restrict out) { + vbool4_t v1 = *(vbool4_t*)in; + vbool2_t v2 = *(vbool2_t*)in; + + *(vbool4_t*)(out + 100) = v1; + *(vbool2_t*)(out + 200) = v2; +} + +void +test_vbool4_then_vbool8(int8_t * restrict in, int8_t * restrict out) { + vbool4_t v1 = *(vbool4_t*)in; + vbool8_t v2 = *(vbool8_t*)in; + + *(vbool4_t*)(out + 100) = v1; + *(vbool8_t*)(out + 200) = v2; +} + +void +test_vbool4_then_vbool16(int8_t * restrict in, int8_t * restrict out) { + vbool4_t v1 = *(vbool4_t*)in; + vbool16_t v2 = *(vbool16_t*)in; + + *(vbool4_t*)(out + 100) = v1; + *(vbool16_t*)(out + 200) = v2; +} + +void +test_vbool4_then_vbool32(int8_t * restrict in, int8_t * restrict out) { + vbool4_t v1 = *(vbool4_t*)in; + vbool32_t v2 = *(vbool32_t*)in; + + *(vbool4_t*)(out + 100) = v1; + *(vbool32_t*)(out + 200) = v2; +} + +void +test_vbool4_then_vbool64(int8_t * restrict in, int8_t * restrict out) { + vbool4_t v1 = *(vbool4_t*)in; + vbool64_t v2 = *(vbool64_t*)in; + + *(vbool4_t*)(out + 100) = v1; + *(vbool64_t*)(out + 200) = v2; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m2,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m1,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vlm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ +/* { dg-final { scan-assembler-times {vsm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/pr108185-4.c b/gcc/testsuite/gcc.target/riscv/pr108185-4.c new file mode 100644 index 00000000000..e70284fada8 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr108185-4.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +#include "riscv_vector.h" + +void +test_vbool8_then_vbool1(int8_t * restrict in, int8_t * restrict out) { + vbool8_t v1 = *(vbool8_t*)in; + vbool1_t v2 = *(vbool1_t*)in; + + *(vbool8_t*)(out + 100) = v1; + *(vbool1_t*)(out + 200) = v2; +} + +void +test_vbool8_then_vbool2(int8_t * restrict in, int8_t * restrict out) { + vbool8_t v1 = *(vbool8_t*)in; + vbool2_t v2 = *(vbool2_t*)in; + + *(vbool8_t*)(out + 100) = v1; + *(vbool2_t*)(out + 200) = v2; +} + +void +test_vbool8_then_vbool4(int8_t * restrict in, int8_t * restrict out) { + vbool8_t v1 = *(vbool8_t*)in; + vbool4_t v2 = *(vbool4_t*)in; + + *(vbool8_t*)(out + 100) = v1; + *(vbool4_t*)(out + 200) = v2; +} + +void +test_vbool8_then_vbool16(int8_t * restrict in, int8_t * restrict out) { + vbool8_t v1 = *(vbool8_t*)in; + vbool16_t v2 = *(vbool16_t*)in; + + *(vbool8_t*)(out + 100) = v1; + *(vbool16_t*)(out + 200) = v2; +} + +void +test_vbool8_then_vbool32(int8_t * restrict in, int8_t * restrict out) { + vbool8_t v1 = *(vbool8_t*)in; + vbool32_t v2 = *(vbool32_t*)in; + + *(vbool8_t*)(out + 100) = v1; + *(vbool32_t*)(out + 200) = v2; +} + +void +test_vbool8_then_vbool64(int8_t * restrict in, int8_t * restrict out) { + vbool8_t v1 = *(vbool8_t*)in; + vbool64_t v2 = *(vbool64_t*)in; + + *(vbool8_t*)(out + 100) = v1; + *(vbool64_t*)(out + 200) = v2; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m1,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vlm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ +/* { dg-final { scan-assembler-times {vsm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/pr108185-5.c b/gcc/testsuite/gcc.target/riscv/pr108185-5.c new file mode 100644 index 00000000000..575a7842cdf --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr108185-5.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +#include "riscv_vector.h" + +void +test_vbool16_then_vbool1(int8_t * restrict in, int8_t * restrict out) { + vbool16_t v1 = *(vbool16_t*)in; + vbool1_t v2 = *(vbool1_t*)in; + + *(vbool16_t*)(out + 100) = v1; + *(vbool1_t*)(out + 200) = v2; +} + +void +test_vbool16_then_vbool2(int8_t * restrict in, int8_t * restrict out) { + vbool16_t v1 = *(vbool16_t*)in; + vbool2_t v2 = *(vbool2_t*)in; + + *(vbool16_t*)(out + 100) = v1; + *(vbool2_t*)(out + 200) = v2; +} + +void +test_vbool16_then_vbool4(int8_t * restrict in, int8_t * restrict out) { + vbool16_t v1 = *(vbool16_t*)in; + vbool4_t v2 = *(vbool4_t*)in; + + *(vbool16_t*)(out + 100) = v1; + *(vbool4_t*)(out + 200) = v2; +} + +void +test_vbool16_then_vbool8(int8_t * restrict in, int8_t * restrict out) { + vbool16_t v1 = *(vbool16_t*)in; + vbool8_t v2 = *(vbool8_t*)in; + + *(vbool16_t*)(out + 100) = v1; + *(vbool8_t*)(out + 200) = v2; +} + +void +test_vbool16_then_vbool32(int8_t * restrict in, int8_t * restrict out) { + vbool16_t v1 = *(vbool16_t*)in; + vbool32_t v2 = *(vbool32_t*)in; + + *(vbool16_t*)(out + 100) = v1; + *(vbool32_t*)(out + 200) = v2; +} + +void +test_vbool16_then_vbool64(int8_t * restrict in, int8_t * restrict out) { + vbool16_t v1 = *(vbool16_t*)in; + vbool64_t v2 = *(vbool64_t*)in; + + *(vbool16_t*)(out + 100) = v1; + *(vbool64_t*)(out + 200) = v2; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf2,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m1,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vlm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ +/* { dg-final { scan-assembler-times {vsm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/pr108185-6.c b/gcc/testsuite/gcc.target/riscv/pr108185-6.c new file mode 100644 index 00000000000..95a11d37016 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr108185-6.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +#include "riscv_vector.h" + +void +test_vbool32_then_vbool1(int8_t * restrict in, int8_t * restrict out) { + vbool32_t v1 = *(vbool32_t*)in; + vbool1_t v2 = *(vbool1_t*)in; + + *(vbool32_t*)(out + 100) = v1; + *(vbool1_t*)(out + 200) = v2; +} + +void +test_vbool32_then_vbool2(int8_t * restrict in, int8_t * restrict out) { + vbool32_t v1 = *(vbool32_t*)in; + vbool2_t v2 = *(vbool2_t*)in; + + *(vbool32_t*)(out + 100) = v1; + *(vbool2_t*)(out + 200) = v2; +} + +void +test_vbool32_then_vbool4(int8_t * restrict in, int8_t * restrict out) { + vbool32_t v1 = *(vbool32_t*)in; + vbool4_t v2 = *(vbool4_t*)in; + + *(vbool32_t*)(out + 100) = v1; + *(vbool4_t*)(out + 200) = v2; +} + +void +test_vbool32_then_vbool8(int8_t * restrict in, int8_t * restrict out) { + vbool32_t v1 = *(vbool32_t*)in; + vbool8_t v2 = *(vbool8_t*)in; + + *(vbool32_t*)(out + 100) = v1; + *(vbool8_t*)(out + 200) = v2; +} + +void +test_vbool32_then_vbool16(int8_t * restrict in, int8_t * restrict out) { + vbool32_t v1 = *(vbool32_t*)in; + vbool16_t v2 = *(vbool16_t*)in; + + *(vbool32_t*)(out + 100) = v1; + *(vbool16_t*)(out + 200) = v2; +} + +void +test_vbool32_then_vbool64(int8_t * restrict in, int8_t * restrict out) { + vbool32_t v1 = *(vbool32_t*)in; + vbool64_t v2 = *(vbool64_t*)in; + + *(vbool32_t*)(out + 100) = v1; + *(vbool64_t*)(out + 200) = v2; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf4,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m1,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vlm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ +/* { dg-final { scan-assembler-times {vsm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/pr108185-7.c b/gcc/testsuite/gcc.target/riscv/pr108185-7.c new file mode 100644 index 00000000000..8f6f0b11f09 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr108185-7.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +#include "riscv_vector.h" + +void +test_vbool64_then_vbool1(int8_t * restrict in, int8_t * restrict out) { + vbool64_t v1 = *(vbool64_t*)in; + vbool1_t v2 = *(vbool1_t*)in; + + *(vbool64_t*)(out + 100) = v1; + *(vbool1_t*)(out + 200) = v2; +} + +void +test_vbool64_then_vbool2(int8_t * restrict in, int8_t * restrict out) { + vbool64_t v1 = *(vbool64_t*)in; + vbool2_t v2 = *(vbool2_t*)in; + + *(vbool64_t*)(out + 100) = v1; + *(vbool2_t*)(out + 200) = v2; +} + +void +test_vbool64_then_vbool4(int8_t * restrict in, int8_t * restrict out) { + vbool64_t v1 = *(vbool64_t*)in; + vbool4_t v2 = *(vbool4_t*)in; + + *(vbool64_t*)(out + 100) = v1; + *(vbool4_t*)(out + 200) = v2; +} + +void +test_vbool64_then_vbool8(int8_t * restrict in, int8_t * restrict out) { + vbool64_t v1 = *(vbool64_t*)in; + vbool8_t v2 = *(vbool8_t*)in; + + *(vbool64_t*)(out + 100) = v1; + *(vbool8_t*)(out + 200) = v2; +} + +void +test_vbool64_then_vbool16(int8_t * restrict in, int8_t * restrict out) { + vbool64_t v1 = *(vbool64_t*)in; + vbool16_t v2 = *(vbool16_t*)in; + + *(vbool64_t*)(out + 100) = v1; + *(vbool16_t*)(out + 200) = v2; +} + +void +test_vbool64_then_vbool32(int8_t * restrict in, int8_t * restrict out) { + vbool64_t v1 = *(vbool64_t*)in; + vbool32_t v2 = *(vbool32_t*)in; + + *(vbool64_t*)(out + 100) = v1; + *(vbool32_t*)(out + 200) = v2; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf8,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m1,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vlm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ +/* { dg-final { scan-assembler-times {vsm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 12 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/pr108185-8.c b/gcc/testsuite/gcc.target/riscv/pr108185-8.c new file mode 100644 index 00000000000..d96959dd064 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr108185-8.c @@ -0,0 +1,77 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +#include "riscv_vector.h" + +void +test_vbool1_then_vbool1(int8_t * restrict in, int8_t * restrict out) { + vbool1_t v1 = *(vbool1_t*)in; + vbool1_t v2 = *(vbool1_t*)in; + + *(vbool1_t*)(out + 100) = v1; + *(vbool1_t*)(out + 200) = v2; +} + +void +test_vbool2_then_vbool2(int8_t * restrict in, int8_t * restrict out) { + vbool2_t v1 = *(vbool2_t*)in; + vbool2_t v2 = *(vbool2_t*)in; + + *(vbool2_t*)(out + 100) = v1; + *(vbool2_t*)(out + 200) = v2; +} + +void +test_vbool4_then_vbool4(int8_t * restrict in, int8_t * restrict out) { + vbool4_t v1 = *(vbool4_t*)in; + vbool4_t v2 = *(vbool4_t*)in; + + *(vbool4_t*)(out + 100) = v1; + *(vbool4_t*)(out + 200) = v2; +} + +void +test_vbool8_then_vbool8(int8_t * restrict in, int8_t * restrict out) { + vbool8_t v1 = *(vbool8_t*)in; + vbool8_t v2 = *(vbool8_t*)in; + + *(vbool8_t*)(out + 100) = v1; + *(vbool8_t*)(out + 200) = v2; +} + +void +test_vbool16_then_vbool16(int8_t * restrict in, int8_t * restrict out) { + vbool16_t v1 = *(vbool16_t*)in; + vbool16_t v2 = *(vbool16_t*)in; + + *(vbool16_t*)(out + 100) = v1; + *(vbool16_t*)(out + 200) = v2; +} + +void +test_vbool32_then_vbool32(int8_t * restrict in, int8_t * restrict out) { + vbool32_t v1 = *(vbool32_t*)in; + vbool32_t v2 = *(vbool32_t*)in; + + *(vbool32_t*)(out + 100) = v1; + *(vbool32_t*)(out + 200) = v2; +} + +void +test_vbool64_then_vbool64(int8_t * restrict in, int8_t * restrict out) { + vbool64_t v1 = *(vbool64_t*)in; + vbool64_t v2 = *(vbool64_t*)in; + + *(vbool64_t*)(out + 100) = v1; + *(vbool64_t*)(out + 200) = v2; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*m1,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf2,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf4,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x][0-9]+,\s*zero,\s*e8,\s*mf8,\s*ta,\s*ma} 1 } } */ +/* { dg-final { scan-assembler-times {vlm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 7 } } */ +/* { dg-final { scan-assembler-times {vsm\.v\s+v[0-9]+,\s*0\([a-x][0-9]+\)} 14 } } */ diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 028bedbc9a0..19fdba8cfa2 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-fold.h" #include "tree-eh.h" #include "gimplify.h" +#include "target.h" #include "flags.h" #include "dojump.h" #include "explow.h" @@ -5657,10 +5658,16 @@ visit_reference_op_load (tree lhs, tree op, gimple *stmt) if (result && !useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (op))) { + machine_mode result_mode = TYPE_MODE (TREE_TYPE (result)); + machine_mode op_mode = TYPE_MODE (TREE_TYPE (op)); + poly_uint16 result_mode_precision = GET_MODE_PRECISION (result_mode); + poly_uint16 op_mode_precision = GET_MODE_PRECISION (op_mode); + /* Avoid the type punning in case the result mode has padding where - the op we lookup has not. */ - if (maybe_lt (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (result))), - GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (op))))) + the op we lookup has not. + Avoid the type punning in case the target mode cannot be tied. */ + if (maybe_lt (result_mode_precision, op_mode_precision) + || !targetm.modes_tieable_p (result_mode, op_mode)) result = NULL_TREE; else {