aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorChen Zheng <czhengsz@cn.ibm.com>2022-06-24 08:04:06 -0400
committerChen Zheng <czhengsz@cn.ibm.com>2022-07-01 02:16:55 -0400
commit39fe49aa57896831d63d10dee8b85ca665c97ad0 (patch)
treee404545410f9fc661da2b3c3e8cf4bd1722bc231 /llvm/lib/Transforms/Utils/InlineFunction.cpp
parentb6b65403b3826af5404f874f32d7abd8ef8a8a96 (diff)
downloadllvm-39fe49aa57896831d63d10dee8b85ca665c97ad0.zip
llvm-39fe49aa57896831d63d10dee8b85ca665c97ad0.tar.gz
llvm-39fe49aa57896831d63d10dee8b85ca665c97ad0.tar.bz2
[Inline] don't add noalias metadata for unknown objects.
The unidentified objects recognized in `getUnderlyingObjects` may still alias to the noalias parameter because `getUnderlyingObjects` may not check deep enough to get the underlying object because of `MaxLookup`. The real underlying object for the unidentified object may still be the noalias parameter. Originally Patched By: tingwang Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D127202
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 226b00a..2fb00f9 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1077,7 +1077,8 @@ static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap,
// Figure out if we're derived from anything that is not a noalias
// argument.
- bool RequiresNoCaptureBefore = false, UsesAliasingPtr = false;
+ bool RequiresNoCaptureBefore = false, UsesAliasingPtr = false,
+ UsesUnknownObject = false;
for (const Value *V : ObjSet) {
// Is this value a constant that cannot be derived from any pointer
// value (we need to exclude constant expressions, for example, that
@@ -1098,14 +1099,24 @@ static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap,
UsesAliasingPtr = true;
}
- // If this is not some identified function-local object (which cannot
- // directly alias a noalias argument), or some other argument (which,
- // by definition, also cannot alias a noalias argument), then we could
- // alias a noalias argument that has been captured).
- if (!isa<Argument>(V) && !isIdentifiedFunctionLocal(V))
+ if (isEscapeSource(V)) {
+ // An escape source can only alias with a noalias argument if it has
+ // been captured beforehand.
RequiresNoCaptureBefore = true;
+ } else if (!isa<Argument>(V) && !isIdentifiedObject(V)) {
+ // If this is neither an escape source, nor some identified object
+ // (which cannot directly alias a noalias argument), nor some other
+ // argument (which, by definition, also cannot alias a noalias
+ // argument), conservatively do not make any assumptions.
+ UsesUnknownObject = true;
+ }
}
+ // Nothing we can do if the used underlying object cannot be reliably
+ // determined.
+ if (UsesUnknownObject)
+ continue;
+
// A function call can always get captured noalias pointers (via other
// parameters, globals, etc.).
if (IsFuncCall && !IsArgMemOnlyCall)