[PATCH] D11900: [GMR] Be a bit smarter about which globals alias when doing recursive lookups
Michael Kuperstein via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 06:58:09 PDT 2015
mkuper updated this revision to Diff 31664.
mkuper added a comment.
Thanks, David!
Added the check mayBeOverwritten() check.
About the zero-size check, what if you have two consecutive zero-size globals, followed by a third (non-zero-size) global? (That sounds like nonsense, but I don't quite understand the semantics of zero-size globals to begin with.)
http://reviews.llvm.org/D11900
Files:
lib/Analysis/IPA/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
@@ -61,7 +61,9 @@
ret i32 %v
}
-define i32 @test4(i32* %param, i32 %n, i1 %c1, i1 %c2) {
+ at g3 = internal global i32 1
+
+define i32 @test4(i32* %param, i32 %n, i1 %c1, i1 %c2, i1 %c3) {
; Ensure that we can fold a store to a load of a global across a store to
; the pointer loaded from that global even when the load is behind PHIs and
; selects, and there is a mixture of a load and another global or argument.
@@ -77,14 +79,15 @@
store i32 42, i32* @g1
%ptr1 = load i32*, i32** @g2
%ptr2 = select i1 %c1, i32* %ptr1, i32* %param
+ %ptr3 = select i1 %c3, i32* %ptr2, i32* @g3
br label %loop
loop:
%iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
- %ptr = phi i32* [ %ptr2, %entry ], [ %ptr4, %loop ]
+ %ptr = phi i32* [ %ptr3, %entry ], [ %ptr5, %loop ]
store i32 7, i32* %ptr
- %ptr3 = load i32*, i32** @g2
- %ptr4 = select i1 %c2, i32* %ptr3, i32* %call
+ %ptr4 = load i32*, i32** @g2
+ %ptr5 = select i1 %c2, i32* %ptr4, i32* %call
%inc = add i32 %iv, 1
%test = icmp slt i32 %inc, %n
br i1 %test, label %loop, label %exit
Index: lib/Analysis/IPA/GlobalsModRef.cpp
===================================================================
--- lib/Analysis/IPA/GlobalsModRef.cpp
+++ lib/Analysis/IPA/GlobalsModRef.cpp
@@ -717,12 +717,20 @@
if (InputGV == GV)
return false;
- // FIXME: It would be good to handle other obvious no-alias cases here, but
- // it isn't clear how to do so reasonbly without building a small version
- // of BasicAA into this code. We could recurse into AliasAnalysis::alias
- // here but that seems likely to go poorly as we're inside the
- // implementation of such a query. Until then, just conservatievly retun
- // false.
+ // Distinct GlobalVariables never alias, unless zero-sized.
+ // FIXME: The condition can be refined, but be conservative for now.
+ auto *GVar = dyn_cast<GlobalVariable>(GV);
+ auto *InputGVar = dyn_cast<GlobalVariable>(InputGV);
+
+ if (GVar && InputGVar &&
+ !GVar->isDeclaration() && !InputGVar->isDeclaration() &&
+ !GVar->mayBeOverridden() && !InputGVar->mayBeOverridden() &&
+ DL->getTypeAllocSize(GVar->getInitializer()->getType()) &&
+ DL->getTypeAllocSize(InputGVar->getInitializer()->getType()))
+ continue;
+
+ // Conservatively return false, even though we could be smarter
+ // (e.g. look through GlobalAliases).
return false;
}
@@ -767,7 +775,12 @@
continue;
}
- // Unknown instruction, bail.
+ // FIXME: It would be good to handle other obvious no-alias cases here, but
+ // it isn't clear how to do so reasonbly without building a small version
+ // of BasicAA into this code. We could recurse into AliasAnalysis::alias
+ // here but that seems likely to go poorly as we're inside the
+ // implementation of such a query. Until then, just conservatievly retun
+ // false.
return false;
} while (!Inputs.empty());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11900.31664.patch
Type: text/x-patch
Size: 3318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150810/ec2d6118/attachment.bin>
More information about the llvm-commits
mailing list