Improve argument register selection and debug info handling.

When allocating a register for an argument value split with no register
constraint, just use the original argument register.

For debug info, always use the original argument register for an
argument value. When we have splits we know that we have disallowed
argument register reuse and therefore the argument value is always
available in the original argument register.

R=zerny@google.com

Bug: 62186207
Change-Id: I1139213142e762d316a3eb2f3fcb52e8e0bdfe59
diff --git a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
index 7103abe..d15010f 100644
--- a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
+++ b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
@@ -238,7 +238,13 @@
         int end = liveRange.end;
         Integer nextEnd;
         while ((nextEnd = nextInRange(start, end, ends)) != null) {
-          ranges.add(new LocalRange(value, getRegisterForValue(value, start), start, nextEnd));
+          // If an argument value has been split, we have disallowed argument reuse and therefore,
+          // the argument value is also in the argument register throughout the method. For debug
+          // information, we always use the argument register whenever a local corresponds to an
+          // argument value. That avoids ending and restarting locals whenever we move arguments
+          // to lower register.
+          int register = getRegisterForValue(value, value.isArgument() ? 0 : start);
+          ranges.add(new LocalRange(value, register, start, nextEnd));
           Integer nextStart = nextInRange(nextEnd, end, starts);
           if (nextStart == null) {
             start = -1;
@@ -797,9 +803,6 @@
     maxRegisterNumber = Math.max(maxRegisterNumber, maxRegister);
   }
 
-  // Select a spill register.
-  // TODO(ager): At this point this always takes the next unused register number. We need a
-  // more intelligent selection of spill registers.
   private int getSpillRegister(LiveIntervals intervals) {
     int registerNumber = nextUnusedRegisterNumber++;
     maxRegisterNumber = registerNumber;
@@ -873,6 +876,18 @@
   private boolean allocateSingleInterval(LiveIntervals unhandledInterval, ArgumentReuseMode mode) {
     int registerConstraint = unhandledInterval.getRegisterLimit();
     assert registerConstraint <= Constants.U16BIT_MAX;
+
+    assert unhandledInterval.requiredRegisters() <= 2;
+    boolean needsRegisterPair = unhandledInterval.requiredRegisters() == 2;
+
+    // Just use the argument register if an argument split has no register constraint. That will
+    // avoid move generation for the argument.
+    if (registerConstraint == Constants.U16BIT_MAX && unhandledInterval.isArgumentInterval()) {
+      int argumentRegister = unhandledInterval.getSplitParent().getRegister();
+      assignRegisterToUnhandledInterval(unhandledInterval, needsRegisterPair, argumentRegister);
+      return true;
+    }
+
     if (registerConstraint < Constants.U16BIT_MAX) {
       // We always have argument sentinels that will not actually occupy registers. Therefore, we
       // allow the use of NUMBER_OF_SENTINEL_REGISTERS more than the limit.
@@ -952,8 +967,6 @@
       }
     }
 
-    assert unhandledInterval.requiredRegisters() <= 2;
-    boolean needsRegisterPair = unhandledInterval.requiredRegisters() == 2;
     // Attempt to use register hints.
     if (useRegisterHint(unhandledInterval, registerConstraint, freePositions, needsRegisterPair)) {
       return true;