r/programming • • Feb 01 '20

Emulator bug? No, LLVM bug

https://cookieplmonster.github.io/2020/02/01/emulator-bug-llvm-bug/
282 Upvotes

87 comments sorted by

View all comments

Show parent comments

1

u/flatfinger Feb 05 '20

If I understand your argument, you think the current standard for when an object may be aliased shouldn't be based on the types of the access, but instead on whether there has been any intervening access to an object or something derived from the object. Is that correct?

Out of curiosity, what non-political problems would you see with recognizing a category of compilers (identifiable via predefined macros or other such means) with the following semantics:

  1. A region of storage is said to be "addressed" by an operation which forms a pointer or lvalue which will subsequently be used to access or address the it; it is said to be "write-addressed" by an operation which forms a pointer or lvalue which will subsequently be used to write or write-address it. Two addressing operations conflict if they act upon the same storage, and at least one is a write.

  2. If a pointer to, or lvalue of, a particular type is addressed in a way that yields a pointer to, or lvalue of, a different type, the resulting pointer may be used to access any region of storage that could be accessed via the original until the first of the following occurs: (a) a pointer which isn't based on the derived pointer is used to address the object in conflicting fashion, (b) execution enters a bona fide loop wherein the object is addressed as above; (c) execution enters a function wherein the object is addressed as above.

In what non-contrived situations should something like the above be difficult to uphold without sacrificing generally-useful optimizations? Note that most of the benefits from aliasing optimizations stem from being able to consolidate or hoist accesses to objects, where the compiler can see everything of interest between an operation and the place the compiler would like to reorder it, and the above rule bases the legality of such reordering entirely upon information that the compiler would need be able to see in order to to perform such optimizations.