C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [[false_path_is_defined_behavior]] attribute to if-thens

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Thu, 31 Oct 2024 21:25:12 +0000
On Thu, 31 Oct 2024 at 20:05, Matthew Kolbe via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> > You can tell the compiler that this is safe either by loading both
> values before the if
>
> As I mentioned in my other email, this is true (and I believe the best
> work around). My two objections are that it's now two more lines of code.
> The other is that taking both paths is no longer an available optimization,
> but instead part of the code. So, even when it doesn't vectorize, there's
> now an additional load that happens for all compilations.
>


Not necessarily: https://godbolt.org/z/4h8eoe6Ea

The optimized code is identical whether you do two loads and only use one
of them, or only do one load. In the case where you do two loads, one is
dead code that can be removed. But it still tells the compiler that
performing that load is not undefined, so the indices i and i+1 must be
within the array bounds.

Received on 2024-10-31 21:26:30