[PATCH] llvm.noalias - Clang CodeGen for local restrict-qualified pointers

John McCall rjmccall at gmail.com
Sat May 2 12:45:54 PDT 2015

Comment at: lib/CodeGen/CGExpr.cpp:1286
@@ -1283,1 +1285,3 @@
+    Value = Builder.CreateNoAlias(Value, NAI->second);
   if (Ty->isAtomicType() ||
This is very strange.  Why do the aliasing properties of an address cause metadata to be attached to the value stored into it?  Shouldn't the metadata be on the address (in which case, perhaps it should have been attached to the load from the restrict pointer?) or the store?

Also, please find some way to avoid doing a DenseMap lookup on every single store.  I would guess that the address only has an entry in that table if it was restrict-qualified; you can probably find a way to pass that information down.

Comment at: lib/CodeGen/CGStmt.cpp:267
@@ +266,3 @@
+/// restrict-qualified variables declared within it.
+struct RestrictFinder : RecursiveASTVisitor<RestrictFinder> {
+  bool FoundRestrictDecl;
RecursiveASTVisitors are actually really big; the last time I checked, a RecursiveASTVisitor compiled to several hundred kilobytes of code, no matter how few traversals you actually have in it.

Also, doing a recursive walk every time you enter a scope is inherently quadratic with deeply-nested scopes.

You don't really need a fully recursive walk, though.  The language specification for 'restrict' talks about the scope B that declares the restrict-qualified pointer; you just need to scan the current compound statement for variable declarations.



More information about the cfe-commits mailing list