Skip to content

Commit fed3d9a

Browse files
author
duke
committedJul 31, 2024
Automatic merge of jdk:master into master
2 parents 5397d11 + f2ba2eb commit fed3d9a

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed
 

‎src/hotspot/share/opto/movenode.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
9191
phase->type(in(IfTrue)) == Type::TOP) {
9292
return nullptr;
9393
}
94-
// Canonicalize the node by moving constants to the right input.
95-
if (in(Condition)->is_Bool() && phase->type(in(IfFalse))->singleton() && !phase->type(in(IfTrue))->singleton()) {
96-
BoolNode* b = in(Condition)->as_Bool()->negate(phase);
97-
return make(in(Control), phase->transform(b), in(IfTrue), in(IfFalse), _type);
98-
}
9994

95+
// Check for Min/Max patterns. This is called before constants are pushed to the right input, as that transform can
96+
// make BoolTests non-canonical.
10097
Node* minmax = Ideal_minmax(phase, this);
10198
if (minmax != nullptr) {
10299
return minmax;
103100
}
104101

102+
// Canonicalize the node by moving constants to the right input.
103+
if (in(Condition)->is_Bool() && phase->type(in(IfFalse))->singleton() && !phase->type(in(IfTrue))->singleton()) {
104+
BoolNode* b = in(Condition)->as_Bool()->negate(phase);
105+
return make(in(Control), phase->transform(b), in(IfTrue), in(IfFalse), _type);
106+
}
107+
105108
return nullptr;
106109
}
107110

‎test/hotspot/jtreg/compiler/c2/irTests/TestIfMinMax.java

+29-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
/*
3232
* @test
33-
* @bug 8324655 8329797
33+
* @bug 8324655 8329797 8331090
3434
* @key randomness
3535
* @summary Test that if expressions are properly folded into min/max nodes
3636
* @requires os.arch != "riscv64"
@@ -505,7 +505,27 @@ public void checkTestMinLongVector(Object[] vals) {
505505
}
506506
}
507507

508-
@Run(test = { "testMinI1", "testMinI2", "testMaxI1", "testMaxI2", "testMinI1E", "testMinI2E", "testMaxI1E", "testMaxI2E" })
508+
@Test
509+
@IR(failOn = { IRNode.IF }, counts = { IRNode.MIN_I, "1" })
510+
public int testMinIConst(int a) {
511+
if (a > 65535) {
512+
a = 65535;
513+
}
514+
515+
return a;
516+
}
517+
518+
@Test
519+
@IR(phase = { CompilePhase.BEFORE_MACRO_EXPANSION }, failOn = { IRNode.IF }, counts = { IRNode.MIN_L, "1" })
520+
public long testMinLConst(long a) {
521+
if (a > 65535) {
522+
a = 65535;
523+
}
524+
525+
return a;
526+
}
527+
528+
@Run(test = { "testMinI1", "testMinI2", "testMaxI1", "testMaxI2", "testMinI1E", "testMinI2E", "testMaxI1E", "testMaxI2E", "testMinIConst" })
509529
public void runTestIntegers() {
510530
testIntegers(10, 20);
511531
testIntegers(20, 10);
@@ -526,9 +546,12 @@ public void testIntegers(int a, int b) {
526546
Asserts.assertEQ(a >= b ? b : a, testMinI2E(a, b));
527547
Asserts.assertEQ(a >= b ? a : b, testMaxI1E(a, b));
528548
Asserts.assertEQ(a <= b ? b : a, testMaxI2E(a, b));
549+
550+
Asserts.assertEQ(a > 65535 ? 65535 : a, testMinIConst(a));
551+
Asserts.assertEQ(b > 65535 ? 65535 : b, testMinIConst(b));
529552
}
530553

531-
@Run(test = { "testMinL1", "testMinL2", "testMaxL1", "testMaxL2", "testMinL1E", "testMinL2E", "testMaxL1E", "testMaxL2E" })
554+
@Run(test = { "testMinL1", "testMinL2", "testMaxL1", "testMaxL2", "testMinL1E", "testMinL2E", "testMaxL1E", "testMaxL2E", "testMinLConst" })
532555
public void runTestLongs() {
533556
testLongs(10, 20);
534557
testLongs(20, 10);
@@ -551,5 +574,8 @@ public void testLongs(long a, long b) {
551574
Asserts.assertEQ(a >= b ? b : a, testMinL2E(a, b));
552575
Asserts.assertEQ(a >= b ? a : b, testMaxL1E(a, b));
553576
Asserts.assertEQ(a <= b ? b : a, testMaxL2E(a, b));
577+
578+
Asserts.assertEQ(a > 65535L ? 65535L : a, testMinLConst(a));
579+
Asserts.assertEQ(b > 65535L ? 65535L : b, testMinLConst(b));
554580
}
555581
}

0 commit comments

Comments
 (0)
Please sign in to comment.