Do [[likely]] and [[unlikely]] flags have anything to do with CPU code prediction / speculative execution that has been a burning subject recently (Spectre)?
It's more than that - it can inform many optimisations, for example keeping values alive in one branch at the expense of another.
But see "Don’t use the [[likely]] or [[unlikely]] attributes": https://blog.aaronballman.com/2020/08/dont-use-the-likely-or...
These attributes are just hints to move hot/slow code near/far away and to maybe to the right thing if there’s no branch prediction. They cannot prevent speculative execution.