Article View: comp.arch
Article #896Re: vector length CSR?
From: Anton Ertl
Date: Sun, 22 Nov 2026 22:04
Date: Sun, 22 Nov 2026 22:04
64 lines
3317 bytes
3317 bytes
Michael S <already5chosen@yahoo.com> writes:
>On Sun, 22 Nov 2026 09:16:24 GMT
>anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
>> int foo(int a, int b, int c, int d)
>> {
>> int r=a;
>> r+=b;
>> r+=c;
>> r+=d;
>> return r;
>> }
...
>> [~/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.
And clang does not reassociate at all in this example. Do you have an
example (without vectorization) where it reassociates.
>BTW, gcc will happily vectorize very short summation loops, even as
>short as 4 integers, where vectorization almost certainly would be
>pessimizing.
Better measure that. Last year clang surprised me by vectorizing the
following loop:
#include <stddef.h>
void axpy1(float a, float *x, float *y,
float *z, float *w, float *v,
size_t n)
{
size_t i;
for (i=0; i<n; i++) {
z[i] += a*x[i];
w[i] = x[i]+y[i];
v[i] = x[i]*z[i];
}
}
v, w, and z are not restrict, so clang has to check first that they do
not overlap. Still vectorization was profitable for n=5 or so. When
the compiler is told that v, w, and z are restrict, the vectorized
variant was faster for even lower n (also for gcc).
- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID:
<2026Nov22.230435@mips.complang.tuwien.ac.at>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-mailReferences:
<11cpqih$acf5$1@dont-email.me> <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> <20261122215511.0000513f@yahoo.com>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: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.arch Subject: Re: vector length CSR? Date: Sun, 22 Nov 2026 22:04:35 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 64 Message-ID: <2026Nov22.230435@mips.complang.tuwien.ac.at> References: <11cpqih$acf5$1@dont-email.me> <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> <20261122215511.0000513f@yahoo.com> Injection-Date: Sun, 22 Nov 2026 22:21:17 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1423662"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lQs4mHDQMdaT4sYD//yYN"; posting-host="f30d6f48c39d6c9405387112f2d4bed3" Cancel-Lock: sha1:3Tut4p72glx715XweugqMtRUAT8= sha256:DRbECoG8eh65Ak04ULQLcoypN/mJvvR74WMkonvq76w= sha1:MMDWobbQ/mtHpHCWDrDyr/JqypA= sha256:Uab45zV8GI0YZ2fx4PM2eT7L7Tf8F+XCQSawBQ4znNQ= X-newsreader: xrn 10.11