mem-cache: Fixed a bug in MRU replacement policy

The lastTouchTick is set to 0 when instantiate. This will cause the
candidate[0] to get evicted over and over again in MRU replacement
policy. To resolve this, break the search loop whenever it finds a
cold cache line.

Change-Id: I33aa57ebe0efca15986f62c3ae10a146bd2b779f
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20881
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Matt Sinclair <mattdsinclair@gmail.com>
diff --git a/src/mem/cache/replacement_policies/mru_rp.cc b/src/mem/cache/replacement_policies/mru_rp.cc
index b2e019f..534fb52 100644
--- a/src/mem/cache/replacement_policies/mru_rp.cc
+++ b/src/mem/cache/replacement_policies/mru_rp.cc
@@ -74,9 +74,14 @@
     // Visit all candidates to find victim
     ReplaceableEntry* victim = candidates[0];
     for (const auto& candidate : candidates) {
-        // Update victim entry if necessary
-        if (std::static_pointer_cast<MRUReplData>(
-                    candidate->replacementData)->lastTouchTick >
+        std::shared_ptr<MRUReplData> candidate_replacement_data =
+            std::static_pointer_cast<MRUReplData>(candidate->replacementData);
+
+        // Stop searching entry if a cache line that doesn't warm up is found.
+        if (candidate_replacement_data->lastTouchTick == 0) {
+            victim = candidate;
+            break;
+        } else if (candidate_replacement_data->lastTouchTick >
                 std::static_pointer_cast<MRUReplData>(
                     victim->replacementData)->lastTouchTick) {
             victim = candidate;