Merge "Remove useless debug positions before register allocator"
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/IRConverter.java b/src/main/java/com/android/tools/r8/ir/conversion/IRConverter.java
index 8e5b26f..c67e229 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/IRConverter.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/IRConverter.java
@@ -559,12 +559,16 @@
     // Always perform dead code elimination before register allocation. The register allocator
     // does not allow dead code (to make sure that we do not waste registers for unneeded values).
     DeadCodeRemover.removeDeadCode(code, codeRewriter, options);
+    if (!options.debug) {
+      // Remove unneeded debug positions before register allocation to avoid to process useless
+      // instructions. These is safe because the register allocator can not generate new
+      // instructions that will throw exceptions and thus apply removedUnneededDebugPositions before
+      // register allocator will produce the same result.
+      CodeRewriter.removedUnneededDebugPositions(code);
+    }
     LinearScanRegisterAllocator registerAllocator = new LinearScanRegisterAllocator(code, options);
     registerAllocator.allocateRegisters(options.debug);
     printMethod(code, "After register allocation (non-SSA)");
-    if (!options.debug) {
-      CodeRewriter.removedUnneededDebugPositions(code);
-    }
     for (int i = 0; i < PEEPHOLE_OPTIMIZATION_PASSES; i++) {
       CodeRewriter.collapsTrivialGotos(method, code);
       PeepholeOptimizer.optimize(code, registerAllocator);