DAGCombiner: Assume invariant load cannot alias a store
[oota-llvm.git] / lib / CodeGen / SelectionDAG / DAGCombiner.cpp
index e05714342d211301486150475234ec9cd29d4eb8..52d620b1d540fc5958cf7cc8d63c645c6bea8203 100644 (file)
@@ -13844,6 +13844,15 @@ bool DAGCombiner::isAlias(LSBaseSDNode *Op0, LSBaseSDNode *Op1) const {
   // If they are both volatile then they cannot be reordered.
   if (Op0->isVolatile() && Op1->isVolatile()) return true;
 
+  // If one operation reads from invariant memory, and the other may store, they
+  // cannot alias. These should really be checking the equivalent of mayWrite,
+  // but it only matters for memory nodes other than load /store.
+  if (Op0->isInvariant() && Op1->writeMem())
+    return false;
+
+  if (Op1->isInvariant() && Op0->writeMem())
+    return false;
+
   // Gather base node and offset information.
   SDValue Base1, Base2;
   int64_t Offset1, Offset2;