Skip to content

Commit 2d34acf

Browse files
eme64TobiHartmann
authored andcommitted
8286638: C2: CmpU needs to do more precise over/underflow analysis
Reviewed-by: kvn, vlivanov, thartmann
1 parent 46d208f commit 2d34acf

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

src/hotspot/share/opto/subnode.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,11 +827,10 @@ const Type* CmpUNode::Value(PhaseGVN* phase) const {
827827
int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here
828828
const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w);
829829
const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w);
830-
const Type* cmp1 = sub(tr1, t2);
831-
const Type* cmp2 = sub(tr2, t2);
832-
if (cmp1 == cmp2) {
833-
return cmp1; // Hit!
834-
}
830+
const TypeInt* cmp1 = sub(tr1, t2)->is_int();
831+
const TypeInt* cmp2 = sub(tr2, t2)->is_int();
832+
// compute union, so that cmp handles all possible results from the two cases
833+
return cmp1->meet(cmp2);
835834
}
836835
}
837836
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8286638
27+
* @summary Dominator failure because ConvL2I node becomes TOP, kills data-flow, but range-check does not collapse
28+
* due to insufficient overflow/underflow handling in CmpUNode::Value.
29+
*
30+
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN -Xcomp -XX:-TieredCompilation
31+
* -XX:CompileCommand=compileonly,compiler.rangechecks.TestRangeCheckCmpUUnderflow::*
32+
* -XX:RepeatCompilation=300
33+
* compiler.rangechecks.TestRangeCheckCmpUUnderflow
34+
*/
35+
36+
package compiler.rangechecks;
37+
38+
public class TestRangeCheckCmpUUnderflow {
39+
volatile int a;
40+
int b[];
41+
float c[];
42+
void e() {
43+
int g, f, i;
44+
for (g = 2;; g++) {
45+
for (i = g; i < 1; i++) {
46+
f = a;
47+
c[i - 1] -= b[i];
48+
}
49+
}
50+
}
51+
public static void main(String[] args) {
52+
try {
53+
TestRangeCheckCmpUUnderflow j = new TestRangeCheckCmpUUnderflow();
54+
j.e();
55+
} catch (Exception ex) {}
56+
}
57+
}

0 commit comments

Comments
 (0)