News for hackers. Stuff that matters.
Re:Incrementing vectors by BeeOnRope on Tuesday August 27, 2019 @11:29AM (#20810635)
> the compiler should be able to assume that a previous write cannot affect the next read from the size field, but it seems that neither GCC nor clang take advantage of it.

Why?

Good point about #pragma ivdep. I feel like the semantics of that one are a bit less than rigorous, but it's a useful tool.

Re:Incrementing vectors by gpderetta on Tuesday August 27, 2019 @11:33AM (#20810686)
Why they do not take advantage ov ivdep? I don't know. I thought it was because the size address was not a function of the iteration variable, but even by artificially adding the dependency (with a barebone vector implementation) does not seem to trigger the optimization.
Re:Incrementing vectors by BeeOnRope on Tuesday August 27, 2019 @11:40AM (#20810785)
I mean why "should [the compiler] be able to assume that a previous write cannot affect the next read from the size field"?

It's not that the size field is a function of the iteration variable (i?) but that the previous write may have overwritten the size field, because the size field is located at some arbitrary place in memory, and the array backing the vector is located at some other arbitrary place and they may overlap (but only because the vector type is uint8_t/char - if it other than a char type the compiler can be sure they don't overlap because the size() fields are pointers which have a distinct type from uint32_t and are not subject to the "char aliasing loophole" rule).

Re:Incrementing vectors by gpderetta on Tuesday August 27, 2019 @11:45AM (#20810865)
sure, but ivdep is supposed to explicitly tells the compiler that there are no loop carried dependencies between iterations, so iteration i-1 couldn't possibly write to a memory location read by iteration i.
Re:Incrementing vectors by BeeOnRope on Tuesday August 27, 2019 @11:48AM (#20810920)
Ah sorry, I read your ivdep sentence and the second part of your post as independent, i.e,. that the compiler should be able to assume this (even without ivdep).

I realize now you were saying "[With ivdep] and in this specific case, the compiler should be able to assume..."

It makes sense now.