[PATCH] D73679: [MemoryBuiltins] Determine the size of a global w/o initializer

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 20:35:47 PST 2020


jdoerfert created this revision.
jdoerfert added reviewers: hfinkel, george.burgess.iv.
Herald added subscribers: bollu, hiraditya.
Herald added a project: LLVM.

NOTE: This is a patch to help start a discussion in response to
      http://lists.llvm.org/pipermail/llvm-dev/2020-January/138725.html

The idea is that a initializer is not necessary if we know the
definition is exact and it is not an empty object.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73679

Files:
  llvm/lib/Analysis/MemoryBuiltins.cpp
  llvm/test/Analysis/BasicAA/bug.23540.ll


Index: llvm/test/Analysis/BasicAA/bug.23540.ll
===================================================================
--- llvm/test/Analysis/BasicAA/bug.23540.ll
+++ llvm/test/Analysis/BasicAA/bug.23540.ll
@@ -4,8 +4,11 @@
 
 @c = external global i32
 
+; Since there are no sizes and both accesses are based on the same global they
+; (can) partially overlap.
+
 ; CHECK-LABEL: f
-; CHECK: MayAlias: i32* %arrayidx, i32* %arrayidx6
+; CHECK: PartialAlias: i32* %arrayidx, i32* %arrayidx6
 define void @f() {
   %idxprom = zext i32 undef to i64
   %add4 = add i32 0, 1
Index: llvm/lib/Analysis/MemoryBuiltins.cpp
===================================================================
--- llvm/lib/Analysis/MemoryBuiltins.cpp
+++ llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -761,10 +761,13 @@
 }
 
 SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalVariable(GlobalVariable &GV){
-  if (!GV.hasDefinitiveInitializer())
+  // Make sure we have an exact definition that cannot be changed.
+  if (!GV.isDefinitionExact())
     return unknown();
-
+  // Weed out any flexible array types.
   APInt Size(IntTyBits, DL.getTypeAllocSize(GV.getValueType()));
+  if (Size.isNullValue())
+    return unknown();
   return std::make_pair(align(Size, GV.getAlignment()), Zero);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73679.241343.patch
Type: text/x-patch
Size: 1259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200130/2d280739/attachment.bin>


More information about the llvm-commits mailing list