From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EA632385841A; Mon, 7 Nov 2022 18:17:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA632385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667845026; bh=FHo3XRwogPfFZA/YoY7YJxW7Ia0BjQSFd3eFd5oX6M8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ok5mJxiAw00XKFRYAj3G2XILvY8GBKWSQayeK6ybGfhTrAUmVmr4BYqh964b4rc1c 6m7p9qk/A6e3QOR6o9Fz2dL43vAmh6vRqScoE+DO+T97is2ZhUciK+wI7LMKu0hX6K XSXi2v+JmerVB/bPrBoCpKmwgBJLp5wYrKlQn8rM= From: "rguenther at suse dot de" 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:17:06 +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: rguenther at suse dot de 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 #4 from rguenther at suse dot de --- > Am 07.11.2022 um 19:07 schrieb nunoplopes at sapo dot pt : >=20 > =EF=BB=BFhttps://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106811 >=20 > --- 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. >=20 > It's like a NaN in the sense that you can invoke e.g. arithmetic operatio= ns. > You can do 2 + poison. That's poison. >=20 > But you can't do 2 / poison. That's undefined behavior (UB), since poison= could > be a zero at run time. >=20 > 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 aroun= d. >=20 > But the point is that poison explains the correctness of the optimization= s 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 could= n't > hoist them without proving that overflows can't happen. The point is they are and we are rewriting them to defined overflow when hoisting. Or in case of division avoid hoisting (because the way to make t= hem defined is to make them unsigned) >=20 > --=20 > You are receiving this mail because: > You reported the bug.=