summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Santiago Aboy Solanes <solanes@google.com> 2024-02-23 16:31:45 +0000
committer Santiago Aboy Solanes <solanes@google.com> 2024-02-26 10:59:52 +0000
commit6d918753132c67fe967f79c7ce20fb3cf57c4587 (patch)
tree23b803a1c3e5049899d091557184e4eeb6d2a471
parentb9e18d2ed06e2868a9e36374a18affa1e46bada5 (diff)
Define InstructionDataEquals for HBitwiseNegatedRight
If this is not defined, two HBitwiseNegatedRight instructions are considered equals when they have the same inputs even though they have different kinds. Bug: 326278115 Bug: 326492225 Fixes: 326278115 Fixes: 326492225 Test: art/test/testrunner/testrunner.py --target --64 Change-Id: I6a8232eedca48d8be27fb82f7fb8f394e324f464
-rw-r--r--compiler/optimizing/nodes_shared.h4
-rw-r--r--test/2274-checker-bitwise-gvn/expected-stderr.txt0
-rw-r--r--test/2274-checker-bitwise-gvn/expected-stdout.txt0
-rw-r--r--test/2274-checker-bitwise-gvn/info.txt2
-rw-r--r--test/2274-checker-bitwise-gvn/src/Main.java54
5 files changed, 60 insertions, 0 deletions
diff --git a/compiler/optimizing/nodes_shared.h b/compiler/optimizing/nodes_shared.h
index 4b0187d536..d627c6daee 100644
--- a/compiler/optimizing/nodes_shared.h
+++ b/compiler/optimizing/nodes_shared.h
@@ -97,6 +97,10 @@ class HBitwiseNegatedRight final : public HBinaryOperation {
}
}
+ bool InstructionDataEquals(const HInstruction* other) const override {
+ return op_kind_ == other->AsBitwiseNegatedRight()->op_kind_;
+ }
+
HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override {
return GetBlock()->GetGraph()->GetIntConstant(
Compute(x->GetValue(), y->GetValue()), GetDexPc());
diff --git a/test/2274-checker-bitwise-gvn/expected-stderr.txt b/test/2274-checker-bitwise-gvn/expected-stderr.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/2274-checker-bitwise-gvn/expected-stderr.txt
diff --git a/test/2274-checker-bitwise-gvn/expected-stdout.txt b/test/2274-checker-bitwise-gvn/expected-stdout.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/2274-checker-bitwise-gvn/expected-stdout.txt
diff --git a/test/2274-checker-bitwise-gvn/info.txt b/test/2274-checker-bitwise-gvn/info.txt
new file mode 100644
index 0000000000..1874dd6109
--- /dev/null
+++ b/test/2274-checker-bitwise-gvn/info.txt
@@ -0,0 +1,2 @@
+Tests that GVN doesn't deduplicate HBitwiseNegatedRight
+instructions with different kind.
diff --git a/test/2274-checker-bitwise-gvn/src/Main.java b/test/2274-checker-bitwise-gvn/src/Main.java
new file mode 100644
index 0000000000..57cdf15c65
--- /dev/null
+++ b/test/2274-checker-bitwise-gvn/src/Main.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Main {
+ public static void main(String[] args) {
+ // Test with even/odd input, and even/odd amount of loop iterations.
+ assertEquals(-33, $noinline$TwoBitwiseOperations(32, 4));
+ assertEquals(1, $noinline$TwoBitwiseOperations(32, 5));
+ assertEquals(-31, $noinline$TwoBitwiseOperations(31, 4));
+ assertEquals(0, $noinline$TwoBitwiseOperations(31, 5));
+ }
+
+ /// CHECK-START-ARM: int Main.$noinline$TwoBitwiseOperations(int, int) instruction_simplifier_arm (after)
+ /// CHECK: BitwiseNegatedRight kind:And
+ /// CHECK: BitwiseNegatedRight kind:Or
+
+ /// CHECK-START-ARM64: int Main.$noinline$TwoBitwiseOperations(int, int) instruction_simplifier_arm64 (after)
+ /// CHECK: BitwiseNegatedRight kind:And
+ /// CHECK: BitwiseNegatedRight kind:Or
+
+ /// CHECK-START-{ARM,ARM64}: int Main.$noinline$TwoBitwiseOperations(int, int) disassembly (after)
+ /// CHECK: BitwiseNegatedRight kind:And
+ /// CHECK: BitwiseNegatedRight kind:Or
+ private static int $noinline$TwoBitwiseOperations(int a, int n) {
+ int result = 0;
+ for (int i = 0; i < n; ++i) {
+ if (i % 2 == 0) {
+ result = (~a) & 1;
+ } else {
+ result = (~a) | 1;
+ }
+ }
+ return result;
+ }
+
+ public static void assertEquals(int expected, int actual) {
+ if (expected != actual) {
+ throw new Error("Expected: " + expected + ", found: " + actual);
+ }
+ }
+}