[LLVMdev] RFC: Proposal to Remove Poison

Sanjoy Das sanjoy at playingwithpointers.com
Sun Feb 8 14:42:14 PST 2015


> Having different notions of undef and poison are problematic as well.
>
> This proposal is motivated from the observation that, in practice, we
> transform:
> define i1 @f(i32 %x, i32 %y, i1 %C) {
>   %add = add nsw i32 %x, %y
>   %sel = select i1 %C, i32 %add, i32 undef
>   %cmp = icmp sgt i32 %sel, %x
>   ret i1 %cmp
> }
>
> into:
> define i1 @f(i32 %x, i32 %y, i1 %C) {
>   %cmp = icmp sgt i32 %y, 0
>   ret i1 %cmp
> }
>
> If undef isn't as strong as poison, this transformation is not valid.

I'd say concluding that the transform is not valid is the "right"
thing to do here.  The way I'd unpack this transform is

 %sel = select i1 %C, i32 %add, i32 undef =0=> %sel = select i1 %C,
i32 %add, i32 %add =1=> %sel = %add

=0=> is problematic since it potentially introduces a use of poison
where there wasn't any.  In general, replacing undef with poison
should not be allowed since as you say, undef is strictly weaker than
poison.

Matthias proposed a poison-to-undef operator that could be used here
-- it is okay to replace %sel with `poison-to-undef %add` and it is
not okay to transform '(poison-to-undef (add nsw x 1)) sgt x` to true.

-- Sanjoy



More information about the llvm-dev mailing list