diff --git a/hpvm/lib/Transforms/Utils/HPVMLoopTransforms.cpp b/hpvm/lib/Transforms/Utils/HPVMLoopTransforms.cpp
index bceb967dc7d22d7e5dd3a97d15c541431b210c0a..083fe374b230bc482afd6cdf9b47e8afe7d863f1 100644
--- a/hpvm/lib/Transforms/Utils/HPVMLoopTransforms.cpp
+++ b/hpvm/lib/Transforms/Utils/HPVMLoopTransforms.cpp
@@ -1270,7 +1270,8 @@ void hpvm::unrollLoopByCount(Loop *L, LoopInfo &LI, DominatorTree &DT,
 
     // Without this, SE performs no extra analysis and can't determine the
     // recurrence for the induction variable, needed in updateNZLoop
-    SE.forgetLoop(L);
+    if (!L->isInvalid())
+      SE.forgetLoop(L);
 
     if (_AllowRuntime && (_TripCount > 0))
       updateNZLoop(L, LI, SE, F, _Count);