[PATCH] D127202: [InlineFunction] Handle early exit during getUnderlyingObjects due to MaxLookup
Ting Wang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 12 22:08:20 PDT 2022
tingwang updated this revision to Diff 436272.
tingwang retitled this revision from "[InlineFunction] Call to getUnderlyingObjects inside AddAliasScopeMetadata shall set MaxLookup = 0" to "[InlineFunction] Handle early exit during getUnderlyingObjects due to MaxLookup".
tingwang edited the summary of this revision.
tingwang added a comment.
(1) Conditionally detect early exit during getUnderlyingObjects by invoke getUnderlyingObjects a second time. If we got new pointers, then the first walk had trouble, and be conservative in this case.
(2) Updated using nikic's simple test case.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127202/new/
https://reviews.llvm.org/D127202
Files:
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Transforms/Inline/inline-noalias.ll
Index: llvm/test/Transforms/Inline/inline-noalias.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/inline-noalias.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -passes=inline -S | FileCheck %s
+
+define i32 @caller(ptr %p) {
+ %v = call i32 @callee(ptr %p)
+ ret i32 %v
+}
+
+define internal i32 @callee(ptr noalias %p) {
+ %p.8 = getelementptr i8, ptr %p, i64 8
+; CHECK: %v.i = load i32, ptr %p.8.i, align 4, !alias.scope ![[ALIAS0:[0-9]+]]
+ %v = load i32, ptr %p.8
+ %p.1 = getelementptr i8, ptr %p, i64 1
+ %p.2 = getelementptr i8, ptr %p.1, i64 1
+ %p.3 = getelementptr i8, ptr %p.2, i64 1
+ %p.4 = getelementptr i8, ptr %p.3, i64 1
+ %p.5 = getelementptr i8, ptr %p.4, i64 1
+ %p.6 = getelementptr i8, ptr %p.5, i64 1
+ %p.7 = getelementptr i8, ptr %p.6, i64 1
+ %p.8.alias = getelementptr i8, ptr %p.7, i64 1
+; CHECK-NOT: store i32 42, ptr %p.8.alias.i, align 4, !noalias ![[ALIAS0:[0-9]+]]
+ store i32 42, ptr %p.8.alias
+ ret i32 %v
+}
Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
===================================================================
--- llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1068,15 +1068,41 @@
SmallPtrSet<const Value *, 4> ObjSet;
SmallVector<Metadata *, 4> Scopes, NoAliases;
+ bool ObjNotIdentified = false;
SmallSetVector<const Argument *, 4> NAPtrArgs;
for (const Value *V : PtrArgs) {
SmallVector<const Value *, 4> Objects;
getUnderlyingObjects(V, Objects, /* LI = */ nullptr);
+ // It is not guaranteed that getUnderlyingObjects produce identifiable
+ // object. In this case, try a second walk starting from previous
+ // result. If the end result is different, it is possible that first
+ // walk exited early due to MaxLookup limit.
+ if (!all_of(Objects, isIdentifiedObject)) {
+ SmallVector<const Value *, 4> MoreObjects;
+ DenseMap<const Value *, bool> Objs;
+ for (const Value *V : Objects)
+ getUnderlyingObjects(V, MoreObjects, /* LI = */ nullptr);
+
+ for (const Value *V : Objects)
+ Objs[V] = true;
+
+ for (const Value *V : MoreObjects)
+ if (Objs.find(V) == Objs.end()) {
+ ObjNotIdentified = true;
+ break;
+ }
+ }
+
for (const Value *O : Objects)
ObjSet.insert(O);
}
+ // Be conservative since getUnderlyingObjects stopped the walk in the
+ // middle.
+ if (ObjNotIdentified)
+ continue;
+
// Figure out if we're derived from anything that is not a noalias
// argument.
bool CanDeriveViaCapture = false, UsesAliasingPtr = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127202.436272.patch
Type: text/x-patch
Size: 2806 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220613/ab52c807/attachment.bin>
More information about the llvm-commits
mailing list