🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #894

Re: vector length CSR?

#894
From: Michael S
Date: Sun, 22 Nov 2026 19:55
118 lines
5183 bytes
On Sun, 22 Nov 2026 09:16:24 GMT
anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

> Thomas Koenig <tkoenig@netcologne.de> writes:
> >gcc treats wrapping and non-wrapping differently.  Here's a function
> >from gcc/tree-ssa-reassoc.cc:
> >
> >/* Returns true if we can reassociate operations of TYPE.
> >   That is for integral or non-saturating fixed-point types, and for
> >   floating point type when associative-math is enabled.  */
> >
> >static bool
> >can_reassociate_type_p (tree type)
> >{
> >  if ((ANY_INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type))
> >      || NON_SAT_FIXED_POINT_TYPE_P (type)
> >      || (flag_associative_math && FLOAT_TYPE_P (type)))
> >    return true;
> >  return false;
> >}
> >
> >Reassociation is possible with -frwapv, not possible with
> >normal semantics.  
> 
> Let's see how well it works (gcc-12):
> 
> [~/tmp:173584] cat reassoc.c
> int foo(int a, int b, int c, int d)
> {
>   int r=a;
>   r+=b;
>   r+=c;
>   r+=d;
>   return r;
> }
> [~/tmp:173585] gcc -O3 -c reassoc.c && objdump -d reassoc.o
> 
> reassoc.o:     file format elf64-x86-64
> 
> 
> Disassembly of section .text:
> 
> 0000000000000000 <foo>:
>    0:   01 f7                   add    %esi,%edi
>    2:   01 d7                   add    %edx,%edi
>    4:   8d 04 0f                lea    (%rdi,%rcx,1),%eax
>    7:   c3                      ret
> [~/tmp:173586] gcc -fwrapv -O3 -c reassoc.c && objdump -d reassoc.o
> 
> reassoc.o:     file format elf64-x86-64
> 
> 
> Disassembly of section .text:
> 
> 0000000000000000 <foo>:
>    0:   01 ca                   add    %ecx,%edx
>    2:   01 f2                   add    %esi,%edx
>    4:   8d 04 3a                lea    (%rdx,%rdi,1),%eax
>    7:   c3                      ret
> 
> So gcc by default does not reassociate, and in the -fwrapv case
> reassociates, but does so in a way that does not reduce the tree
> height, but that corresponds to
> 
> c+=d;
> c+=b;
> return c+a;
> 
> What's the reason for that?  "Relevant" programs where the earlier
> parameters are on the critical path and the later ones are not?
> 
> Let's see how clang-14 does:
> 
> [~/tmp:173587] clang -O3 -c reassoc.c && objdump -d reassoc.o
> 
> reassoc.o:     file format elf64-x86-64
> 
> 
> Disassembly of section .text:
> 
> 0000000000000000 <foo>:
>    0:   8d 04 37                lea    (%rdi,%rsi,1),%eax
>    3:   01 d0                   add    %edx,%eax
>    5:   01 c8                   add    %ecx,%eax
>    7:   c3                      ret
> [~/tmp:173588] clang -fwrapv -O3 -c reassoc.c && objdump -d reassoc.o
> 
> reassoc.o:     file format elf64-x86-64
> 
> 
> Disassembly of section .text:
> 
> 0000000000000000 <foo>:
>    0:   8d 04 37                lea    (%rdi,%rsi,1),%eax
>    3:   01 d0                   add    %edx,%eax
>    5:   01 c8                   add    %ecx,%eax
>    7:   c3                      ret
> 
> No reassociation with either flag.
> 
> - anton

Unlike clang, gcc performs no useful re-association for "open" code.
The uselessness is independent, of presence/absence of -fwrapv
flags. More so, it is independent of signed vs unsigned.

gcc does re-associate in useful manner when vecorizing loops.
Again, it performs it independently of -fwrapv or from signness.

See examples in my post below.

BTW, gcc will happily vectorize very short summation loops, even as
short as 4 integers, where vectorization almost certainly would be
pessimizing.



Technical Details
Message-ID: <20261122215511.0000513f@yahoo.com>
Path: mbox-mo1.pugleaf.net!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> <11csull$1ef6e$1@dont-email.me> <2026Nov9.230104@mips.complang.tuwien.ac.at> <11cvcr4$28k7g$1@dont-email.me> <11d3npt$3mmho$1@dont-email.me> <11dn936$2ebc2$1@dont-email.me> <11dndfd$2fr9j$1@dont-email.me> <11dngb5$2he51$1@dont-email.me> <2026Nov19.203832@mips.complang.tuwien.ac.at> <11dq56a$3f094$1@dont-email.me> <11ds0io$12f8$1@dont-email.me> <11ds88c$46jd$1@dont-email.me> <11ds95m$4co4$1@dont-email.me> <11dsbag$5a43$1@dont-email.me> <2026Nov22.101624@mips.complang.tuwien.ac.at>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Michael S <already5chosen@yahoo.com>
Newsgroups: comp.arch
Subject: Re: vector length CSR?
Date: Sun, 22 Nov 2026 21:55:11 +0200
Organization: A noiseless patient Spider
Lines: 118
Message-ID: <20261122215511.0000513f@yahoo.com>
References: <11cpqih$acf5$1@dont-email.me>
	<11csull$1ef6e$1@dont-email.me>
	<2026Nov9.230104@mips.complang.tuwien.ac.at>
	<11cvcr4$28k7g$1@dont-email.me>
	<11d3npt$3mmho$1@dont-email.me>
	<11dn936$2ebc2$1@dont-email.me>
	<11dndfd$2fr9j$1@dont-email.me>
	<11dngb5$2he51$1@dont-email.me>
	<2026Nov19.203832@mips.complang.tuwien.ac.at>
	<11dq56a$3f094$1@dont-email.me>
	<11ds0io$12f8$1@dont-email.me>
	<11ds88c$46jd$1@dont-email.me>
	<11ds95m$4co4$1@dont-email.me>
	<11dsbag$5a43$1@dont-email.me>
	<2026Nov22.101624@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 22 Nov 2026 19:55:12 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1313530"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+ISOTC56aootDJbNvrOcWTBbeCC5jraQc="; posting-host="8ed8fb11f8730b45d16f936e8720ca13"
Cancel-Lock: sha1:kKvSvAYLzxUWq8SOEb26tMB46vY= sha256:zjiBioBwY2lPYRcOvt+YoIr/2KIDQyn6hv8qtC9lTOU=
	sha1:WBDLDGDuUAkLkXikwYTUdvQHkbE= sha256:PjBmTqw/k7M9N1AOxv41dtmx7XJmRpFxmAcCXO7HQnQ=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)