This gets rid of a bunch of weird special cases; instead of trying to understand the structure of the induction variable, just use SCEV expansion for everything. In addition to being simpler, this fixes a bug where we would use the wrong stride in certain edge cases; see the new test pointer_bitcast_baseinst. (The bug might be a regression from D26529 ? Not sure.)
The one bit I'm not quite sure about is the trip count handling, specifically the FIXME about overflow. In general, I think we need to widen the exit condition, but that's probably not profitable if the new type isn't legal, so we probably need a check somewhere. That said, I don't think this patch makes the existing problem any worse.
As a followup to this, a bunch of other IV-related could be cleaned up and generalized, since the rewriting can handle more cases.
Stale doxygen comment. Could you document LIBETC?