OSDN Git Service

Fix ARMGlobalMerge pass to check if globals are entirely within range.
authorBob Wilson <bob.wilson@apple.com>
Wed, 17 Nov 2010 21:25:36 +0000 (21:25 +0000)
committerBob Wilson <bob.wilson@apple.com>
Wed, 17 Nov 2010 21:25:36 +0000 (21:25 +0000)
It is generally not sufficient to check if the starting offset is in range
of the maximum offset that can be efficiently used for the target.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119565 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMGlobalMerge.cpp
test/CodeGen/ARM/global-merge.ll

index 44d5235..72cab64 100644 (file)
@@ -129,11 +129,14 @@ bool ARMGlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
     uint64_t MergedSize = 0;
     std::vector<const Type*> Tys;
     std::vector<Constant*> Inits;
-    for (j = i; MergedSize < MaxOffset && j != e; ++j) {
+    for (j = i; j != e; ++j) {
       const Type *Ty = Globals[j]->getType()->getElementType();
+      MergedSize += TD->getTypeAllocSize(Ty);
+      if (MergedSize > MaxOffset) {
+        break;
+      }
       Tys.push_back(Ty);
       Inits.push_back(Globals[j]->getInitializer());
-      MergedSize += TD->getTypeAllocSize(Ty);
     }
 
     StructType *MergedTy = StructType::get(M.getContext(), Tys);
index dcc16c0..e519dde 100644 (file)
@@ -9,3 +9,9 @@
 ; CHECK: _MergedGlobals:
 @g1 = internal global i32 1
 @g2 = internal global i32 2
+
+; Make sure that the complete variable fits within the range of the maximum
+; offset.  Having the starting offset in range is not sufficient.
+; When this works properly, @g3 is placed in a separate chunk of merged globals.
+; CHECK: _MergedGlobals1:
+@g3 = internal global [30 x i32] [ i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10 ]