add a validity check that was missed, fixing a crash on the
new testcase.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122662 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index 9878a2e..8c78803 100644
--- a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -234,6 +234,11 @@
 processLoopStoreOfSplatValue(StoreInst *SI, unsigned StoreSize,
                              Value *SplatValue,
                              const SCEVAddRecExpr *Ev, const SCEV *BECount) {
+  // Verify that the stored value is loop invariant.  If not, we can't promote
+  // the memset.
+  if (!CurLoop->isLoopInvariant(SplatValue))
+    return false;
+  
   // Temporarily remove the store from the loop, to avoid the mod/ref query from
   // seeing it.
   Instruction *InstAfterStore = ++BasicBlock::iterator(SI);