News for hackers. Stuff that matters.
Re:Firefox 64 built with GCC and Clang by MaxBarraclough on Sunday December 16, 2018 @09:50AM (#18693250)
If it affects cache behaviour, we should all care.
Re:Firefox 64 built with GCC and Clang by DannyBee on Sunday December 16, 2018 @11:30AM (#18693731)
Whether that is true or not depends on a lot of factors.

They are mostly unrelated to overall binary size due to paging, etc.

You also won't easily predict the behavior due to reordering.

Re:Firefox 64 built with GCC and Clang by MaxBarraclough on Monday December 17, 2018 @07:19AM (#18698488)
Smaller binary enables use of a lower-level cache, no? [0]

My understanding is that profile-guided optimisation is largely based on the utility of small binaries, by optimising hotspots for speed and everything else for space, thereby alleviating cache-pressure. Is this wrong?

> You also won't easily predict the behavior due to reordering.

I wasn't thinking of anything as sophisticated as looking at specific flows, where I can well imagine things get unpredictable with reordering and speculative execution. Won't there will be a reliable pattern of better fitting in cache, if we shrink everything?

[0] https://lwn.net/Articles/534735/

Re:Firefox 64 built with GCC and Clang by DannyBee on Monday December 17, 2018 @11:48PM (#18704591)
"Smaller binary enables use of a lower-level cache, no? [0]" No. It would if all of the stuff was actually all in memory at once, and pulled in the stuff next to it.

IE you couldn't pull in function A without pulling in function B. That is mostly not true[1].

This is why reordering mostly brings load time benefits instead of run time benefits.

The utility of PGO is mostly about knowing where to spend your time optimizing, and knowing what to do. That's a generalization. There are certainly cases in inline/etc heavy code where it helps get the speed part right too. A lot of that is more often about "it lets the compiler spend it's inlining budget on inlining stuff that matters" than "it stops the compiler from blowing cache out".

I speak in generalities because there are always counterexamples.

There are cases where PGO makes things significantly worse, for example!

Last I remember (My job now means i don't have time to stay in the game), LLVM did not bother to optimize the cold regions for size, and GCC did.

[1] It depends on function sizes and page sizes and mlocking and section flags and all sorts of fun things, but i'm just going to assert the truth of this in most cases go make it simpler.

Re:Firefox 64 built with GCC and Clang by mhh__ on Sunday December 16, 2018 @09:59AM (#18693292)
I guess that LLVM is fairly cache aware so I think the performance probably isn't affected too greatly (I hope).
Re:Firefox 64 built with GCC and Clang by hubicka on Sunday December 16, 2018 @11:08AM (#18693632)
I would be interested to know what cache aware code layout optimizations are available in LLVM. I personally know of none. GCC is bit simplistic in this sense (it does reorder functions based on profile feedback and execution time) and I plan to change that for next stage 1 (i.e. GCC 10)
Re:Firefox 64 built with GCC and Clang by DannyBee on Sunday December 16, 2018 @11:28AM (#18693716)
Hey Jan, Long time ;)

LLVM will do the same kind of reordering.

(Both are interestingly well behind what commercial compilers do, and this is one of the very few areas where that is true. My suspicion is that it does not matter as much in practice as we want it to. Most forms of layout optimization are also very hard to perform on the C++ code you want to optimize due to inability to prove safety)

Re:Firefox 64 built with GCC and Clang by hubicka on Sunday December 16, 2018 @11:34AM (#18693749)
Hehe, nice to see you :)

Yep, I have code layout pass in my tree for a while, but because I was never really able to measure off-noise improvements it is not in the tree, yet. I hope to make more sense of it with help of CPU counters which improved over the time.

Re:Firefox 64 built with GCC and Clang by mhh__ on Sunday December 16, 2018 @01:00PM (#18694177)
I'm not familiar enough with LLVM to really say, so I was just speculating: I vaguely remembered some kind of talk about cache optimisation and LLVM, so it's possible it was talking about the LLVM codebase rather than the passes available in LLVM.