diff --git a/src/base/SMPBasicBlock.cpp b/src/base/SMPBasicBlock.cpp
index 5f36c7fc4ff759db1a1d402b2b51c4c7bab9bf40..2771b4661ebf37ef6d9b82a649f19d55ba42be12 100644
--- a/src/base/SMPBasicBlock.cpp
+++ b/src/base/SMPBasicBlock.cpp
@@ -6010,6 +6010,7 @@ bool SMPBasicBlock::IsDefUsedInUnsafeMemWrite(list<pair<pair<STARSOpndTypePtr, i
 	return true;
 #else
 	bool FoundMemWriteUse = false;
+	bool InvariantDEF = false;
 	assert(DefOp->IsRegOp());
 	if (!(this->IsProcessed())) {
 		this->SetProcessed(true);
@@ -6025,6 +6026,10 @@ bool SMPBasicBlock::IsDefUsedInUnsafeMemWrite(list<pair<pair<STARSOpndTypePtr, i
 		}
 		else {
 			InstIter = this->GetInstIterFromAddr(DefAddr);
+			SMPInstr *DefInst = (*InstIter);
+			set<DefOrUse, LessDefUse>::iterator DefIter = DefInst->FindDef(DefOp);
+			assert(DefIter != DefInst->GetLastDef());
+			InvariantDEF = DefIter->IsInvariantForAllLoops();
 			++InstIter;
 		}
 		while (InstIter != this->GetLastInst()) {
@@ -6041,7 +6046,7 @@ bool SMPBasicBlock::IsDefUsedInUnsafeMemWrite(list<pair<pair<STARSOpndTypePtr, i
 				STARSOpndTypePtr NewDefOp = DefIter->GetOp();
 				assert(nullptr != NewDefOp);
 #if 1
-				bool DangerousWrite = CurrInst->IsUnsafeMemWrite();
+				bool DangerousWrite = (!InvariantDEF) && CurrInst->IsUnsafeMemWrite();
 #else
 				bool DangerousWrite = CurrInst->HasDestMemoryOperand();
 				if (DangerousWrite) {
diff --git a/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id
index 888a04566d717b98a8a380070684fa69593209b4..a32081bdc006a199083af1a08267df24a8bedbc4 100644
--- a/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id
+++ b/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id
@@ -1 +1 @@
-cc0231bd87f595a3cbb8158cd581363bb6e25cff
\ No newline at end of file
+c1ce9a28bae332d56f8b2632e733683802430009
\ No newline at end of file
diff --git a/tests/commit/trimmed-sorted-save-ffmpeg.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-ffmpeg.psexe.annot.REMOVED.git-id
index 66fa65bfbc05f1e74fa82658be39937bb829df0e..317b58c7214302a90b1cb7dd334328c2b44431b4 100644
--- a/tests/commit/trimmed-sorted-save-ffmpeg.psexe.annot.REMOVED.git-id
+++ b/tests/commit/trimmed-sorted-save-ffmpeg.psexe.annot.REMOVED.git-id
@@ -1 +1 @@
-cca5a06f533d5be15cc392a41d1b6632da134bda
\ No newline at end of file
+923578564814ffb4d04bdd98c8f50ae5913099ee
\ No newline at end of file
diff --git a/tests/commit/trimmed-sorted-save-gimp.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-gimp.psexe.annot.REMOVED.git-id
index 78d399e922a090889a510ce8558cf4110872ac3b..3c15ebfa925daacd7c24d43d745899f03f1edd77 100644
--- a/tests/commit/trimmed-sorted-save-gimp.psexe.annot.REMOVED.git-id
+++ b/tests/commit/trimmed-sorted-save-gimp.psexe.annot.REMOVED.git-id
@@ -1 +1 @@
-a302870b39df70affe3181870555860f054d30bc
\ No newline at end of file
+1bbceddf6fb9b7e1e29612686a4f8dae55668624
\ No newline at end of file
diff --git a/tests/commit/trimmed-sorted-save-gnome-calculator.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-gnome-calculator.psexe.annot.REMOVED.git-id
index c7db4ff3b38ffe09220649c9163e9f4dc89aa563..a5e1673e05968773c8e8c123f91af185b9091a4e 100644
--- a/tests/commit/trimmed-sorted-save-gnome-calculator.psexe.annot.REMOVED.git-id
+++ b/tests/commit/trimmed-sorted-save-gnome-calculator.psexe.annot.REMOVED.git-id
@@ -1 +1 @@
-b022d794ff6109eee9e2d8f9413acf0c4aeef019
\ No newline at end of file
+050d480af91f2aff5a61e00f2a8d3f58afb58c11
\ No newline at end of file
diff --git a/tests/commit/trimmed-sorted-save-nginx.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-nginx.psexe.annot.REMOVED.git-id
index a667d8c3d756f0289f79ee7fbf2b707967541dc2..09b171f2a942d850c9721d5b603cbdd7c8170319 100644
--- a/tests/commit/trimmed-sorted-save-nginx.psexe.annot.REMOVED.git-id
+++ b/tests/commit/trimmed-sorted-save-nginx.psexe.annot.REMOVED.git-id
@@ -1 +1 @@
-871af1cc2b6a60b2d15b16c8ec0eef69923836b2
\ No newline at end of file
+304040fb5138645d8f4e7694eebede27fc7a0053
\ No newline at end of file