[llvm-dev] RFC: Killing undef and spreading poison

Nuno Lopes via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 18 12:25:37 PDT 2016


> On 10/18/2016 5:06 AM, Nuno Lopes via llvm-dev wrote:
>> Another use is, for example, to implement bit-fields:
>> a.x = 2
>> becomes:
>> %v = load %a
>> %v2 = freeze %v  ; %v could be uninitialized data (poison)
>> %v3 = ... bitmasking...
>> store %a, %v3
>
> It seems like you're saying that an integer load which touches any 
> uninitialized byte of memory results in poison.  Therefore, load %a 
> simplifies to "poison", and your proposed lowering of a bitfield write 
> throws away the value of every other adjacent bitfield.  Am I missing 
> something?

Right, a load touching a single uninitialized bit results in poison.
The trick is that on the first bitfield write, all the remaining untouched 
fields become initialized (with an arbitrary value, though). Essentially we 
are making the adjacent bitfields undef.

So if you have:
struct foo a;
a.x = 2;
a.y = 3;

IR becomes:
%a = alloca foo
%x = load %a
%x2 = freeze %v  ; %x2 not poison
%x3 = bitmasking  ; %x3 not poison
store %a, %x3

%y = load %a
%y2 = freeze %y  ;  not needed; %y is not poison
etc..

Nuno 



More information about the llvm-dev mailing list