Index: lib/Analysis/LiveVariables.cpp
===================================================================
--- lib/Analysis/LiveVariables.cpp	(revision 215205)
+++ lib/Analysis/LiveVariables.cpp	(working copy)
@@ -450,19 +450,17 @@
 
   // Construct the dataflow worklist.  Enqueue the exit block as the
   // start of the analysis.
-  DataflowWorklist worklist(*cfg, AC);
+  DataflowWorklistInverse worklist(*cfg, AC);
   llvm::BitVector everAnalyzedBlock(cfg->getNumBlockIDs());
+  llvm::BitVector scannedForAssignments(cfg->getNumBlockIDs());
 
-  // FIXME: we should enqueue using post order.
-  for (CFG::const_iterator it = cfg->begin(), ei = cfg->end(); it != ei; ++it) {
-    const CFGBlock *block = *it;
-    worklist.enqueueBlock(block);
+  while (const CFGBlock *block = worklist.dequeue()) {
     
     // FIXME: Scan for DeclRefExprs using in the LHS of an assignment.
     // We need to do this because we lack context in the reverse analysis
     // to determine if a DeclRefExpr appears in such a context, and thus
     // doesn't constitute a "use".
-    if (killAtAssign)
+    if (killAtAssign && !scannedForAssignments[block->getBlockID()]) {
       for (CFGBlock::const_iterator bi = block->begin(), be = block->end();
            bi != be; ++bi) {
         if (Optional<CFGStmt> cs = bi->getAs<CFGStmt>()) {
@@ -477,11 +475,9 @@
           }
         }
       }
-  }
+      scannedForAssignments[block->getBlockID()] = true;
+    }
   
-  worklist.sortWorklist();
-  
-  while (const CFGBlock *block = worklist.dequeue()) {
     // Determine if the block's end value has changed.  If not, we
     // have nothing left to do for this block.
     LivenessValues &prevVal = LV->blocksEndToLiveness[block];
Index: lib/Analysis/PostOrderCFGView.cpp
===================================================================
--- lib/Analysis/PostOrderCFGView.cpp	(revision 215205)
+++ lib/Analysis/PostOrderCFGView.cpp	(working copy)
@@ -47,3 +47,51 @@
   return b1V > b2V;
 }
 
+// In this implementation, po_iterator is overridden for the inverse order.
+PostOrderInverseCFGView::PostOrderInverseCFGView(const CFG *cfg) {
+  unsigned size = cfg->getNumBlockIDs();
+  Blocks.reserve(size);
+  CFGBlockSet BSet(cfg);
+    
+  for (po_iterator I = po_iterator::begin(cfg, BSet),
+                   E = po_iterator::end(cfg, BSet); I != E; ++I) {
+    BlockOrder[*I] = Blocks.size() + 1;
+    Blocks.push_back(*I);      
+  }
+
+  // It may be that some blocks are inaccessible going from the CFG exit upwards
+  // (e.g. infinite loops); we still need to add them.
+  while (Blocks.size() < size) {
+    // Find a block that we skipped
+    CFG::const_iterator I = cfg->begin(), E = cfg->end();
+    for (; I != E; ++I)
+      if (!BlockOrder.count(*I))
+        break;
+    assert(I != E);
+    const CFGBlock* block = *I;
+    // Add a chain going upwards
+    while (!BlockOrder.count(block)) {
+      BlockOrder[block] = Blocks.size() + 1;
+      Blocks.push_back(block);
+      CFGBlock::const_pred_iterator PI = block->pred_begin(),
+                                    PE = block->pred_end();
+      for (; PI != PE; ++PI) {
+        const CFGBlock* pred = *PI;
+        if (pred && !BlockOrder.count(pred)) {
+          block = pred;
+          break;
+        }
+      }
+      // Chain ends when we couldn't find an unmapped pred
+      if (PI == PE) break;
+    }
+  }
+}
+
+PostOrderInverseCFGView *
+PostOrderInverseCFGView::create(AnalysisDeclContext &ctx) {
+  const CFG *cfg = ctx.getCFG();
+  if (!cfg)
+    return nullptr;
+  return new PostOrderInverseCFGView(cfg);
+}
Index: lib/Analysis/DataflowWorklist.cpp
===================================================================
--- lib/Analysis/DataflowWorklist.cpp	(revision 215205)
+++ lib/Analysis/DataflowWorklist.cpp	(working copy)
@@ -21,14 +21,14 @@
 // that's not because everything is added initially to the worklist,
 // but instead, to cause the forward analysis to follow the reverse post order
 // until we enqueue something on the worklist. 
