|
|
|
|
|
by aw1621107
876 days ago
|
|
Yeah, the extra instructions from the division helped clue me into what might be going on, since the individual (f - b) and (e - b) calculations are visible in Clang's output. I feel the division by sizeof(T) shouldn't matter that much, since the compiler knows it has pointers to T so I don't think the divisions would have remainders. I want to say pointer overflow and arithmetic on pointers to different objects (allocations?) should also be UB, so I suppose that might clear up most obstacles? I think I'm still missing something... Does make me wonder how frequently this pattern might pop up elsewhere if it does turn out to be optimizable. |
|
> Does make me wonder how frequently this pattern might pop up elsewhere if it does turn out to be optimizable.
Probably a fair bit, but as I mentioned, it might break a lot of code too, because there's too much code in the wild doing illegal things with pointers (like shoving random state into the lower bits, etc.). Or not... the Clang folks would probably know better.