[llvm-dev] UB and known bits

John Regehr via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 8 10:26:45 PDT 2015


On the subject of undefined behavior and known bits, as I'm sure some of 
you are aware, code in ValueTracking.cpp is exploiting poison value rules 
to get a bit of extra precision in the known bits. These rules fire on 
examples like the ones below.  Do we have a set of rules that clients of 
known bits need to follow to avoid unsoundness?  I remember Nuno and/or 
David Majnemer saying something about this but I don't have it handy.

John


%0:i32 = var
%1:i32 = lshr %0, 1:i32
%2:i32 = addnw 1:i32, %1
infer %2

known from Souper:   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
known from compiler: 0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
llvm is stronger



%0:i32 = var (000000000000000xxxxxxxxxxxxxxxxx)
%1:i32 = and 65535:i32, %0
%2:i16 = var
%3:i32 = zext %2
%4:i32 = mulnw %1, %3
infer %4

known from Souper:   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
known from compiler: 0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
llvm is stronger


More information about the llvm-dev mailing list