-void DataflowWorklist::enqueueBlock(const clang::CFGBlock *block) {
+void DataflowWorklistBase::enqueueBlock(const clang::CFGBlock *block) {
   if (block && !enqueuedBlocks[block->getBlockID()]) {
     enqueuedBlocks[block->getBlockID()] = true;
     worklist.push_back(block);
   }
 }
 
-// The forward analysis alternates between essentially two worklists.
+// The analysis alternates between essentially two worklists.
 // A prioritization worklist (SmallVector<const CFGBlock *> worklist)
 // is consulted first, and if it's empty, we consult the reverse
 // post-order traversal (PostOrderCFGView::iterator PO_I).
@@ -38,32 +38,21 @@
 // we want to prioritize analyzing first, because that causes dataflow facts
 // to flow up the graph, which we then want to propagate forward.
 // In practice this can cause the analysis to converge much faster.  
-void DataflowWorklist::enqueueSuccessors(const clang::CFGBlock *block) {
+void DataflowWorklistBase::enqueueSuccessors(const clang::CFGBlock *block) {
   for (CFGBlock::const_succ_iterator I = block->succ_begin(),
        E = block->succ_end(); I != E; ++I) {
     enqueueBlock(*I);
   }
 }
 
-// The reverse analysis uses a simple re-sorting of the worklist to
-// reprioritize it.  It's not as efficient as the two-worklists approach,
-// but it isn't performance sensitive since it's used by the static analyzer,
-// and the static analyzer does far more work that dwarfs the work done here.
-// TODO: It would still be nice to use the same approach for both analyses.
-void DataflowWorklist::enqueuePredecessors(const clang::CFGBlock *block) {
-  const unsigned OldWorklistSize = worklist.size();
+void DataflowWorklistBase::enqueuePredecessors(const clang::CFGBlock *block) {
   for (CFGBlock::const_pred_iterator I = block->pred_begin(),
        E = block->pred_end(); I != E; ++I) {
     enqueueBlock(*I);
   }
-
-  if (OldWorklistSize == 0 || OldWorklistSize == worklist.size())
-    return;
-
-  sortWorklist();
 }
 
-const CFGBlock *DataflowWorklist::dequeue() {
+const CFGBlock *DataflowWorklistBase::dequeue() {
   const CFGBlock *B = nullptr;
 
   // First dequeue from the worklist.  This can represent
@@ -86,7 +75,3 @@
   return B;
 }
 
-void DataflowWorklist::sortWorklist() {
-  std::sort(worklist.begin(), worklist.end(), comparator);
-}
-
Index: include/clang/Analysis/Analyses/PostOrderCFGView.h
===================================================================
--- include/clang/Analysis/Analyses/PostOrderCFGView.h	(revision 215205)
+++ include/clang/Analysis/Analyses/PostOrderCFGView.h	(working copy)
@@ -70,6 +70,8 @@
 
 private:
   typedef llvm::po_iterator<const CFG*, CFGBlockSet, true>  po_iterator;
+
+protected:
   std::vector<const CFGBlock*> Blocks;
 
   typedef llvm::DenseMap<const CFGBlock *, unsigned> BlockOrderTy;
@@ -107,8 +109,21 @@
   static const void *getTag();
 
   static PostOrderCFGView *create(AnalysisDeclContext &analysisContext);
+
+protected:
+  PostOrderCFGView() {}
 };
 
+class PostOrderInverseCFGView : public PostOrderCFGView {
+  typedef llvm::po_iterator<const CFG*, CFGBlockSet, true,
+                            llvm::GraphTraits<llvm::Inverse<const CFG*> >
+                           > po_iterator;
+
+public:
+  PostOrderInverseCFGView(const CFG *cfg);
+  static PostOrderInverseCFGView *create(AnalysisDeclContext &analysisContext);
+};
+
 } // end clang namespace
 
 #endif
Index: include/clang/Analysis/Analyses/DataflowWorklist.h
===================================================================
--- include/clang/Analysis/Analyses/DataflowWorklist.h	(revision 215205)
+++ include/clang/Analysis/Analyses/DataflowWorklist.h	(working copy)
@@ -10,7 +10,7 @@
 // DataflowWorklist keeps track of blocks for dataflow analysis. It maintains a
 // vector of blocks for priority processing, and falls back upon a reverse
 // post-order iterator. It supports both forward (used in UninitializedValues)
-// and reverse (used in LiveVariables) analyses.
+// and inverse (used in LiveVariables) analyses.
 //
 //===----------------------------------------------------------------------===//
 
@@ -24,37 +24,38 @@
 class DataflowWorklistBase {
 protected:
   PostOrderCFGView::iterator PO_I, PO_E;
-  PostOrderCFGView::BlockOrderCompare comparator;
   SmallVector<const CFGBlock *, 20> worklist;
   llvm::BitVector enqueuedBlocks;
 
   DataflowWorklistBase(const CFG &cfg, PostOrderCFGView &view)
     : PO_I(view.begin()), PO_E(view.end()),
-      comparator(view.getComparator()),
       enqueuedBlocks(cfg.getNumBlockIDs(), true) {
-        // Treat the first block as already analyzed.
-        if (PO_I != PO_E) {
-          assert(*PO_I == &cfg.getEntry());
+        // For forward analysis, treat the first block as already analyzed.
+        if ((PO_I != PO_E) && (*PO_I == &cfg.getEntry())) {
           enqueuedBlocks[(*PO_I)->getBlockID()] = false;
           ++PO_I;
         }
       }
-};
 
-class DataflowWorklist : DataflowWorklistBase {
-
 public:
-  DataflowWorklist(const CFG &cfg, AnalysisDeclContext &Ctx)
-    : DataflowWorklistBase(cfg, *Ctx.getAnalysis<PostOrderCFGView>()) {}
-
   void enqueueBlock(const CFGBlock *block);
   void enqueuePredecessors(const CFGBlock *block);
   void enqueueSuccessors(const CFGBlock *block);
   const CFGBlock *dequeue();
+};
 
-  void sortWorklist();
+class DataflowWorklist : public DataflowWorklistBase {
+public:
+  DataflowWorklist(const CFG &cfg, AnalysisDeclContext &Ctx)
+    : DataflowWorklistBase(cfg, *Ctx.getAnalysis<PostOrderCFGView>()) {}
 };
 
+class DataflowWorklistInverse : public DataflowWorklistBase {
+public:
+  DataflowWorklistInverse(const CFG &cfg, AnalysisDeclContext &Ctx)
+    : DataflowWorklistBase(cfg, *Ctx.getAnalysis<PostOrderInverseCFGView>()) {}
+};
+
 } // end clang namespace
 
 #endif
