Skip to content

Commit c032082

Browse files
galderzbenoitmaillard
authored andcommitted
8374896: Min/Max identity optimization opportunities missing for int and long
Reviewed-by: chagedorn, bmaillard
1 parent c988a4e commit c032082

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/hotspot/share/opto/phaseX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2680,7 +2680,7 @@ void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_
26802680
if (use->is_MinMax()) {
26812681
for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
26822682
Node* u = use->fast_out(i2);
2683-
if (u->Opcode() == use->Opcode()) {
2683+
if (u->is_MinMax()) {
26842684
worklist.push(u);
26852685
}
26862686
}

test/hotspot/jtreg/compiler/igvn/TestMinMaxIdentity.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ private static String generate(CompileFramework comp) {
7373
.flatMap(MinMaxOp::generate)
7474
.forEach(testTemplateTokens::add);
7575

76+
// Note that for floating point Min/Max these cases below don't hold
77+
generate(MinMaxOp.MIN_I, MinMaxOp.MAX_I).forEach(testTemplateTokens::add);
78+
generate(MinMaxOp.MIN_L, MinMaxOp.MAX_L).forEach(testTemplateTokens::add);
79+
7680
Stream.of(Fp16MinMaxOp.values())
7781
.flatMap(Fp16MinMaxOp::generate)
7882
.forEach(testTemplateTokens::add);
@@ -89,6 +93,38 @@ private static String generate(CompileFramework comp) {
8993
testTemplateTokens);
9094
}
9195

96+
static Stream<TemplateToken> generate(MinMaxOp op1, MinMaxOp op2) {
97+
return Stream.of(template("a", "b", op1, op2), template("b", "a", op1, op2),
98+
template("a", "b", op2, op1), template("b", "a", op2, op1)).
99+
map(Template.ZeroArgs::asToken);
100+
}
101+
102+
static Template.ZeroArgs template(String arg1, String arg2, MinMaxOp op1, MinMaxOp op2) {
103+
return Template.make(() -> scope(
104+
let("boxedTypeName", op1.type.boxedTypeName()),
105+
let("op1", op1.name()),
106+
let("op2", op2.name()),
107+
let("type", op1.type.name()),
108+
let("fn1", op1.functionName),
109+
let("fn2", op2.functionName),
110+
let("arg1", arg1),
111+
let("arg2", arg2),
112+
"""
113+
@Test
114+
@IR(counts = {IRNode.#op1, "= 0", IRNode.#op2, "= 0"},
115+
phase = CompilePhase.BEFORE_MACRO_EXPANSION)
116+
@Arguments(values = {Argument.NUMBER_42, Argument.NUMBER_42})
117+
public #type $test(#type #arg1, #type #arg2) {
118+
int i;
119+
for (i = -10; i < 1; i++) {
120+
}
121+
#type c = a * i;
122+
return #boxedTypeName.#fn1(a, #boxedTypeName.#fn2(b, c));
123+
}
124+
"""
125+
));
126+
}
127+
92128
enum MinMaxOp {
93129
MIN_D("min", CodeGenerationDataNameType.doubles()),
94130
MAX_D("max", CodeGenerationDataNameType.doubles()),

0 commit comments

Comments
 (0)