https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99470
Mathias Stearn <redbeard0531 at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED Resolution|INVALID |--- --- Comment #4 from Mathias Stearn <redbeard0531 at gmail dot com> --- Yes, but I believe any case where they would access different addresses would be UB overflow in f(), making it valid to turn f() into g(), especially if you used an internal lowering which sign extended index to pointer width and had defined wrapping semantics. I'll note that clang already generates identical code for f() and g() https://gcc.godbolt.org/z/j897sh, although I think gcc has better codegen at least for g(). Also, my example was perhaps oversimplified. My indexes were actually int8_t (which is why I'm indexing into a 256-element array), so due to int promotion, overflow is actually impossible. However, with int8_t arguments, gcc generates even worse code for f(), doing the sign-extension twice for some reason (8 -> 32 -> 64): https://gcc.godbolt.org/z/5r9h89 (I hope it isn't a faux pas to reopen the ticket, but I think I've provided enough new information that this warrants another look)