From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C031E3858C2C; Tue, 12 Sep 2023 14:55:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C031E3858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694530559; bh=BOX9zIyf+Q29GRIxbe31BnQqcFGGi+Cx6xscsITdn7k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rKWHqpwIieLphNvX1vBv++bj9EDPIwqLNrmvLtCTSgXtnPuntXO98CubkQicNzyq3 X6wqg5jHuKJaOGzHiyRPnKfy7TCqTTCuCkcCeqOnMwuVzKJ0spHS+UUmGRyCvICXqO KcaM634zk14H11zYaXUXKHyuUKT7KJg5bk2bwqrs= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111388] std:.get_if variant, unnecessary branch when outside of if statement Date: Tue, 12 Sep 2023 14:55:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111388 --- Comment #1 from Andrew Pinski --- Note variant can still hold neither ... You might need to add a check for valueless_by_exception here. But variant::index could be improved to say the only values that are valid = is [0,N],[-1]. and that will remove the check. Note clang even produces the similar code even with libc++: xorl %eax, %eax cmpl $2, 8(%rdi) cmovaeq %rax, %rdi Just GCC isolates the null pointer access.=