Version 1.6.81
Cherry pick: Fix count error in IdempotentFunctionCallCanonicalizer
CL: https://r8-review.googlesource.com/c/r8/+/49531
Bug: 150688800
Change-Id: I4eb6f94a5bdabbc7fd6a5e0cb6cb721304aeea50
diff --git a/src/main/java/com/android/tools/r8/Version.java b/src/main/java/com/android/tools/r8/Version.java
index b2cd485..8c6b22e 100644
--- a/src/main/java/com/android/tools/r8/Version.java
+++ b/src/main/java/com/android/tools/r8/Version.java
@@ -11,7 +11,7 @@
// This field is accessed from release scripts using simple pattern matching.
// Therefore, changing this field could break our release scripts.
- public static final String LABEL = "1.6.80";
+ public static final String LABEL = "1.6.81";
private Version() {
}
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/IdempotentFunctionCallCanonicalizer.java b/src/main/java/com/android/tools/r8/ir/optimize/IdempotentFunctionCallCanonicalizer.java
index 0195c84..e5a7fc9 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/IdempotentFunctionCallCanonicalizer.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/IdempotentFunctionCallCanonicalizer.java
@@ -270,8 +270,12 @@
InstructionListIterator it = entryBlock.listIterator(code);
while (it.hasNext()) {
Instruction current = it.next();
- if (current.hasOutValue() && canonicalizedInvoke.inValues().contains(current.outValue())) {
- numberOfInValuePassed++;
+ if (current.hasOutValue()) {
+ for (Value inValue : canonicalizedInvoke.inValues()) {
+ if (inValue == current.outValue()) {
+ numberOfInValuePassed++;
+ }
+ }
}
if (numberOfInValuePassed == canonicalizedInvoke.inValues().size()) {
// If this invocation uses arguments and this iteration ends in the middle of Arguments,
diff --git a/src/test/java/com/android/tools/r8/regress/b150688800/IdempotentCountErrorTest.java b/src/test/java/com/android/tools/r8/regress/b150688800/IdempotentCountErrorTest.java
new file mode 100644
index 0000000..52ed2e5
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/regress/b150688800/IdempotentCountErrorTest.java
@@ -0,0 +1,61 @@
+// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.regress.b150688800;
+
+import com.android.tools.r8.NeverInline;
+import com.android.tools.r8.NeverPropagateValue;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.StringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class IdempotentCountErrorTest extends TestBase {
+
+ static final String EXPECTED = StringUtils.lines("0.0");
+
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public IdempotentCountErrorTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void test() throws Exception {
+ testForR8(parameters.getBackend())
+ .enableInliningAnnotations()
+ .enableMemberValuePropagationAnnotations()
+ .addInnerClasses(IdempotentCountErrorTest.class)
+ .addKeepMainRule(TestClass.class)
+ .setMinApi(parameters.getApiLevel())
+ .run(parameters.getRuntime(), TestClass.class)
+ .disassemble()
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ static class TestClass {
+
+ @NeverInline
+ @NeverPropagateValue
+ public static double twoInputValues(double x, double y) {
+ return x + y;
+ }
+
+ public static void main(String[] args) {
+ if (args.length > 42) {
+ System.out.println(twoInputValues(0, 0));
+ } else {
+ System.out.println(twoInputValues(0, 0));
+ }
+ }
+ }
+}