From 3ceabf0f647beb4943c06709aa8797f7511cd48e Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Thu, 3 Apr 2025 11:34:45 +0000 Subject: [PATCH] 8353359: C2: Or(I|L)Node::Ideal is missing AddNode::Ideal call Reviewed-by: epeter, chagedorn --- src/hotspot/share/opto/addnode.cpp | 4 ++-- .../c2/irTests/OrINodeIdealizationTests.java | 22 +++++++++++++++--- .../c2/irTests/OrLNodeIdealizationTests.java | 23 ++++++++++++++++--- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/opto/addnode.cpp b/src/hotspot/share/opto/addnode.cpp index d1be0180fd9..51b7ae7f6d4 100644 --- a/src/hotspot/share/opto/addnode.cpp +++ b/src/hotspot/share/opto/addnode.cpp @@ -829,7 +829,7 @@ Node* OrINode::Ideal(PhaseGVN* phase, bool can_reshape) { Node* tn = phase->transform(and_a_b); return AddNode::make_not(phase, tn, T_INT); } - return nullptr; + return AddNode::Ideal(phase, can_reshape); } //------------------------------add_ring--------------------------------------- @@ -909,7 +909,7 @@ Node* OrLNode::Ideal(PhaseGVN* phase, bool can_reshape) { return AddNode::make_not(phase, tn, T_LONG); } - return nullptr; + return AddNode::Ideal(phase, can_reshape); } //------------------------------add_ring--------------------------------------- diff --git a/test/hotspot/jtreg/compiler/c2/irTests/OrINodeIdealizationTests.java b/test/hotspot/jtreg/compiler/c2/irTests/OrINodeIdealizationTests.java index 60ac26b6f45..b0eb1226c6b 100644 --- a/test/hotspot/jtreg/compiler/c2/irTests/OrINodeIdealizationTests.java +++ b/test/hotspot/jtreg/compiler/c2/irTests/OrINodeIdealizationTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,7 @@ import compiler.lib.ir_framework.*; /* * @test - * @bug 8322077 + * @bug 8322077 8353359 * @summary Test that Ideal transformations of OrINode* are being performed as expected. * @library /test/lib / * @run driver compiler.c2.irTests.OrINodeIdealizationTests @@ -38,7 +38,7 @@ public class OrINodeIdealizationTests { TestFramework.run(); } - @Run(test = { "test1" }) + @Run(test = { "test1", "test2", "test3" }) public void runMethod() { int a = RunInfo.getRandom().nextInt(); int b = RunInfo.getRandom().nextInt(); @@ -55,6 +55,8 @@ public class OrINodeIdealizationTests { @DontCompile public void assertResult(int a, int b) { Asserts.assertEQ((~a) | (~b), test1(a, b)); + Asserts.assertEQ((a | 3) | 6, test2(a)); + Asserts.assertEQ((a | 3) | a, test3(a)); } // Checks (~a) | (~b) => ~(a & b) @@ -65,4 +67,18 @@ public class OrINodeIdealizationTests { public int test1(int a, int b) { return (~a) | (~b); } + + // Checks (a | 3) | 6 => a | (3 | 6) => a | 7 + @Test + @IR(counts = { IRNode.OR, "1"}) + public int test2(int a) { + return (a | 3) | 6; + } + + // Checks (a | 3) | a => (a | a) | 3 => a | 3 + @Test + @IR(counts = { IRNode.OR, "1"}) + public int test3(int a) { + return (a | 3) | a; + } } diff --git a/test/hotspot/jtreg/compiler/c2/irTests/OrLNodeIdealizationTests.java b/test/hotspot/jtreg/compiler/c2/irTests/OrLNodeIdealizationTests.java index 8de59bb8614..023e5fcc3d1 100644 --- a/test/hotspot/jtreg/compiler/c2/irTests/OrLNodeIdealizationTests.java +++ b/test/hotspot/jtreg/compiler/c2/irTests/OrLNodeIdealizationTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,7 @@ import compiler.lib.ir_framework.*; /* * @test - * @bug 8322077 + * @bug 8322077 8353359 * @summary Test that Ideal transformations of OrLNode* are being performed as expected. * @library /test/lib / * @run driver compiler.c2.irTests.OrLNodeIdealizationTests @@ -38,7 +38,7 @@ public class OrLNodeIdealizationTests { TestFramework.run(); } - @Run(test = { "test1" }) + @Run(test = { "test1", "test2", "test3" }) public void runMethod() { long a = RunInfo.getRandom().nextLong(); long b = RunInfo.getRandom().nextLong(); @@ -55,6 +55,8 @@ public class OrLNodeIdealizationTests { @DontCompile public void assertResult(long a, long b) { Asserts.assertEQ((~a) | (~b), test1(a, b)); + Asserts.assertEQ((a | 3) | 6, test2(a)); + Asserts.assertEQ((a | 3) | a, test3(a)); } // Checks (~a) | (~b) => ~(a & b) @@ -65,4 +67,19 @@ public class OrLNodeIdealizationTests { public long test1(long a, long b) { return (~a) | (~b); } + + + // Checks (a | 3) | 6 => a | (3 | 6) => a | 7 + @Test + @IR(counts = { IRNode.OR, "1"}) + public long test2(long a) { + return (a | 3) | 6; + } + + // Checks (a | 3) | a => (a | a) | 3 => a | 3 + @Test + @IR(counts = { IRNode.OR, "1"}) + public long test3(long a) { + return (a | 3) | a; + } }