[SeparateConstOffsetFromGEP] Fixed a bug related to unsigned modulo
[oota-llvm.git] / lib / Transforms / Scalar / MergedLoadStoreMotion.cpp
index a10733952be46988e8587c098cd262ac03216847..dad62fa26f99e344ae12467b5af0567e20959863 100644 (file)
 //
 //            header:
 //                     br %cond, label %if.then, label %if.else
-//                        /                    \
-//                       /                      \
-//                      /                        \
+//                        +                    +
+//                       +                      +
+//                      +                        +
 //            if.then:                         if.else:
 //               %lt = load %addr_l               %le = load %addr_l
 //               <use %lt>                        <use %le>
 //               <...>                            <...>
 //               store %st, %addr_s               store %se, %addr_s
 //               br label %if.end                 br label %if.end
-//                     \                         /
-//                      \                       /
-//                       \                     /
+//                     +                         +
+//                      +                       +
+//                       +                     +
 //            if.end ("footer"):
 //                     <...>
 //
 //            header:
 //                     %l = load %addr_l
 //                     br %cond, label %if.then, label %if.else
-//                        /                    \
-//                       /                      \
-//                      /                        \
+//                        +                    +
+//                       +                      +
+//                      +                        +
 //            if.then:                         if.else:
 //               <use %l>                         <use %l>
 //               <...>                            <...>
 //               br label %if.end                 br label %if.end
-//                      \                        /
-//                       \                      /
-//                        \                    /
+//                      +                        +
+//                       +                      +
+//                        +                    +
 //            if.end ("footer"):
 //                     %s.sink = phi [%st, if.then], [%se, if.else]
 //                     <...>
@@ -97,9 +97,6 @@ using namespace llvm;
 //===----------------------------------------------------------------------===//
 //                         MergedLoadStoreMotion Pass
 //===----------------------------------------------------------------------===//
-static cl::opt<bool>
-EnableMLSM("mlsm", cl::desc("Enable motion of merged load and store"),
-           cl::init(true));
 
 namespace {
 class MergedLoadStoreMotion : public FunctionPass {
@@ -108,7 +105,8 @@ class MergedLoadStoreMotion : public FunctionPass {
 
 public:
   static char ID; // Pass identification, replacement for typeid
-  explicit MergedLoadStoreMotion(void) : FunctionPass(ID), MD(nullptr) {
+  explicit MergedLoadStoreMotion(void)
+      : FunctionPass(ID), MD(nullptr), MagicCompileTimeControl(250) {
     initializeMergedLoadStoreMotionPass(*PassRegistry::getPassRegistry());
   }
 
@@ -150,7 +148,7 @@ private:
   // where Size0 and Size1 are the #instructions on the two sides of
   // the diamond. The constant chosen here is arbitrary. Compiler Time
   // Control is enforced by the check Size0 * Size1 < MagicCompileTimeControl.
-  const int MagicCompileTimeControl = 250;
+  const int MagicCompileTimeControl;
 };
 
 char MergedLoadStoreMotion::ID = 0;
@@ -242,6 +240,10 @@ bool MergedLoadStoreMotion::isLoadHoistBarrier(Instruction *Inst) {
     return true;
   if (isa<TerminatorInst>(Inst))
     return true;
+  // FIXME: Conservatively let a store instruction block the load.
+  // Use alias analysis instead.
+  if (isa<StoreInst>(Inst))
+    return true;
   // Note: mayHaveSideEffects covers all instructions that could
   // trigger a change to state. Eg. in-flight stores have to be executed
   // before ordered loads or fences, calls could invoke functions that store
@@ -410,8 +412,12 @@ bool MergedLoadStoreMotion::mergeLoads(BasicBlock *BB) {
 
 ///
 /// \brief True when instruction is sink barrier for a store
-///
+/// 
 bool MergedLoadStoreMotion::isStoreSinkBarrier(Instruction *Inst) {
+  // FIXME: Conservatively let a load instruction block the store.
+  // Use alias analysis instead.
+  if (isa<LoadInst>(Inst))
+    return true;
   if (isa<CallInst>(Inst))
     return true;
   if (isa<TerminatorInst>(Inst) && !isa<BranchInst>(Inst))
@@ -602,8 +608,6 @@ bool MergedLoadStoreMotion::runOnFunction(Function &F) {
   AA = &getAnalysis<AliasAnalysis>();
 
   bool Changed = false;
-  if (!EnableMLSM)
-    return false;
   DEBUG(dbgs() << "Instruction Merger\n");
 
   // Merge unconditional branches, allowing PRE to catch more
@@ -613,7 +617,6 @@ bool MergedLoadStoreMotion::runOnFunction(Function &F) {
 
     // Hoist equivalent loads and sink stores
     // outside diamonds when possible
-    // Run outside core GVN
     if (isDiamondHead(BB)) {
       Changed |= mergeLoads(BB);
       Changed |= mergeStores(getDiamondTail(BB));