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
diff --git a/compiler/optimizing/nodes_shared.h b/compiler/optimizing/nodes_shared.h
index 4b0187d..d627c6d 100644
--- a/compiler/optimizing/nodes_shared.h
+++ b/compiler/optimizing/nodes_shared.h
@@ -97,6 +97,10 @@
     }
   }
 
+  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 0000000..e69de29
--- /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 0000000..e69de29
--- /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 0000000..1874dd6
--- /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 0000000..57cdf15
--- /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);
+        }
+    }
+}