An alignment should be non-zero positive power-of-two, anything and everything else is UB.
We should not have that check for all these prerequisites here, it's just UB.
Also, that was likely confusing middle-end passes.
While there, CreateIntCast() should be called with /*isSigned*/ false.
Think about it, there are two explanations: "An alignment should be positive",
therefore the sign bit is unset, so zext and sext is equivalent.
Or a second one: you have i2 0b10 - a valid alignment,
now you sext it: i2 0b110 - no longer valid alignment.
Why not just use a Boolean?