🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #1030

Re: reassociation and undefined behaviour

#1030
From: Anton Ertl
Date: Wed, 02 Dec 2026 19:14
47 lines
3341 bytes
Thomas Koenig <tkoenig@netcologne.de> writes:
>Anton Ertl <anton@mips.complang.tuwien.ac.at> schrieb:
>> There are lots of cases where (a+b)+(c+d) is not the fastest way to
>> get the sum of a,b,c,d.  E.g., if a is available by an addition
>> latency (or more) after b, and c and d are available by two addition
>> latencies or more after a, then a+(b+(c+d)) is better.
>
>So this is something to be left to the phase where registers
>are allocated (as in the test case).

The register allocation does not have the latency information.  I am
not aware that any compiler does have this information as is relevant
for an OoO machine.  There are instruction scheduling phases, but they
are typically working at the basic block or at most superblock level,
and they are designed for in-order machines.  And the problem here
would be that for source code like

r=0;
for (size_t i=0; i<n; i+=stride)
  r += a[i];

we see a computation like this after unrolling.

r=r+a[i]+a[i+stride]

A naive view would assume that r has less latency than the two loads
from the array.  One would have to smarten this up to know that a
recurrence will often have a longer latency.  And then reassociation
might understand that it should compute this as

t=a[i]+a[i+stride]
r=r+t

And that's very special-casey.  In many cases such a reassociation
based on some variant of the data for instruction scheduling will have
trouble knowing enough about preceding basic blocks to understand
which values are probably available last.

Concerning register allocation, it may want to reassociate for lower
register pressure, which may or may not be in conflict with the
latency-reduction goal.  In the example above the latency-optimal
association results in more register pressure.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID: <2026Dec2.201455@mips.complang.tuwien.ac.at>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11cpqih$acf5$1@dont-email.me> <86o6b6kaqf.fsf@linuxsc.com> <11ejr5e$nk8$1@reader2.panix.com> <11ejtoe$eoj7$1@dont-email.me> <11el2c1$q43$1@reader2.panix.com> <11emcgn$1k681$1@dont-email.me> <11emvbp$1sc68$3@dont-email.me> <2026Dec2.084013@mips.complang.tuwien.ac.at> <11epogc$3cl08$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: reassociation and undefined behaviour
Date: Wed, 02 Dec 2026 19:14:55 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 47
Message-ID: <2026Dec2.201455@mips.complang.tuwien.ac.at>
References: <11cpqih$acf5$1@dont-email.me> <86o6b6kaqf.fsf@linuxsc.com> <11ejr5e$nk8$1@reader2.panix.com> <11ejtoe$eoj7$1@dont-email.me> <11el2c1$q43$1@reader2.panix.com> <11emcgn$1k681$1@dont-email.me> <11emvbp$1sc68$3@dont-email.me> <2026Dec2.084013@mips.complang.tuwien.ac.at> <11epogc$3cl08$1@dont-email.me>
Injection-Date: Wed, 02 Dec 2026 19:29:40 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3520296"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18bEJzHxdi3QvNKiic2ledi"; posting-host="9e58e1045521d54b1b4af042e3ed402f"
Cancel-Lock: sha1:4nSBM7MWojJUEv/eRI4HAGDlGlk= sha256:2dhhPpA2hmCybikCkQGAlcunfpYIoHa33GT3+gWXHrc=
	sha1:V3ocIOPcu0vPxG+0EjnflkUhlMc= sha256:Bnq+BnA61WuaNpvvZ2OHD4kaTEpQnPLvtyxZUZU9ctw=
X-newsreader: xrn 10.11