[Clang] Add option to allow marking pass-by-value args as noalias.
authorFlorian Hahn <flo@fhahn.com>
Sat, 12 Sep 2020 13:23:36 +0000 (14:23 +0100)
committerFlorian Hahn <flo@fhahn.com>
Sat, 12 Sep 2020 13:56:13 +0000 (14:56 +0100)
commita874d63344093752c912d01de60211f65745ea6f
tree1af7a9221b4586b540e96968fabfed447d658872
parent2e61cd1295e0031b2379af2b65373e2798a551cb
[Clang] Add option to allow marking pass-by-value args as noalias.

After the recent discussion on cfe-dev 'Can indirect class parameters be
noalias?' [1], it seems like using using noalias is problematic for
current C++, but should be allowed for C-only code.

This patch introduces a new option to let the user indicate that it is
safe to mark indirect class parameters as noalias. Note that this also
applies to external callers, e.g. it might not be safe to use this flag
for C functions that are called by C++ functions.

In targets that allocate indirect arguments in the called function, this
enables more agressive optimizations with respect to memory operations
and brings a ~1% - 2% codesize reduction for some programs.

[1] : http://lists.llvm.org/pipermail/cfe-dev/2020-July/066353.html

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D85473
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/pass-by-value-noalias.c [new file with mode: 0644]
clang/test/CodeGenCXX/pass-by-value-noalias.cpp [new file with mode: 0644]
clang/test/CodeGenObjC/pass-by-value-noalias.m [new file with mode: 0644]