Follow-up 769ebcd1bdcf4393e5e25e8c75abbf2dd777fdc0

Visits instructions at the block level instead of the code level and
makes the method 'hasLineChangeBetween' static.

Also reorder conditions to mitigate the cost of detecting line
changes.

Bug: 67454184
Change-Id: Ib1adf9e6225d2cf97c6249fd1107e812fe37904c
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
index 770ac3a..fd3e433 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
@@ -1373,7 +1373,7 @@
   }
 
   // TODO(mikaelpeltier) Manage that from and to instruction do not belong to the same block.
-  private boolean hasLineChangeBetween(Instruction from, Instruction to) {
+  private static boolean hasLineChangeBetween(Instruction from, Instruction to) {
     if (from.getBlock() != to.getBlock()) {
       return true;
     }
@@ -1411,23 +1411,23 @@
           }
         }
       }
-    }
 
-    InstructionIterator iterator = code.instructionIterator();
-    while (iterator.hasNext()) {
-      Instruction instruction = iterator.next();
-      if (instruction.isDebugLocalWrite()) {
-        assert instruction.inValues().size() == 1;
-        Value inValue = instruction.inValues().get(0);
-        if (inValue.definition != null &&
-            !hasLineChangeBetween(inValue.definition, instruction) &&
-            !inValue.hasLocalInfo() &&
-            inValue.numberOfAllUsers() == 1) {
-          inValue.setLocalInfo(instruction.outValue().getLocalInfo());
-          instruction.moveDebugValues(inValue.definition);
-          instruction.outValue().replaceUsers(inValue);
-          instruction.clearDebugValues();
-          iterator.remove();
+      InstructionIterator iterator = block.iterator();
+      while (iterator.hasNext()) {
+        Instruction instruction = iterator.next();
+        if (instruction.isDebugLocalWrite()) {
+          assert instruction.inValues().size() == 1;
+          Value inValue = instruction.inValues().get(0);
+          if (!inValue.hasLocalInfo() &&
+              inValue.numberOfAllUsers() == 1 &&
+              inValue.definition != null &&
+              !hasLineChangeBetween(inValue.definition, instruction)) {
+            inValue.setLocalInfo(instruction.outValue().getLocalInfo());
+            instruction.moveDebugValues(inValue.definition);
+            instruction.outValue().replaceUsers(inValue);
+            instruction.clearDebugValues();
+            iterator.remove();
+          }
         }
       }
     }