In case Chandler ever come see this (or anyone else know the answer) : how would have the optimizer worked if %first (the loop invariant) was volatile ? And how, in general, the optimizer work through a multithreaded code ? Thanks :) . I wish I was there !
A volatile variable typically is accessed in LLVM using a volatile 'load' or 'store' instruction. Unlike a normal 'load', a volatile one has a *side-effect*. It is as-if that load printed output somewhere. This means we can't change how many times we do the load or where we do it with respect to other observable side effects. Hope that helps answer the first question. The second question (optimizing multithreaded code) would require a *much* longer answer... And maybe would even make a great talk.... ;]
Hi there. Thanks for the answer ! Indeed I was curious about that because of the talk of Jason Turner (comodor 64) and the fact that non-volatile variables-read are optimized away from the loop if non volatile. I guess the optimizer really work trough the c++ norm to get the best out of the code. If you're ever think about doing a talk about optimizing multithreaded code, I think I'm not the only one that would be glad to watch it and learn from it ! It's often taboo'ed or black-boxed away because "it's complicated", we don't know "what the compiler does", "what the processor does", "what the operating system does", "is it even deterministic ?" and so on that I can hear from time to time.
In case Chandler ever come see this (or anyone else know the answer) : how would have the optimizer worked if %first (the loop invariant) was volatile ?
And how, in general, the optimizer work through a multithreaded code ?
Thanks :) . I wish I was there !
A volatile variable typically is accessed in LLVM using a volatile 'load' or 'store' instruction. Unlike a normal 'load', a volatile one has a *side-effect*. It is as-if that load printed output somewhere. This means we can't change how many times we do the load or where we do it with respect to other observable side effects. Hope that helps answer the first question.
The second question (optimizing multithreaded code) would require a *much* longer answer... And maybe would even make a great talk.... ;]
Hi there. Thanks for the answer ! Indeed I was curious about that because of the talk of Jason Turner (comodor 64) and the fact that non-volatile variables-read are optimized away from the loop if non volatile. I guess the optimizer really work trough the c++ norm to get the best out of the code.
If you're ever think about doing a talk about optimizing multithreaded code, I think I'm not the only one that would be glad to watch it and learn from it ! It's often taboo'ed or black-boxed away because "it's complicated", we don't know "what the compiler does", "what the processor does", "what the operating system does", "is it even deterministic ?" and so on that I can hear from time to time.