Remove redundant debug positions before numbering instructions

Change-Id: I94a9d24b67bc2e7ad7120a46d2dc7483c7a55135
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/DexBuilder.java b/src/main/java/com/android/tools/r8/ir/conversion/DexBuilder.java
index a6e556d..7803adc 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/DexBuilder.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/DexBuilder.java
@@ -182,13 +182,13 @@
       // large for the if encoding.
       rewriteIfs();
 
-      // Reset the state of the builder to start from scratch.
-      reset();
-
       // Remove redundant debug position instructions. They would otherwise materialize as
       // unnecessary nops.
       removeRedundantDebugPositions(ir);
 
+      // Reset the state of the builder to start from scratch.
+      reset();
+
       // Populate the builder info objects.
       numberOfInstructions = 0;
 
@@ -667,10 +667,12 @@
 
   // Helper used by the info objects.
   private Info getInfo(com.android.tools.r8.ir.code.Instruction instruction) {
+    assert instruction.getNumber() >= 0;
     return instructionToInfo[instructionNumberToIndex(instruction.getNumber())];
   }
 
   private void setInfo(com.android.tools.r8.ir.code.Instruction instruction, Info info) {
+    assert instruction.getNumber() >= 0;
     if (!(info instanceof FallThroughInfo)) {
       previousNonFallthroughInfo = info;
     }