The fact that loads and stores can have the alignment missing is a constant source of confusion: code that usually works can break down in rare cases. So fix the LoadInst API so the alignment is never missing.
To reduce the number of changes required to make this work, IRBuilder and certain LoadInst constructors will grab the module's datalayout and compute the alignment automatically. This is the same alignment instcombine would eventually apply anyway; we're just doing it earlier. There's a minor risk that the way we're retrieving the datalayout could break out-of-tree code, but I don't think that's likely.
I tried to write the changes here in a way that allows applying each bit independently. So we don't have to apply the whole patch at once; we can review and apply chunks independently. This is taking advantage of two tricks:
1. We can pass the result of getAlign() to setAlignment(), with or without the changes to LoadInst.
2. There's an implicit conversion from Align to MaybeAlign, so various places that expect a MaybeAlign can also take an Align.
This doesn't include test changes. A bunch of regression tests break because the CHECK lines aren't expecting the alignment to get printed.This is the last in a series of patches, And some codegen regression tests produce different assembly because the backend didn't handle unspecified alignment consistently.
so most of the necessary changes have already been merged.