From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 753B13858C3A; Mon, 7 Nov 2022 18:07:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 753B13858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667844460; bh=Inz4ElVrPJ8Ia8VH23giDUiD6iBjmK1J1htTB7ERmsk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=G2At1cYu+RbIBHnXefbY3S3I9nHOOwjpcIWBXuOnDkr0xVcTpSTwPlGR4qGJee8ZS QBj7hm4RxiXe0n932wBMW3vEKNDttHgpNcQnhYVNYvpbF+y9jUbZQz9ESmeZaFvGkw 5vxPfAc7mO0jf/Fz+TBbhcNTMUmVHzAS2ELa0Uz0= From: "nunoplopes at sapo dot pt" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/106811] GENERIC and GIMPLE IL undefined behavior needs documenting Date: Mon, 07 Nov 2022 18:07:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nunoplopes at sapo dot pt 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=3D106811 --- Comment #3 from Nuno Lopes --- > > I suggest adopting the concept of poison that LLVM has. It allows opera= tions to > > have undefined behavior, while still allow them to be moved freely. > > I have some slides that may serve as an introduction to the topic: > > https://web.ist.utl.pt/nuno.lopes/pres/ub-vmcai19.pdf > >=20 > > Happy to discuss further. >=20 > I've seen this before but I don't really see how that manages to avoid > issues when making conditional undefined behavior invoking stmts > unconditional. It's like a NaN in the sense that you can invoke e.g. arithmetic operations. You can do 2 + poison. That's poison. But you can't do 2 / poison. That's undefined behavior (UB), since poison c= ould be a zero at run time. So poison enables free movement of instructions that don't trigger UB. For instructions that may trigger UB, like division, memory accesses, function calls, etc, you still need to be careful as usual when moving those around. But the point is that poison explains the correctness of the optimizations = that gcc is already doing today, like hoisting arithmetic operations. You can't their semantics be full UB on e.g. signed overflow as otherwise you couldn't hoist them without proving that overflows can't happen.=