> Can we? q is at a language level, possibly aliased with the write immediately above to (p+1)
It's not, because writing to a one-past-the-end pointer is UB.
> Indeed, there was originally a write to q, which we replaced with an aliased write to q, so it seems to me that on the whole, the various optimizations are assuming different things about aliasing.
That optimization pass doesn't know anything about aliasing, it just replaced an integer with another integer that's equal to the first.
It's not, because writing to a one-past-the-end pointer is UB.
> Indeed, there was originally a write to q, which we replaced with an aliased write to q, so it seems to me that on the whole, the various optimizations are assuming different things about aliasing.
That optimization pass doesn't know anything about aliasing, it just replaced an integer with another integer that's equal to the first.