PATCH: UndefInst and UnreachableValue (Constant)

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 01:41:08 PDT 2016


Hi Nick!

This is great!

Nick Lewycky via llvm-commits wrote:
 > This series of patches proposes two closely related extensions to LLVM's handling and optimization of undefined 
behaviour.
 >
 > The first innovation is the "undef instruction" which produces a single value that is in range for its type, but does
 > not define what that single value is. That is, it can not be unsigned-less-than zero, nor can it be both not equal to X
 > and not equal to Y where X is not equal to Y. That sort of thing.

+1

 > The second innovation is the inverse of the first, adding UnreachableValue with semantics similar to the existing
 > unreachable instruction, but as a constant. The intended primary user is the constant folder itself.
 >
 > Similarly to undef, combining an unreachable constant with another value produces an unreachable constant. "unreachable
 > + 1 == unreachable". You can safely put an unreachable on one side of a select as long as that side is not chosen

I think "combining an unreachable constant with another value produces
an unreachable constant" needs more clarification.  Is "0 &
unreachable_value == unreachable_value"?  If so, we cannot replace
"select i1 %c, i1 %x, i1 0" with "%c & %x" since if %c == 0 and %x ==
unreachable_value, then the former is 0 but the latter is
unreachable_value.

At least on the surface unreachable_value sounds a lot like poison,
we'll have to be careful in making sure it does not have the same
problems as poison.

-- Sanjoy


More information about the llvm-commits mailing list