[PATCH] D75285: Mark restrict pointer or reference to const as invariant

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 3 12:37:12 PST 2020


rjmccall added a comment.

In D75285#1903611 <https://reviews.llvm.org/D75285#1903611>, @yaxunl wrote:

> In D75285#1903444 <https://reviews.llvm.org/D75285#1903444>, @rjmccall wrote:
>
> > That is not true for two reasons: first, `restrict` guarantees that the variable is not accessed through any non-derived l-value within its scope, and that would certainly include from other threads; and second, it is undefined behavior for two threads to access the same object without synchronizing anyway (unless they're both just reading from it).
>
>
> How about the cases where users cannot use restrict but they still want to mark a pointer as invariant?


I'm not sure what cases those would be; I'm pretty sure that if memory is invariant then you can always use `restrict`.

> Or even though restrict is used but it is too complicated for alias analysis to deduce invariance?

I asked before if there was a specific optimization problem you were trying to solve, and I still have that question.  It kindof feels like somebody's already decided that they don't want to use alias analysis for something, so now you're looking for ways to do it without alias analysis, even though alias analysis might be a satisfactory way of solving the problem.  `restrict` gives us a *lot* of informatiion; I'm sure there are places where we don't preserve it well enough to do some optimization, but that can be improved without needing a whole new language feature.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75285/new/

https://reviews.llvm.org/D75285





More information about the cfe-commits mailing list