[PATCH] D11900: [GMR] Be a bit smarter about which globals alias when doing recursive lookups

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 06:31:37 PDT 2015


majnemer added inline comments.

================
Comment at: lib/Analysis/IPA/GlobalsModRef.cpp:720-729
@@ -719,7 +719,12 @@
 
-      // 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() &&
+          DL->getTypeAllocSize(GVar->getInitializer()->getType()) &&
+          DL->getTypeAllocSize(InputGVar->getInitializer()->getType()))
+        continue;
+
----------------
I guess a zero-sized global can never be "modified" as you would *actually* modify some other global (or commit UB if there was no other global).  However, it's possible to have a global variable in one TU and a global alias in another TU with the same name which makes me think that you need to check that the linkage is not `mayBeOverridden`.


http://reviews.llvm.org/D11900





More information about the llvm-commits mailing list