public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Vineet Gupta <vineetg@rivosinc.com>
To: Jeff Law <jeffreyalaw@gmail.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 19:09:50 -0700	[thread overview]
Message-ID: <f97b82d4-305e-6e38-ffac-6c214ad310b4@rivosinc.com> (raw)
In-Reply-To: <53dcbef4-7aef-5f63-9bd8-e11c614b0be8@gmail.com>


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.

>
>>
>> FWIW -fno-unroll-loops only seems to work at -O2. At -O3 it always 
>> unrolls. Is that expected ?
>
> The only case I'm immediately aware of where this wouldn't work would 
> be if -O3 came after -fno-unroll-oops.

Weird that gcc-12, gcc-11, gcc-10 all seem to be silently ignoring 
-funroll-loops despite following -O3. Perhaps a different toggle is 
needed to supress the issue.

Thx,
-Vineet

  reply	other threads:[~2022-10-19  2:09 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 [this message]
2022-10-19  3:42         ` Jeff Law
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=f97b82d4-305e-6e38-ffac-6c214ad310b4@rivosinc.com \
    --to=vineetg@rivosinc.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=kito.cheng@sifive.com \
    --cc=philipp.tomsich@vrull.eu \
    /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).