GlobalOpt does not treat externally_initialized globals correctly
[oota-llvm.git] / lib / Transforms / Utils / GlobalStatus.cpp
index 44b7d25d519a166349ccb5494fa9a0afc3218e06..3893a752503b6b63600edd6ddd6b7b56461054b5 100644 (file)
@@ -49,6 +49,10 @@ bool llvm::isSafeToDestroyConstant(const Constant *C) {
 
 static bool analyzeGlobalAux(const Value *V, GlobalStatus &GS,
                              SmallPtrSetImpl<const PHINode *> &PhiUsers) {
+  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
+    if (GV->isExternallyInitialized())
+      GS.StoredType = GlobalStatus::StoredOnce;
+
   for (const Use &U : V->uses()) {
     const User *UR = U.getUser();
     if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(UR)) {