Fix a bug in heap-sra that caused compilation failure of office-ispell.
authorChris Lattner <sabre@nondot.org>
Tue, 9 Jan 2007 23:29:37 +0000 (23:29 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 9 Jan 2007 23:29:37 +0000 (23:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33043 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/GlobalOpt.cpp

index e17ded82d92fc3d985ee0c0dc24320430635b491..f25621eb78cce1c47ac3a35ff60a8c7ad804eb27 100644 (file)
@@ -1016,9 +1016,25 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI){
   // loads, and all uses of those loads are simple.  Rewrite them to use loads
   // of the per-field globals instead.
   while (!GV->use_empty()) {
-    LoadInst *LI = cast<LoadInst>(GV->use_back());
-    RewriteUsesOfLoadForHeapSRoA(LI, FieldGlobals);
-    LI->eraseFromParent();
+    if (LoadInst *LI = dyn_cast<LoadInst>(GV->use_back())) {
+      RewriteUsesOfLoadForHeapSRoA(LI, FieldGlobals);
+      LI->eraseFromParent();
+    } else {
+      // Must be a store of null.
+      StoreInst *SI = cast<StoreInst>(GV->use_back());
+      assert(isa<Constant>(SI->getOperand(0)) &&
+             cast<Constant>(SI->getOperand(0))->isNullValue() &&
+             "Unexpected heap-sra user!");
+      
+      // Insert a store of null into each global.
+      for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
+        Constant *Null = 
+          Constant::getNullValue(FieldGlobals[i]->getType()->getElementType());
+        new StoreInst(Null, FieldGlobals[i], SI);
+      }
+      // Erase the original store.
+      SI->eraseFromParent();
+    }
   }
 
   // The old global is now dead, remove it.