[llvm] r257750 - [GlobalsAA] Relax condition in checking globals as args to functions
Vaivaswatha Nagaraj via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 14 00:46:47 PST 2016
Author: vaivaswatha
Date: Thu Jan 14 02:46:45 2016
New Revision: 257750
URL: http://llvm.org/viewvc/llvm-project?rev=257750&view=rev
Log:
[GlobalsAA] Relax condition in checking globals as args to functions
Summary:
Since globals may escape as function arguments (even when they have been
found to be non-escaping, because of optimizations such as memcpyoptimizer
that replaces stores with memcpy), all arguments to a function are checked
during query to make sure they are identifiable. At that time, also ensure
we return a conservative result only if the arguments don't alias to our global.
Reviewers: hfinkel, jmolloy
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D16140
Added:
llvm/trunk/test/Analysis/GlobalsModRef/no-escape.ll
Modified:
llvm/trunk/lib/Analysis/GlobalsModRef.cpp
Modified: llvm/trunk/lib/Analysis/GlobalsModRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/GlobalsModRef.cpp?rev=257750&r1=257749&r2=257750&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/GlobalsModRef.cpp (original)
+++ llvm/trunk/lib/Analysis/GlobalsModRef.cpp Thu Jan 14 02:46:45 2016
@@ -863,7 +863,11 @@ ModRefInfo GlobalsAAResult::getModRefInf
GetUnderlyingObjects(A, Objects, DL);
// All objects must be identified.
- if (!std::all_of(Objects.begin(), Objects.end(), isIdentifiedObject))
+ if (!std::all_of(Objects.begin(), Objects.end(), isIdentifiedObject) &&
+ // Try ::alias to see if all objects are known not to alias GV.
+ !std::all_of(Objects.begin(), Objects.end(), [&](Value *V) {
+ return this->alias(MemoryLocation(V), MemoryLocation(GV)) == NoAlias;
+ }))
return ConservativeResult;
if (std::find(Objects.begin(), Objects.end(), GV) != Objects.end())
Added: llvm/trunk/test/Analysis/GlobalsModRef/no-escape.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/GlobalsModRef/no-escape.ll?rev=257750&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/GlobalsModRef/no-escape.ll (added)
+++ llvm/trunk/test/Analysis/GlobalsModRef/no-escape.ll Thu Jan 14 02:46:45 2016
@@ -0,0 +1,65 @@
+; RUN: opt < %s -basicaa -globals-aa -S -enable-non-lto-gmr=true -licm | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.10.0"
+
+ at b = common global i32 0, align 4
+ at c = internal global i32 0, align 4
+ at d = common global i32 0, align 4
+ at e = common global i32* null, align 4
+
+define void @foo(i32* %P) noinline {
+; CHECK: define void @foo
+ %loadp = load i32, i32* %P, align 4
+ store i32 %loadp, i32* @d, align 4
+ ret void
+}
+
+define void @bar() noinline {
+; CHECK: define void @bar
+ %loadp = load i32, i32* @d, align 4
+ store i32 %loadp, i32* @c, align 4
+ ret void
+}
+
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4
+ %c = alloca [1 x i32], align 4
+ store i32 0, i32* %retval, align 4
+ call void @bar()
+ store i32 0, i32* @b, align 4
+ br label %for.cond
+ ;; Check that @c is LICM'ed out.
+; CHECK: load i32, i32* @c
+for.cond: ; preds = %for.inc, %entry
+; CHECK-LABEL: for.cond:
+; CHECK: load i32, i32* @b
+ %a1 = load i32, i32* @b, align 4
+ %aa2 = load i32, i32* @c, align 4
+ %add = add nsw i32 %a1, %aa2
+ %p1 = load i32*, i32** @e, align 4
+ call void @foo(i32* %p1)
+ %cmp = icmp slt i32 %add, 3
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %a2 = load i32, i32* @b, align 4
+ %idxprom = sext i32 %a2 to i64
+ br label %for.inc
+
+for.inc: ; preds = %for.body
+ %a3 = load i32, i32* @b, align 4
+ %inc = add nsw i32 %a3, 1
+ store i32 %inc, i32* @b, align 4
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ ret i32 0
+}
+
+; Function Attrs: nounwind argmemonly
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind argmemonly
+
+; Function Attrs: noreturn nounwind
+declare void @abort() noreturn nounwind
More information about the llvm-commits
mailing list