public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Vineet Gupta <vineetg@rivosinc.com>, gcc@gcc.gnu.org
Cc: Kito Cheng <kito.cheng@sifive.com>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>
Subject: Re: Redundant constants in coremark crc8 for RISCV/aarch64 (no-if-conversion)
Date: Tue, 18 Oct 2022 21:42:25 -0600	[thread overview]
Message-ID: <8cbea421-5130-6d37-06a2-42ec7daef5cc@gmail.com> (raw)
In-Reply-To: <f97b82d4-305e-6e38-ffac-6c214ad310b4@rivosinc.com>


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.

Oh, cunroll.  There might be a distinct flag for complete unrolling.


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.

Some of Bodik's work might catch it as well, though implementing his 
ideas is likely a lot more work.


Jeff

  reply	other threads:[~2022-10-19  3:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 15:56 Vineet Gupta
2022-10-14 16:54 ` Jeff Law
2022-10-18 21:51   ` Vineet Gupta
2022-10-18 23:36     ` Jeff Law
2022-10-19  2:09       ` Vineet Gupta
2022-10-19  3:42         ` Jeff Law [this message]
2022-10-19  7:46           ` Richard Biener
2022-10-19 13:30             ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8cbea421-5130-6d37-06a2-42ec7daef5cc@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=kito.cheng@sifive.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=vineetg@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).