From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 882C33858D3C for ; Wed, 19 Oct 2022 07:46:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 882C33858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x630.google.com with SMTP id a26so37577428ejc.4 for ; Wed, 19 Oct 2022 00:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=umzzyKg88b+0co5Us+Jq6afEtvH1PgD4UhXpk4F31hE=; b=iJWwDOmrfBQj0HQKt+A4U8T5x6QtGqf3PC4WcLkeM2IQYcOC4NqoK1VWovLTcJzmsV nuJKvmeP9jCF00XNTtM1EcCUkp9DKYIEjMMRMLW4dppgRY+YVAIhhOCN/iHdIokgC2LO 2Dyr6GzJgux76SlK5glDEFefV+OBa7hhOC7aokREqQfQqgVUiU7UV8sOxcf/9yH9Atp9 1VFGmBDLdCm6uIb3hmYZBhY/78wO9+pMzAJTHXCB9fhNMpcfjEvtSIvNzhqI6+Wepx48 RVI7fZCWzCiWioksoOvR1xoOhpDGZjPIiWRnwzlml3bYjdzGyNSHDwc38EMIpW+MRatS nu6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=umzzyKg88b+0co5Us+Jq6afEtvH1PgD4UhXpk4F31hE=; b=6foNkfxJ5uzz8ODg1ifrrVXJj+sGnJX0JMY3ViV5nuQAoGUg4P+wtJ/3oF9HwCLk4E eVWDSFUEo0v3kew+HHye4lssM4sP9fOhYGa/P5G6nTCJ0LTCc5hoF4eCZ3++TrPbpsdP TcfOggiVrsnoODBAOmjuh2q6WnNYYdY3ziQFdc1sG9ra+4kt/0eMveHmSuNRVmUPUrLV tNWsD7eiXoqeM6saI9WTGjkY4wFh/X2Edc2M8SI69OTkbX5SxUV2EdLwoOsUBohQWtKh ePCSuipcNIHEUVbFyYbBAtjgu18drabJ3qv9PsFhO3EHvrukO27Mfw6Z3ddUrJDx6OHF QNbw== X-Gm-Message-State: ACrzQf1CZbIBvcBOYRDrti9iORQRZlfEvfSfu+8PVBdQ3KV0i4FNFo+0 pZFYAnHrg0q68zQO8Jx3r2DNglbH/R3pulDdYbA= X-Google-Smtp-Source: AMsMyM5ZpT2qm+IWx+KlrBEfjucstjanntzh7e8MHoE0rGuJ4nYhm3aPffWlrA//xLzhRaD7pcarakNuRPXAq5xTtIM= X-Received: by 2002:a17:907:6d08:b0:78e:e87:5c06 with SMTP id sa8-20020a1709076d0800b0078e0e875c06mr5425128ejc.511.1666165614234; Wed, 19 Oct 2022 00:46:54 -0700 (PDT) MIME-Version: 1.0 References: <1a636f1e-31be-1735-5d8f-649df3c5e018@gmail.com> <1e118c0c-5d9a-4fca-9fe9-12e2baa34019@rivosinc.com> <53dcbef4-7aef-5f63-9bd8-e11c614b0be8@gmail.com> <8cbea421-5130-6d37-06a2-42ec7daef5cc@gmail.com> In-Reply-To: <8cbea421-5130-6d37-06a2-42ec7daef5cc@gmail.com> From: Richard Biener Date: Wed, 19 Oct 2022 09:46:41 +0200 Message-ID: Subject: Re: Redundant constants in coremark crc8 for RISCV/aarch64 (no-if-conversion) To: Jeff Law Cc: Vineet Gupta , gcc@gcc.gnu.org, Kito Cheng , Philipp Tomsich Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 List-Id: On Wed, Oct 19, 2022 at 5:44 AM Jeff Law via Gcc wrote: > > > On 10/18/22 20:09, Vineet Gupta wrote: > > > > On 10/18/22 16:36, Jeff Law wrote: > >>>> There isn't a great place in GCC to handle this right now. If the > >>>> constraints were relaxed in PRE, then we'd have a chance, but > >>>> getting the cost model right is going to be tough. > >>> > >>> It would have been better (for this specific case) if loop unrolling > >>> was not being done so early. The tree pass cunroll is flattening it > >>> out and leaving for rest of the all tree/rtl passes to pick up the > >>> pieces and remove any redundancies, if at all. It obviously needs to > >>> be early if we are injecting 7x more instructions, but seems like a > >>> lot to unravel. > >> > >> Yup. If that loop gets unrolled, it's going to be a mess. It will > >> almost certainly make this problem worse as each iteration is going > >> to have a pair of constants loaded and no good way to remove them. > > > > Thats the original problem that I started this thread with. I'd > > snipped the disassembly as it would have been too much text but > > basically on RV, Coremark crc8 loop of const 8 iterations gets > > unrolled including extraneous 8 insns pairs to load the same constant > > - which is preposterous. Other arches side-step by using if-conversion > > / cond moves, latter currently WIP in RV International. x86 w/o > > if-convert seems OK since the const can be encoded in the xor insn. > > > > OTOH given that gimple/tree-pass cunroll is doing the culprit loop > > unrolling and introducing redundant const 8 times, can it ne addressed > > there somehow. > > tree_estimate_loop_size() seems to identify constant expression, not > > just an operand. Can it be taught to identify a "non-trivial const" > > and hoist/code-move the expression. Sorry just rambling here, most > > likely non-sense. On GIMPLE all constants are "simple". > Oh, cunroll. There might be a distinct flag for complete unrolling. At -O3 we peel completely, there's no flag to disable that. > I really expect something like Click's work is the way forward. > Essentially when you VN the function you'll identify those constants and > collapse them all down to a single instance. Then the GCM phase will > kick in and find a place to put the evaluation so that you have one and > only one. I'd say postreload gcse would be a place to do that. At least when there's no available hardreg CSEing likely isn't going to be a win. > Some of Bodik's work might catch it as well, though implementing his > ideas is likely a lot more work. > > > Jeff