diff --git a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
index 642202bf055adcf534b7f1b44b3ab71858347ecb..ba8a371c9a8a2ab90a4848f90b1e9be97f758fc4 100644
--- a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
+++ b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
@@ -1513,7 +1513,7 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
   // have assumed theworst memory behaviour for these function calls
   // Traverse the vector backwards, otherwise definitions are deleted while
   // their subsequent uses are still around
-  for (auto *I : IItoRemove) {
+  for (auto *I : reverse(IItoRemove)) {
     DEBUG(errs() << "Erasing: " << *I << "\n");
     I->eraseFromParent();
   }