Skip to content

Commit

Permalink
8329797: Shenandoah: Default case invoked for: "MaxL" (bad AD file)
Browse files Browse the repository at this point in the history
Reviewed-by: shade, thartmann
  • Loading branch information
caojoshua authored and TobiHartmann committed Apr 25, 2024
1 parent ccc0d0f commit d32f109
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/opto/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci,
_stub_entry_point(nullptr),
_max_node_limit(MaxNodeLimit),
_post_loop_opts_phase(false),
_allow_macro_nodes(true),
_inlining_progress(false),
_inlining_incrementally(false),
_do_cleanup(false),
Expand Down Expand Up @@ -915,6 +916,7 @@ Compile::Compile( ciEnv* ci_env,
_stub_entry_point(nullptr),
_max_node_limit(MaxNodeLimit),
_post_loop_opts_phase(false),
_allow_macro_nodes(true),
_inlining_progress(false),
_inlining_incrementally(false),
_has_reserved_stack_access(false),
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/opto/compile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class Compile : public Phase {
uintx _max_node_limit; // Max unique node count during a single compilation.

bool _post_loop_opts_phase; // Loop opts are finished.
bool _allow_macro_nodes; // True if we allow creation of macro nodes.

int _major_progress; // Count of something big happening
bool _inlining_progress; // progress doing incremental inlining?
Expand Down Expand Up @@ -787,6 +788,9 @@ class Compile : public Phase {
void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }

bool allow_macro_nodes() { return _allow_macro_nodes; }
void reset_allow_macro_nodes() { _allow_macro_nodes = false; }

void record_for_post_loop_opts_igvn(Node* n);
void remove_from_post_loop_opts_igvn(Node* n);
void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/opto/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,8 @@ void PhaseMacroExpand::eliminate_macro_nodes() {
//------------------------------expand_macro_nodes----------------------
// Returns true if a failure occurred.
bool PhaseMacroExpand::expand_macro_nodes() {
// Do not allow new macro nodes once we started to expand
C->reset_allow_macro_nodes();
if (StressMacroExpansion) {
C->shuffle_macro_nodes();
}
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/opto/movenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ CMoveNode *CMoveNode::make(Node *c, Node *bol, Node *left, Node *right, const Ty

// Try to identify min/max patterns in CMoves
Node* CMoveNode::Ideal_minmax(PhaseGVN* phase, CMoveNode* cmove) {
// If we're post loop opts then don't attempt to match the min/max pattern, as this node might have been a
// MinL or MaxL that was already expanded during macro expansion.
if (phase->C->post_loop_opts_phase()) {
// Only create MinL/MaxL if we are allowed to create macro nodes.
if (!phase->C->allow_macro_nodes()) {
return nullptr;
}

Expand Down
40 changes: 38 additions & 2 deletions test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

/*
* @test
* @bug 8324655 8329797
* @key randomness
* @bug 8324655
* @summary Test that if expressions are properly folded into min/max nodes
* @requires os.arch != "riscv64"
* @library /test/lib /
* @run main compiler.c2.irTests.TestIfMinMax
* @run driver compiler.c2.irTests.TestIfMinMax
*/
public class TestIfMinMax {
private static final Random RANDOM = Utils.getRandomInstance();
Expand Down Expand Up @@ -140,6 +140,42 @@ public long testMaxL2E(long a, long b) {
return a <= b ? b : a;
}

public class Dummy {
long l;
public Dummy(long l) { this.l = l; }
}

@Setup
Object[] setupDummyArray() {
Dummy[] arr = new Dummy[512];
for (int i = 0; i < 512; i++) {
arr[i] = new Dummy(RANDOM.nextLong());
}
return new Object[] { arr };
}

@Test
@Arguments(setup = "setupDummyArray")
@IR(failOn = { IRNode.MAX_L })
public long testMaxLAndBarrierInLoop(Dummy[] arr) {
long result = 0;
for (int i = 0; i < arr.length; ++i) {
result += Math.max(arr[i].l, 1);
}
return result;
}

@Test
@Arguments(setup = "setupDummyArray")
@IR(failOn = { IRNode.MIN_L })
public long testMinLAndBarrierInLoop(Dummy[] arr) {
long result = 0;
for (int i = 0; i < arr.length; ++i) {
result += Math.min(arr[i].l, 1);
}
return result;
}

@Setup
static Object[] setupIntArrays() {
int[] a = new int[512];
Expand Down

1 comment on commit d32f109

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.