[PATCH] D49144: [FunctionAttrs] Infer the speculatable attribute

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 17 15:12:43 PDT 2018


efriedma added inline comments.


================
Comment at: lib/Transforms/IPO/FunctionAttrs.cpp:1251
+  // have local metadata that might prove the constraint but can't be
+  // speculated).
+
----------------
hfinkel wrote:
> efriedma wrote:
> > Do we also need to look for other attributes on the function?  For example, a function which reads memory but is marked readnone, or a function which calls itself but is marked norecurse.
> I looked at them, but I don't think there are any issues in this regard. Because we don't allow branching, there can't be any control dependencies on whether or not memory is read or whether the function recurses. argmemonly, by the current wording, is not allowed to be valid by implicit contract, so even that one is okay.
It's possible to have a function which has unconditional undefined behavior; that's fine as long as it isn't "speculatable" and never actually gets called.

Or you could have a function like `int g; const int c = 10; __attribute((const)) int f(bool b) { return *(b ? &g : &c); }`. `f(true)` is UB, but `f(false)` is fine.


https://reviews.llvm.org/D49144





More information about the llvm-commits mailing list