The pointer size of the addrspacecasted pointer might not have matched,
so this would have hit an assert in accumulateConstantOffset.
I think this was here to allow constant folding of a load of an
addrspacecasted constant. Accumulating the offset through the
addrspacecast doesn't make much sense, so something else is necessary
to allow folding the load through this cast.
Isn't there still a bug here? The size of the result type of ptrtoint can disagree with its operand's type.
Sounds like the correct thing to do would be to call the static member function CastInst::isNoopCast with appropriate operands.