Current implementation of PHITransAddr::PHITranslateValue succeeds only if phi translated address has exact match in the predecessor (see code at PHITransAddr.cpp:237 for more details). In other words, it will fail to translate %p5 (and as a result optimize stores) in the following example:
BB1:
%p1 = ...
%p2 = GEP i8* %p1, 2
store i32* %p2, 0
...
BB3:
%p3 = phi([%p1, BB1], ....)
%p4 = GEP i8* %p3, 1
%p5 = bitcast i8*p3 to i16*
store %p5, 0
The solution is to traverse through GEPs (and maintain offsets) before calling PHITransAddr::PHITranslateValue.
clang-format suggested style edits found: