Do not interpretat -dontoptimize as a global keep rule

Bug: 189806230
Change-Id: If97153ee59481cc186c9081c326856ca6c0eb828
diff --git a/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java b/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
index 6d3a8ca..de0cc2c 100644
--- a/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
+++ b/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
@@ -378,14 +378,14 @@
         // For Proguard -keepattributes are only applicable when obfuscating.
         keepAttributePatterns.addAll(ProguardKeepAttributes.KEEP_ALL);
       }
-      // If either of the flags -dontshrink, -dontobfuscate or -dontoptimize is passed, or
-      // shrinking or minification is turned off through the API, then add a match all rule
-      // which will apply that.
-      if (!isShrinking() || !isObfuscating() || !isOptimizing()) {
+      // If either of the flags -dontshrink or -dontobfuscate, or shrinking or minification is
+      // turned off through the API, then add a match all rule which will apply that.
+      if (!isShrinking() || !isObfuscating()) {
         ProguardKeepRule rule =
             ProguardKeepRule.defaultKeepAllRule(
                 modifiers -> {
                   modifiers.setAllowsShrinking(isShrinking());
+                  // TODO(b/189807246): This should be removed.
                   modifiers.setAllowsOptimization(isOptimizing());
                   modifiers.setAllowsObfuscation(isObfuscating());
                 });
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/MemberValuePropagationTest.java b/src/test/java/com/android/tools/r8/ir/optimize/MemberValuePropagationTest.java
index e5746ec..5dd3140 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/MemberValuePropagationTest.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/MemberValuePropagationTest.java
@@ -12,7 +12,6 @@
 import com.android.tools.r8.utils.FileUtils;
 import com.android.tools.r8.utils.codeinspector.ClassSubject;
 import com.android.tools.r8.utils.codeinspector.CodeInspector;
-import com.android.tools.r8.utils.codeinspector.InstructionSubject;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.List;
@@ -62,14 +61,15 @@
   public void testWriteOnlyField_dontoptimize() throws Exception {
     CodeInspector inspector = runR8(DONT_OPTIMIZE);
     ClassSubject clazz = inspector.clazz(QUALIFIED_CLASS_NAME);
-    // With the support of 'allowshrinking' dontoptimize will now effectively pin all
-    // items that are not tree shaken out. The field operations will thus remain.
-    assertTrue(clazz.clinit().streamInstructions().anyMatch(InstructionSubject::isStaticPut));
-    assertTrue(
-        clazz
-            .uniqueInstanceInitializer()
-            .streamInstructions()
-            .anyMatch(InstructionSubject::isInstancePut));
+    clazz.forAllMethods(
+        methodSubject -> {
+          // Dead code removal is not part of -dontoptimize. That is, even with -dontoptimize,
+          // field put instructions are gone with better dead code removal.
+          assertTrue(
+              methodSubject
+                  .streamInstructions()
+                  .noneMatch(i -> i.isInstancePut() || i.isStaticPut()));
+        });
   }
 
   private CodeInspector runR8(Path proguardConfig) throws Exception {