Convert not in dex input to xor with minus one if the not instruction cannot be used

Additional guard against inserting a not instructions if it cannot be used

Bug: 73601520
Change-Id: Ifa7e92560b0af7e43fa2f145ec7110e8952086d8
diff --git a/src/main/java/com/android/tools/r8/ir/code/Not.java b/src/main/java/com/android/tools/r8/ir/code/Not.java
index baf97f6..82840f8 100644
--- a/src/main/java/com/android/tools/r8/ir/code/Not.java
+++ b/src/main/java/com/android/tools/r8/ir/code/Not.java
@@ -52,6 +52,7 @@
 
   @Override
   public void buildDex(DexBuilder builder) {
+    assert builder.getOptions().canUseNotInstruction();
     com.android.tools.r8.code.Instruction instruction;
     int dest = builder.allocatedRegister(dest(), getNumber());
     int src = builder.allocatedRegister(source(), getNumber());
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java b/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
index 0a27017..08bdae8 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
@@ -1258,7 +1258,13 @@
   public void addNot(NumericType type, int dest, int value) {
     Value in = readNumericRegister(value, type);
     Value out = writeNumericRegister(dest, type, ThrowingInfo.NO_THROW);
-    Not instruction = new Not(type, out, in);
+    Instruction instruction;
+    if (options.canUseNotInstruction()) {
+      instruction = new Not(type, out, in);
+    } else {
+      Value minusOne = readLiteral(ValueType.fromNumericType(type), -1);
+      instruction = new Xor(type, out, in, minusOne);
+    }
     assert !instruction.instructionTypeCanThrow();
     addInstruction(instruction);
   }
@@ -1616,6 +1622,22 @@
     return readRegister(register, ValueType.fromNumericType(type));
   }
 
+  public Value readLiteral(ValueType type, long constant) {
+    if (type == ValueType.INT) {
+      return readIntLiteral(constant);
+    } else {
+      assert type == ValueType.LONG;
+      return readLongLiteral(constant);
+    }
+  }
+
+  public Value readLongLiteral(long constant) {
+    Value value = new Value(valueNumberGenerator.next(), ValueType.LONG, null);
+    ConstNumber number = new ConstNumber(value, constant);
+    add(number);
+    return number.outValue();
+  }
+
   public Value readIntLiteral(long constant) {
     Value value = new Value(valueNumberGenerator.next(), ValueType.INT, null);
     ConstNumber number = new ConstNumber(value, constant);