C++ Logo

std-proposals

Advanced search

Re: std::as

From: Ryan P. Nicholl <rnicholl_at_[hidden]>
Date: Mon, 26 Oct 2020 18:09:17 +0000
I mean sure, we could convince compiler writers to implement more optimizations... or we could just add std::as. We currently require a branch even if it could theoretically be removed by the optimizer. Both get and get_if require a branch. I would not rely on compilers eliminating branches. My experience is that they are quite poor at doing this.

--
Ryan P. Nicholl
Tel: (678)-358-7765
Personal Email: rnicholl_at_[hidden]
Work Email: ryan.nicholl_at_[hidden]icrosoft.com
Tox: 52B3A61CDAF88BCC854F568933F071E3530600CDBA3D5354AADC9AD179575D68021AE959719D
-------- Original Message --------
On Oct 26, 2020, 10:58, Arthur O'Dwyer via Std-Proposals wrote:
> On Mon, Oct 26, 2020 at 10:46 AM Giuseppe D'Angelo via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>
>> On 26/10/2020 15:24, Arthur O'Dwyer via Std-Proposals wrote:
>> >
>> > Confirmed. Have people filed missed-optimization bugs against GCC and
>> > MSVC on this topic, yet? People should.
>> > https://godbolt.org/z/n9acqh
>>
>> Clang too? https://godbolt.org/z/MarcvM
>
> That's a tougher one. Most compilers (for historical reasons) cannot assume that references are always non-null; the caller might be testing, like,
>
> int main() { return &getint(v) != nullptr; }
>
> This is UB, of course, but it's also super common in legacy code.
> So what I would expect here is that the compiler vendor should provide a compiler flag something like -fno-null-references, to enable the optimization of getint() when it returns a reference type. I haven't done my homework to learn how that flag is spelled on any of the Big Three vendors — or even if it exists yet.
>
> –Arthur

Received on 2020-10-26 13:09:29