https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106811

--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> ---
> Am 07.11.2022 um 19:07 schrieb nunoplopes at sapo dot pt 
> <gcc-bugzi...@gcc.gnu.org>:
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106811
> 
> --- Comment #3 from Nuno Lopes <nunoplopes at sapo dot pt> ---
>>> I suggest adopting the concept of poison that LLVM has. It allows 
>>> operations 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
>>> 
>>> Happy to discuss further.
>> 
>> 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 
> could
> 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.

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 them
defined is to make them unsigned)

> 
> -- 
> You are receiving this mail because:
> You reported the bug.

Reply via email to