[PATCH] D13512: [GlobalsAA] Loosen an overly conservative bailout
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 13 03:10:26 PDT 2015
jmolloy updated this revision to Diff 37225.
jmolloy added a comment.
Hi Chandler,
You're right, the previous patch was utter utter nonsense.
This updated patch covers all the cases I cared about and seems far more sound. Simply: instead of bailing out, recurse. If a captured value is found while following a chain of loads, all those loads are also captured.
This lets us hit the case I care about which is something like:
static int a;
static int **b;
alias? (a, b[1][2]);
Cheers,
James
Repository:
rL LLVM
http://reviews.llvm.org/D13512
Files:
lib/Analysis/GlobalsModRef.cpp
test/Analysis/GlobalsModRef/nonescaping-noalias.ll
Index: test/Analysis/GlobalsModRef/nonescaping-noalias.ll
===================================================================
--- test/Analysis/GlobalsModRef/nonescaping-noalias.ll
+++ test/Analysis/GlobalsModRef/nonescaping-noalias.ll
@@ -97,3 +97,20 @@
%v = load i32, i32* @g1
ret i32 %v
}
+
+define i32 @test5(i32** %param) {
+; Ensure that we can fold a store to a load of a global across a store to
+; a parameter that has been dereferenced when the global is non-escaping.
+;
+; CHECK-LABEL: @test5(
+; CHECK: %p = load i32*
+; CHECK: store i32 42, i32* @g1
+; CHECK-NOT: load i32
+; CHECK: ret i32 42
+entry:
+ %p = load i32*, i32** %param
+ store i32 42, i32* @g1
+ store i32 7, i32* %p
+ %v = load i32, i32* @g1
+ ret i32 %v
+}
Index: lib/Analysis/GlobalsModRef.cpp
===================================================================
--- lib/Analysis/GlobalsModRef.cpp
+++ lib/Analysis/GlobalsModRef.cpp
@@ -666,22 +666,30 @@
// non-addr-taken globals.
continue;
}
+ // Recurse through a limited number of selects, loads and PHIs. This is an
+ // arbitrary depth of 4, lower numbers could be used to fix compile time
+ // issues if needed, but this is generally expected to be only be important
+ // for small depths.
+ if (++Depth > 4)
+ return false;
+
if (auto *LI = dyn_cast<LoadInst>(Input)) {
// A pointer loaded from a global would have been captured, and we know
// that the global is non-escaping, so no alias.
if (isa<GlobalValue>(GetUnderlyingObject(LI->getPointerOperand(), DL)))
continue;
- // Otherwise, a load could come from anywhere, so bail.
- return false;
+ auto *Ptr = GetUnderlyingObject(LI->getPointerOperand(), DL);
+ if (Ptr) {
+ // If the object this is loaded from is itself captured, then this
+ // pointer must have been captured too.
+ Inputs.push_back(Ptr);
+ continue;
+ } else {
+ // Otherwise, a load could come from anywhere, so bail.
+ return false;
+ }
}
-
- // Recurse through a limited number of selects and PHIs. This is an
- // arbitrary depth of 4, lower numbers could be used to fix compile time
- // issues if needed, but this is generally expected to be only be important
- // for small depths.
- if (++Depth > 4)
- return false;
if (auto *SI = dyn_cast<SelectInst>(Input)) {
const Value *LHS = GetUnderlyingObject(SI->getTrueValue(), DL);
const Value *RHS = GetUnderlyingObject(SI->getFalseValue(), DL);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13512.37225.patch
Type: text/x-patch
Size: 2563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151013/f62b847c/attachment.bin>
More information about the llvm-commits
mailing list