When reusing a load in a way that requires coercion (i.e. casts or bit extraction) we currently fail to adjust metadata. Unfortunately, none of our existing tooling for this is really suitable, because combineMetadataForCSE() expects both loads to have the same type. In this case we may work on loads of different types and possibly and offset memory location.
As such, what this patch does is to simply drop all metadata, with the following exceptions:
- Metadata for which violation is known to always cause UB.
- If the load is !noundef, keep all metadata, as this will turn poison-generating metadata into UB as well.
This fixes the miscompile that was exposed by D146629.
For !noalias or !alias.scope, I think we don't care about the size and type. But it is also dropped. Maybe leave a TODO which says we can do better for these two metadata.