Fixed a bug introduced by my last commit: TargetGlobalValues should key on
GlobalValue * and index pair. Update getGlobalAddress() for symmetry.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24524 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h
index 2f9ffda..da6bec8 100644
--- a/include/llvm/CodeGen/SelectionDAG.h
+++ b/include/llvm/CodeGen/SelectionDAG.h
@@ -109,9 +109,10 @@
   SDOperand getConstant(uint64_t Val, MVT::ValueType VT);
   SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT);
   SDOperand getConstantFP(double Val, MVT::ValueType VT);
-  SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT);
+  SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
+                             int offset = 0);
   SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
-                                   int offset=0);
+                                   int offset = 0);
   SDOperand getFrameIndex(int FI, MVT::ValueType VT);
   SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT);
   SDOperand getConstantPool(Constant *C, MVT::ValueType VT);
@@ -399,8 +400,8 @@
   std::map<std::pair<SDOperand, std::pair<SDOperand, MVT::ValueType> >,
            SDNode *> Loads;
 
-  std::map<const GlobalValue*, SDNode*> GlobalValues;
-  std::map<const GlobalValue*, SDNode*> TargetGlobalValues;
+  std::map<std::pair<const GlobalValue*, int>, SDNode*> GlobalValues;
+  std::map<std::pair<const GlobalValue*, int>, SDNode*> TargetGlobalValues;
   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> Constants;
   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> TargetConstants;
   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> ConstantFPs;
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 606ed52..8aa2bc6 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -283,12 +283,18 @@
     Erased = CondCodeNodes[cast<CondCodeSDNode>(N)->get()] != 0;
     CondCodeNodes[cast<CondCodeSDNode>(N)->get()] = 0;
     break;
-  case ISD::GlobalAddress:
-    Erased = GlobalValues.erase(cast<GlobalAddressSDNode>(N)->getGlobal());
+  case ISD::GlobalAddress: {
+    GlobalAddressSDNode *GN = cast<GlobalAddressSDNode>(N);
+    Erased = GlobalValues.erase(std::make_pair(GN->getGlobal(),
+                                               GN->getOffset()));
     break;
-  case ISD::TargetGlobalAddress:
-    Erased =TargetGlobalValues.erase(cast<GlobalAddressSDNode>(N)->getGlobal());
+  }
+  case ISD::TargetGlobalAddress: {
+    GlobalAddressSDNode *GN = cast<GlobalAddressSDNode>(N);
+    Erased =TargetGlobalValues.erase(std::make_pair(GN->getGlobal(),
+                                                    GN->getOffset()));
     break;
+  }
   case ISD::FrameIndex:
     Erased = FrameIndices.erase(cast<FrameIndexSDNode>(N)->getIndex());
     break;
@@ -491,8 +497,8 @@
 
 
 SDOperand SelectionDAG::getGlobalAddress(const GlobalValue *GV,
-                                         MVT::ValueType VT) {
-  SDNode *&N = GlobalValues[GV];
+                                         MVT::ValueType VT, int offset) {
+  SDNode *&N = GlobalValues[std::make_pair(GV, offset)];
   if (N) return SDOperand(N, 0);
   N = new GlobalAddressSDNode(false, GV, VT);
   AllNodes.push_back(N);
@@ -501,7 +507,7 @@
 
 SDOperand SelectionDAG::getTargetGlobalAddress(const GlobalValue *GV,
                                                MVT::ValueType VT, int offset) {
-  SDNode *&N = TargetGlobalValues[GV];
+  SDNode *&N = TargetGlobalValues[std::make_pair(GV, offset)];
   if (N) return SDOperand(N, 0);
   N = new GlobalAddressSDNode(true, GV, VT, offset);
   AllNodes.push_back(N);