Add a target hook to allow loads from constant pools to be rematerialized, and an
implementation for x86.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37576 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp
index eadd47b..aae27bb 100644
--- a/lib/CodeGen/LiveIntervalAnalysis.cpp
+++ b/lib/CodeGen/LiveIntervalAnalysis.cpp
@@ -336,12 +336,14 @@
   // time we see a vreg.
   if (interval.empty()) {
     // Remember if the definition can be rematerialized. All load's from fixed
-    // stack slots are re-materializable.
+    // stack slots are re-materializable. The target may permit other loads to
+    // be re-materialized as well.
     int FrameIdx = 0;
     if (vi.DefInst &&
         (tii_->isReMaterializable(vi.DefInst->getOpcode()) ||
          (tii_->isLoadFromStackSlot(vi.DefInst, FrameIdx) &&
-          mf_->getFrameInfo()->isFixedObjectIndex(FrameIdx))))
+          mf_->getFrameInfo()->isFixedObjectIndex(FrameIdx)) ||
+         tii_->isOtherReMaterializableLoad(vi.DefInst)))
       interval.remat = vi.DefInst;
 
     // Get the Idx of the defining instructions.
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp
index 9ae38ac..95453b0 100644
--- a/lib/CodeGen/VirtRegMap.cpp
+++ b/lib/CodeGen/VirtRegMap.cpp
@@ -664,7 +664,8 @@
     // If this instruction is being rematerialized, just remove it!
     int FrameIdx;
     if ((TID->Flags & M_REMATERIALIZIBLE) ||
-        TII->isLoadFromStackSlot(&MI, FrameIdx)) {
+        TII->isLoadFromStackSlot(&MI, FrameIdx) ||
+        TII->isOtherReMaterializableLoad(&MI)) {
       bool Remove = true;
       for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
         MachineOperand &MO = MI.getOperand(i);