Change some of the internal interfaces in Loads.cpp to keep track of the
number of bytes we're trying to prove dereferenceable using an explicit
Size parameter.
Before this, the Size parameter was implicitly inferred from the
pointee type of the pointer whose dereferenceability we were trying to
prove, causing us to be conservative around bitcasts. This was
unfortunate since bitcast instructions are no-ops and should never
break optimizations. With an explicit Size parameter, we're more
precise (as shown in the test cases), and the code is simpler.
We should eventually move towards a DerefQuery struct that groups
together a base pointer, an offset, a size and an alignment; but this
patch is a first step.
You change the behavior for opaque types here. Is it intentional? Previous version tried to give an answer for the cases where it could guarantee dereferenceability, e.g. load from an opaque typed global. I thought that we even have a test case for that.
If we don't want to support this case anymore, the code can be simplified further. Value::isPointerDereferenceable can be removed, instead we can rely on getPointerDereferenceable to return dereferenceable bytes for the cases now handled by isPointerDereferenceable.
If we do want to support both sized and opaque types it might make sense to separate handling into two functions, one for sized one for non-sized.