From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by sourceware.org (Postfix) with ESMTPS id C0C3E3858C66 for ; Tue, 25 Jul 2023 06:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0C3E3858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690265272; x=1721801272; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=z5r5Y2cc94lNikFHTCBLUkrzvXjL+osPYanH1d1EGfQ=; b=HcySM6eSAy/61GBcbgc6rIExTDGzhCa8aKXmJglAinWlTs14Ov7JFwL2 tPDeTTS4b7qz/sDdOLLN8AYejPOc6ts1W+9jIIAvp38TAgxbkCwBe1UvS cXcsd6uAtrBtWPCAz6J27Oklpz6kcfRh9Z6yeBRfk486O89rBwoyNe6Wj cL+JICE2gvmpd69Vjw2V6j92B/SwwMPJm4IqCses3hpM8FhPn0wDp2w8o aMo725JxGoyIO+0DJDkVAdNalEXd8wreM29ZQ9/P2Og3k7ihfdrVw1Z8y GdqaZrfRTcosm7v9PS6RN4F+w0b6d7Vgg3Y8In597Vv47Eepy7dR26QjZ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="431427974" X-IronPort-AV: E=Sophos;i="6.01,229,1684825200"; d="scan'208";a="431427974" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 23:07:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="816131512" X-IronPort-AV: E=Sophos;i="6.01,229,1684825200"; d="scan'208";a="816131512" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by FMSMGA003.fm.intel.com with ESMTP; 24 Jul 2023 23:07:50 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 24 Jul 2023 23:07:49 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 24 Jul 2023 23:07:49 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Mon, 24 Jul 2023 23:07:49 -0700 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.168) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Mon, 24 Jul 2023 23:07:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ICTvMgWDenK90rv1EG83jHBHiLjhVleK9go+zpl+7+xs7ibmq2jdLgG5ozrne0sbWzMbQnrlEX+M1T6Wmy7UtNiotfVSvhNwUd/fWNqvEabfSMx3Jkx3dPU9T4K+eahNlzH08LlXIPM90YeK4bIU22olEKAsJqVOGq/eocUY6+4TM2M/I1xGPsAmNatyRIHRlr33YOE6CBGHo+O4shqQku5SGTXLqwfWa/Zi1r8W+FbsEIDugqr2RGTKnSI7wvWOkwEjHuiaSSFadEP7tELAlVyQ5xyAOARihnVCD8MfYcguGPJVML2yN2QUOyXENVX450VmuXq9q4kFs77SNj0e3A== 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=WWFQxzvYf88ZqyDOq49qlKuY2wfBumywAUoQcjOLm+k=; b=fOc21qlVFhzcRXiElXxqGiW/udSDiUDe0hfMTNwe1PpXKvudYHJZuTxh5DdX8qx6Qr6LRidGdCuUe5CPCa2DMBiYTJ5KzGv/BV7dqPVLAjsphw/92tdBWc6ijSVwGjq83HfjGkBmPNiJW4VOlCoCFIX1W6Lg4b6QCL+/9zsM92AZOxDbpraEo8JfnUDpIRxglv3G4VjE45+hJbOZVU8039se5eBLgM5USVFeSzi9igzZElptbssG+Kswq1Udyx61jM418TGoxVHVfWpxveApOBdzfUaUeww5RgEruKHhmGp4Jz7Fo2H5A/3J4poSUCQi9wyrOlyRXgvRdc25P8SGXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from SJ0PR11MB5919.namprd11.prod.outlook.com (2603:10b6:a03:42d::15) by PH7PR11MB5886.namprd11.prod.outlook.com (2603:10b6:510:135::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 06:07:45 +0000 Received: from SJ0PR11MB5919.namprd11.prod.outlook.com ([fe80::801d:8f14:834a:e3ec]) by SJ0PR11MB5919.namprd11.prod.outlook.com ([fe80::801d:8f14:834a:e3ec%5]) with mapi id 15.20.6609.032; Tue, 25 Jul 2023 06:07:45 +0000 From: "Li, Pan2" To: "gcc-patches@gcc.gnu.org" CC: "juzhe.zhong@rivai.ai" , "kito.cheng@sifive.com" , "Wang, Yanzhang" , "rdapp.gcc@gmail.com" Subject: RE: [PATCH v7] RISC-V: Support CALL for RVV floating-point dynamic rounding Thread-Topic: [PATCH v7] RISC-V: Support CALL for RVV floating-point dynamic rounding Thread-Index: AQHZvrwwRbdV6qtqXU+h6+NYPUOJSq/J+3vg Date: Tue, 25 Jul 2023 06:07:44 +0000 Message-ID: References: <20230719032822.85817-1-pan2.li@intel.com> <20230725055156.595718-1-pan2.li@intel.com> In-Reply-To: <20230725055156.595718-1-pan2.li@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SJ0PR11MB5919:EE_|PH7PR11MB5886:EE_ x-ms-office365-filtering-correlation-id: 435a797b-0e7c-47cc-cdf6-08db8cd576aa x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: F8EKO/+RY9aPsAh0i6uCm5nz5NENAL3fAnSM0SZ/aAO4zskijuMNpMACymcXIdRP1yaOfLqoR1xJfd0rmOVhaPNWTY7pkhF5cY2N6ij06MguX5XjoySpPTTsTuB4+ysUoG+/8iV1+rEGPQWqAXoYI0RMOtOwtCGVtN48sv+PPuiixODu8ga6MBaz84EPew/i3wCnzsJdaLV+SjXC+U+O55RFv9g+8YiUTlofML6NhDtDiFbWJ/+g8IU1u0GBQtkOPe9b+fyHDQV8HcfIRMV1Yzy01BqL1r34Kkc8CpYaof3Uk+grSNqhdq/3knY+zrxJ39Wb+21Q/Ajv6MOMe0iIJazTBW9pNCWw/IZ7IOcmZN26ShBRxi3DJoA3Dq6doXRPWzQqu4C7vrm9gMdwUXlPcuOYR28Ggn3e0dQBwqsBetB4PDHCG0aKRNNRe1J3k9mdymGVi2wPOclW10M2zIGfWjQXQ5RnkqAKagd4Y2HJ2cr2FXRZsClHol/WFeNBeD1NP1j0kQoBjdvg6CZrQ2mjwNLspWdmbGhQuQEDiNmEtjnd2waCaNVlmt09dg3v51u3/jAXctcwvZIHHQ9X7liiRkneQzmGK8GmocLqiRmJuLhwc2uDkd6AtL10qSGEf1nf x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR11MB5919.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(366004)(396003)(136003)(39860400002)(346002)(451199021)(82960400001)(478600001)(186003)(9686003)(84970400001)(53546011)(6506007)(26005)(122000001)(54906003)(71200400001)(4326008)(6916009)(66946007)(64756008)(66556008)(66476007)(76116006)(66446008)(83380400001)(7696005)(38100700002)(38070700005)(5660300002)(8676002)(8936002)(52536014)(2906002)(30864003)(41300700001)(316002)(55016003)(86362001)(33656002)(21314003)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?P7hFGFbShWCW0Ru0dSpN2glyZt/NVIDC8DnUbvGC0lCZI3/Ej3DNOIehPo1T?= =?us-ascii?Q?IzwoJHtpUrh5yUQt6MIGDYmI213txJ/j7e455BzA4jzAxbJASs3GqM/TU2uj?= =?us-ascii?Q?Q9uXqpFx2SevFK+VK7Usw7s9bpkps5FztaXKPe5Xb8jYL4IeN7iofYucBAwm?= =?us-ascii?Q?PKLy2XwRxBImSL6BE1DNPn38m0VxbSI4mCfWSP9ZOEUY+7WSt16bsNyzhj0D?= =?us-ascii?Q?m7X3b4QnspmLZAlYn9Ri6j25B1a4zw4ix0mCQoqM5cA0INqoKPfcfdk9aLqg?= =?us-ascii?Q?i1kt74e7gUHi/ueMvC0CBkjyrGeNiZVyIkzwIh8vPbpdg/J2CgPrlmUHTg3r?= =?us-ascii?Q?au89SfkUW0RLXhjk4kDsyd4spMWhfHDLY3m3EKvC9F2AP7UWHj5yf/VMwDC3?= =?us-ascii?Q?e3F7aZqS6cmHm89KzPD7UkdHtir6oH93zOFbWPDthPZayEEz5iyde/GJuF7N?= =?us-ascii?Q?TOHz20599LKci6tyBy3CQzUZQwqEu/o/G3dUCbgCmhX0LE75u1IJdJ+lt4E9?= =?us-ascii?Q?/MEd+/+XnuqflFfTBCtQsz+WYuSxHDX/LBKLR0vZZ/Fya/woyksiCmG/6VGq?= =?us-ascii?Q?SFla9SCVmK9GOo8hZFdOR8IQwATyygM5DpXTXpt+xXQOwEQR2T4k5p73mrGl?= =?us-ascii?Q?FJ0Qc+te/426GxIVsRxoIaYAsg2L1MOnq3bd9lo6bhpCzHTNdpYRJfKgSNBO?= =?us-ascii?Q?LgndyldXNdZHF/6l+dnmoerh5Ihj3nklfcsAwBxLzeUU45bdWVizp/JLruLP?= =?us-ascii?Q?8zMxIRlXQdQo4S26J8a645ZzlqK3fN1eXoqrNQfEvwj8+9T+RjASv1qJbsVI?= =?us-ascii?Q?MjQEO+7JZ3+9A5WV/ZdwteXkHoq9YXAjzGD3y8Zpq4C92lMLp7/5uPD0fRf1?= =?us-ascii?Q?6whWUOANeUxmRJpOclqbT0kRiu/off6GqlSj25NX2+8HtMdX7hUkex4F+DM/?= =?us-ascii?Q?tcI3xXyUBN5rs4lb2IioJnIEVlE2gnAXAp/Thrw867qqadUl0fQCf/TRW5cX?= =?us-ascii?Q?mPBVlcY7b2+BTe5E6hCyFiM7defgO/nc8X4gP7gn6wqhdyGfOykta3udLa8z?= =?us-ascii?Q?Q8jUVjB+0CHsB7PVwwN1hPoyR9vF3lCf6QRReT9EIipZDMCsOY2MPq9fiWZE?= =?us-ascii?Q?jJPDDXUbDIED6qBIvR5+GfKgvIKNIUeNjdM1VgvCH60YADurVtyPwU7+3/sE?= =?us-ascii?Q?4QR1lvWMqEjwAPHBrcIFmVzWEIVmnw9rfTZ2ylwVyrUC04qRPEUUw1yjhdbk?= =?us-ascii?Q?yPAedP0TsYy89ldbfeRXIn1sVX0S6I6HSeex2ZZ1XNzxbGxaCKaz4tZHL1Kt?= =?us-ascii?Q?ig6csNn+IwjjChesYXPlmmjIna2i/TJwdK7nKiWb7XBM9SEHQmMSSAh2vgzI?= =?us-ascii?Q?n/0Wd+mmSFp1QmV72gqomfoHEXK3R2nrKAF8Yuw6FbEKxZoF7nj9E3OP5Bi0?= =?us-ascii?Q?uGD7ubH0UQdJBTV3pYtUS7tmJUTJbhlYQFBHp3kf3fGsGQ0QDSPa3yVuN4Bb?= =?us-ascii?Q?xf2/DrrONAdIvj3MRFOP5WW/mnjAcHwnpa+HIQUZGx6Q1O9Szw5chsaniS3a?= =?us-ascii?Q?wz5+DL8alqy/ggFYJf4=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR11MB5919.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 435a797b-0e7c-47cc-cdf6-08db8cd576aa X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jul 2023 06:07:44.9485 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: zZWjxIXbuf3qbnRU3gaKBaLAgBR3X2aMGcuW5kJZVtDfv6459nnqoky4hMQwO51CgZXrv4Bso+QlNJ4yT7Ebfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB5886 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Robin, Given we have a call, we would like to restore before call and then backup = frm after call.=20 Looks current mode switching cannot emit insn like that, it can only either= emit insn before (mostly) or after (when NOTE_INSN_BASIC_BLOCK_P). Thus, we try to emit the one after call when needed as a specially handling= here. To take care of it elegantly, I may suggest we can have one optional mode s= witch HOOK like TARGET_MODE_EMIT_AFTER, which will emit the backup/restore after insn besides TARGET_MODE_EMIT. I may prefer to hav= e a try later in another PATCH(es) in the middle-end. Pan -----Original Message----- From: Li, Pan2 =20 Sent: Tuesday, July 25, 2023 1:52 PM To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai; kito.cheng@sifive.com; Li, Pan2 ; Wang, Yanzhang ; rdapp.gcc@gmail.com Subject: [PATCH v7] RISC-V: Support CALL for RVV floating-point dynamic rou= nding From: Pan Li Update in PATCH v7: 1. Take previous/next_nonnote_nondebug_insn_bb for seeking the insn. 2. Splitting the function in detection and emit when needed. Original commit logs: In basic dynamic rounding mode, we simply ignore call instructions and we would like to take care of call in this PATCH. During the call, the frm may be updated or keep as is. Thus, we must make sure at least 2 things. 1. The static frm before call should not pollute the frm value in call. 2. The updated frm value in call should be sticky after call completed. We will perfrom some steps to make above happen. 1. Mark call instruction with new mode DYN_CALL. 2. Mark the instruction after CALL from NONE to DYN. 3. When emit for a DYN_CALL, we will restore the frm value. 4. When emit from a DYN_CALL, we will backup the frm value. Let's take a flow for this. +-------------+ | Entry (DYN) | <- frrm a5 +-------------+ / \ +-------+ +-----------+ | VFADD | | VFADD RTZ | <- fsrmi 1(RTZ) +-------+ +-----------+ | | +-------+ +-----------+ | CALL | | CALL | <- fsrm a5 +-------+ +-----------+ | | +-----------+ +-------+ | SHIFT | <- frrm a5 | VFADD | <- frrm a5 +-----------+ +-------+ | / +-----------+ / | VFADD RUP | <- fsrm1 3(RUP) +-----------+ / \ / +-----------------+ | Exit (DYN_EXIT) | <- fsrm a5 +-----------------+ When call is the last insn of one bb, we take care of it when needed for each insn by inserting one frm backup (frrm) insn to the end of the current bb. Signed-off-by: Pan Li Co-Authored-By: Juzhe-Zhong gcc/ChangeLog: * config/riscv/riscv.cc (DYNAMIC_FRM_RTL): New macro. (STATIC_FRM_P): Ditto. (struct mode_switching_info): New struct for mode switching. (struct machine_function): Add new field mode switching. (riscv_emit_frm_mode_set): Add DYN_CALL emit. (riscv_frm_adjust_mode_after_call): New function for call mode. (riscv_frm_emit_after_call_in_bb_end): New function for emit insn when call as the end of bb. (riscv_frm_mode_needed): New function for frm mode needed. (riscv_mode_needed): Extrac function for frm. (riscv_frm_mode_after): Add DYN_CALL after. (riscv_mode_entry): Remove backup rtl initialization. * config/riscv/vector.md (frm_mode): Add dyn_call. (fsrmsi_restore_exit): Rename to _volatile. (fsrmsi_restore_volatile): Likewise. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/float-point-frm-insert-7.c: Adjust test cases. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-33.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-34.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-35.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-36.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-37.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-38.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-39.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-40.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-41.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-42.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-43.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-44.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-45.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-46.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-47.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-48.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-49.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-50.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-51.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-52.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-53.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-54.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-55.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-56.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-57.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-58.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-59.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-60.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-61.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-62.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-63.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-64.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-65.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-66.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-67.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-68.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-69.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-70.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-71.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-72.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-73.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-74.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-75.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-76.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-77.c: New test. * gcc.target/riscv/rvv/base/float-point-frm-run-4.c: New test. * gcc.target/riscv/rvv/base/float-point-frm-run-5.c: New test. --- gcc/config/riscv/riscv.cc | 130 ++++++++++++++++-- gcc/config/riscv/vector.md | 4 +- .../rvv/base/float-point-dynamic-frm-33.c | 31 +++++ .../rvv/base/float-point-dynamic-frm-34.c | 32 +++++ .../rvv/base/float-point-dynamic-frm-35.c | 32 +++++ .../rvv/base/float-point-dynamic-frm-36.c | 29 ++++ .../rvv/base/float-point-dynamic-frm-37.c | 36 +++++ .../rvv/base/float-point-dynamic-frm-38.c | 34 +++++ .../rvv/base/float-point-dynamic-frm-39.c | 36 +++++ .../rvv/base/float-point-dynamic-frm-40.c | 34 +++++ .../rvv/base/float-point-dynamic-frm-41.c | 37 +++++ .../rvv/base/float-point-dynamic-frm-42.c | 37 +++++ .../rvv/base/float-point-dynamic-frm-43.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-44.c | 40 ++++++ .../rvv/base/float-point-dynamic-frm-45.c | 35 +++++ .../rvv/base/float-point-dynamic-frm-46.c | 35 +++++ .../rvv/base/float-point-dynamic-frm-47.c | 36 +++++ .../rvv/base/float-point-dynamic-frm-48.c | 36 +++++ .../rvv/base/float-point-dynamic-frm-49.c | 36 +++++ .../rvv/base/float-point-dynamic-frm-50.c | 36 +++++ .../rvv/base/float-point-dynamic-frm-51.c | 36 +++++ .../rvv/base/float-point-dynamic-frm-52.c | 36 +++++ .../rvv/base/float-point-dynamic-frm-53.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-54.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-55.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-56.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-57.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-58.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-59.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-60.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-61.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-62.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-63.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-64.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-65.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-66.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-67.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-68.c | 38 +++++ .../rvv/base/float-point-dynamic-frm-69.c | 31 +++++ .../rvv/base/float-point-dynamic-frm-70.c | 28 ++++ .../rvv/base/float-point-dynamic-frm-71.c | 28 ++++ .../rvv/base/float-point-dynamic-frm-72.c | 33 +++++ .../rvv/base/float-point-dynamic-frm-73.c | 39 ++++++ .../rvv/base/float-point-dynamic-frm-74.c | 39 ++++++ .../rvv/base/float-point-dynamic-frm-75.c | 39 ++++++ .../rvv/base/float-point-dynamic-frm-76.c | 39 ++++++ .../rvv/base/float-point-dynamic-frm-77.c | 20 +++ .../riscv/rvv/base/float-point-frm-insert-7.c | 5 +- .../riscv/rvv/base/float-point-frm-run-4.c | 82 +++++++++++ .../riscv/rvv/base/float-point-frm-run-5.c | 83 +++++++++++ 50 files changed, 1892 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-33.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-34.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-35.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-36.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-37.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-38.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-39.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-40.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-41.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-42.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-43.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-44.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-45.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-46.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-47.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-48.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-49.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-50.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-51.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-52.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-53.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-54.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-55.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-56.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-57.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-58.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-59.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-60.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-61.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-62.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-63.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-64.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-65.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-66.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-67.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-68.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-69.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-70.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-71.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-72.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-73.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-74.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-75.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-76.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyn= amic-frm-77.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm= -run-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm= -run-5.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 332fa720f01..7d2d4252e5c 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -69,6 +69,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-iterator.h" #include "gimple-expr.h" #include "tree-vectorizer.h" +#include "gcse.h" =20 /* This file should be included last. */ #include "target-def.h" @@ -90,6 +91,12 @@ along with GCC; see the file COPYING3. If not see /* True if bit BIT is set in VALUE. */ #define BITSET_P(VALUE, BIT) (((VALUE) & (1ULL << (BIT))) !=3D 0) =20 +/* Extract the backup dynamic frm rtl. */ +#define DYNAMIC_FRM_RTL(c) ((c)->machine->mode_sw_info.dynamic_frm) + +/* True the mode switching has static frm, or false. */ +#define STATIC_FRM_P(c) ((c)->machine->mode_sw_info.static_frm_p) + /* Information about a function's frame layout. */ struct GTY(()) riscv_frame_info { /* The size of the frame in bytes. */ @@ -125,6 +132,22 @@ enum riscv_privilege_levels { UNKNOWN_MODE, USER_MODE, SUPERVISOR_MODE, MACHINE_MODE }; =20 +struct GTY(()) mode_switching_info { + /* The RTL variable which stores the dynamic FRM value. We always use t= his + RTX to restore dynamic FRM rounding mode in mode switching. */ + rtx dynamic_frm; + + /* The boolean variables indicates there is at least one static rounding + mode instruction in the function or not. */ + bool static_frm_p; + + mode_switching_info () + { + dynamic_frm =3D NULL_RTX; + static_frm_p =3D false; + } +}; + struct GTY(()) machine_function { /* The number of extra stack bytes taken up by register varargs. This area is allocated by the callee at the very top of the frame. *= / @@ -148,9 +171,8 @@ struct GTY(()) machine_function { not be considered by the prologue and epilogue. */ bool reg_is_wrapped_separately[FIRST_PSEUDO_REGISTER]; =20 - /* The RTL variable which stores the dynamic FRM value. We always use t= his - RTX to restore dynamic FRM rounding mode in mode switching. */ - rtx dynamic_frm; + /* The mode swithching information for the FRM rounding modes. */ + struct mode_switching_info mode_sw_info; }; =20 /* Information about a single argument. */ @@ -7709,9 +7731,13 @@ riscv_static_frm_mode_p (int mode) static void riscv_emit_frm_mode_set (int mode, int prev_mode) { + rtx backup_reg =3D DYNAMIC_FRM_RTL (cfun); + + if (prev_mode =3D=3D FRM_MODE_DYN_CALL) + emit_insn (gen_frrmsi (backup_reg)); /* Backup frm when DYN_CALL. */ + if (mode !=3D prev_mode) { - rtx backup_reg =3D cfun->machine->dynamic_frm; /* TODO: By design, FRM_MODE_xxx used by mode switch which is different from the FRM value like FRM_RTZ defined in riscv-protos.h. When mode switching we actually need a conversion @@ -7721,10 +7747,14 @@ riscv_emit_frm_mode_set (int mode, int prev_mode) and then we leverage this assumption when emit. */ rtx frm =3D gen_int_mode (mode, SImode); =20 - if (mode =3D=3D FRM_MODE_DYN_EXIT && prev_mode !=3D FRM_MODE_DYN) + if (mode =3D=3D FRM_MODE_DYN_CALL && prev_mode !=3D FRM_MODE_DYN) /* No need to emit when prev mode is DYN already. */ - emit_insn (gen_fsrmsi_restore_exit (backup_reg)); - else if (mode =3D=3D FRM_MODE_DYN) + emit_insn (gen_fsrmsi_restore_volatile (backup_reg)); + else if (mode =3D=3D FRM_MODE_DYN_EXIT && STATIC_FRM_P (cfun) + && prev_mode !=3D FRM_MODE_DYN && prev_mode !=3D FRM_MODE_DYN_CALL) + /* No need to emit when prev mode is DYN or DYN_CALL already. */ + emit_insn (gen_fsrmsi_restore_volatile (backup_reg)); + else if (mode =3D=3D FRM_MODE_DYN && prev_mode !=3D FRM_MODE_DYN_CAL= L) /* Restore frm value from backup when switch to DYN mode. */ emit_insn (gen_fsrmsi_restore (backup_reg)); else if (riscv_static_frm_mode_p (mode)) @@ -7753,6 +7783,79 @@ riscv_emit_mode_set (int entity, int mode, int prev_= mode, } } =20 +/* Adjust the FRM_MODE_NONE insn after a call to FRM_MODE_DYN for the + underlying emit. */ + +static int +riscv_frm_adjust_mode_after_call (rtx_insn *cur_insn, int mode) +{ + basic_block bb =3D BLOCK_FOR_INSN (cur_insn); + rtx_insn *insn =3D prev_nonnote_nondebug_insn_bb (cur_insn); + + if (insn && CALL_P (insn)) + return FRM_MODE_DYN; + + return mode; +} + +/* Insert the backup frm insn to the end of the bb if and only if the call + is the last insn of this bb. */ + +static void +riscv_frm_emit_after_call_in_bb_end (rtx_insn *cur_insn) +{ + basic_block bb =3D BLOCK_FOR_INSN (cur_insn); + + start_sequence (); + emit_insn (gen_frrmsi (DYNAMIC_FRM_RTL (cfun))); + rtx_insn *backup_insn =3D get_insns (); + end_sequence (); + + insert_insn_end_basic_block (backup_insn, bb); +} + +/* Return mode that frm must be switched into + prior to the execution of insn. */ + +static int +riscv_frm_mode_needed (rtx_insn *cur_insn, int code) +{ + if (!DYNAMIC_FRM_RTL(cfun)) + { + /* The dynamic frm will be initialized only onece during cfun. */ + DYNAMIC_FRM_RTL (cfun) =3D gen_reg_rtx (SImode); + emit_insn_at_entry (gen_frrmsi (DYNAMIC_FRM_RTL (cfun))); + } + + if (CALL_P (cur_insn)) + { + rtx_insn *insn =3D next_nonnote_nondebug_insn_bb (cur_insn); + + if (!insn) + riscv_frm_emit_after_call_in_bb_end (cur_insn); + + return FRM_MODE_DYN_CALL; + } + + int mode =3D code >=3D 0 ? get_attr_frm_mode (cur_insn) : FRM_MODE_NONE; + + if (mode =3D=3D FRM_MODE_NONE) + /* After meet a call, we need to backup the frm because it may be + updated during the call. Here, for each insn, we will check if + the previous insn is a call or not. When previous insn is call, + there will be 2 cases for the emit mode set. + + 1. Current insn is not MODE_NONE, then the mode switch framework + will do the mode switch from MODE_CALL to MODE_NON_NONE natively. + 2. Current insn is MODE_NONE, we need to adjust the MODE_NONE to + the MODE_DYN, and leave the mode switch itself to perform + the emit mode set. + */ + mode =3D riscv_frm_adjust_mode_after_call (cur_insn, mode); + + return mode; +} + /* Return mode that entity must be switched into prior to the execution of insn. */ =20 @@ -7766,7 +7869,7 @@ riscv_mode_needed (int entity, rtx_insn *insn) case RISCV_VXRM: return code >=3D 0 ? get_attr_vxrm_mode (insn) : VXRM_MODE_NONE; case RISCV_FRM: - return code >=3D 0 ? get_attr_frm_mode (insn) : FRM_MODE_NONE; + return riscv_frm_mode_needed (insn, code); default: gcc_unreachable (); } @@ -7843,6 +7946,11 @@ riscv_vxrm_mode_after (rtx_insn *insn, int mode) static int riscv_frm_mode_after (rtx_insn *insn, int mode) { + STATIC_FRM_P (cfun) =3D STATIC_FRM_P (cfun) || riscv_static_frm_mode_p (= mode); + + if (CALL_P (insn)) + return FRM_MODE_DYN_CALL; + if (frm_unknown_dynamic_p (insn)) return FRM_MODE_DYN; =20 @@ -7883,12 +7991,6 @@ riscv_mode_entry (int entity) return VXRM_MODE_NONE; case RISCV_FRM: { - if (!cfun->machine->dynamic_frm) - { - cfun->machine->dynamic_frm =3D gen_reg_rtx (SImode); - emit_insn_at_entry (gen_frrmsi (cfun->machine->dynamic_frm)); - } - /* According to RVV 1.0 spec, all vector floating-point operations use the dynamic rounding mode in the frm register. Likewise in other similar places. */ diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index f745888127c..05fd7600ba4 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -686,7 +686,7 @@ (define_attr "vxrm_mode" "rnu,rne,rdn,rod,none" (const_string "none"))) =20 ;; Defines rounding mode of an floating-point operation. -(define_attr "frm_mode" "rne,rtz,rdn,rup,rmm,dyn,dyn_exit,none" +(define_attr "frm_mode" "rne,rtz,rdn,rup,rmm,dyn,dyn_exit,dyn_call,none" (cond [(eq_attr "type" "vfalu") (cond [(match_test "INTVAL (operands[9]) =3D=3D riscv_vector::FRM_RNE") @@ -813,7 +813,7 @@ (define_insn "fsrmsi_restore" ;; The volatile fsrmsi restore is used for the exit point for the ;; dynamic mode switching. It will generate one volatile fsrm a5 ;; which won't be eliminated. -(define_insn "fsrmsi_restore_exit" +(define_insn "fsrmsi_restore_volatile" [(set (reg:SI FRM_REGNUM) (unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")] UNSPECV_FRM_RESTORE_EXIT))]