annotate src/share/vm/opto/mathexactnode.cpp @ 17726:085b304a1cc5

8027754: Enable loop optimizations for loops with MathExact inside Reviewed-by: kvn, iveresov
author rbackman
date Thu, 23 Jan 2014 12:08:28 +0100
parents 59e8ad757e19
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
1 /*
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
4 *
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
7 * published by the Free Software Foundation.
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
8 *
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
13 * accompanied this code).
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
14 *
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
18 *
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
21 * questions.
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
22 *
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
23 */
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
24
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
25 #include "precompiled.hpp"
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
26 #include "memory/allocation.inline.hpp"
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
27 #include "opto/addnode.hpp"
12888
4a2acfb16e97 8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents: 12323
diff changeset
28 #include "opto/cfgnode.hpp"
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
29 #include "opto/machnode.hpp"
12888
4a2acfb16e97 8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents: 12323
diff changeset
30 #include "opto/matcher.hpp"
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
31 #include "opto/mathexactnode.hpp"
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
32 #include "opto/subnode.hpp"
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
33
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
34 template <typename OverflowOp>
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
35 class AddHelper {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
36 public:
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
37 typedef typename OverflowOp::TypeClass TypeClass;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
38 typedef typename TypeClass::NativeType NativeType;
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
39
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
40 static bool will_overflow(NativeType value1, NativeType value2) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
41 NativeType result = value1 + value2;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
42 // Hacker's Delight 2-12 Overflow if both arguments have the opposite sign of the result
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
43 if (((value1 ^ result) & (value2 ^ result)) >= 0) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
44 return false;
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
45 }
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
46 return true;
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
47 }
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
48
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
49 static bool can_overflow(const Type* type1, const Type* type2) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
50 if (type1 == TypeClass::ZERO || type2 == TypeClass::ZERO) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
51 return false;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
52 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
53 return true;
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
54 }
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
55 };
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
56
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
57 template <typename OverflowOp>
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
58 class SubHelper {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
59 public:
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
60 typedef typename OverflowOp::TypeClass TypeClass;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
61 typedef typename TypeClass::NativeType NativeType;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
62
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
63 static bool will_overflow(NativeType value1, NativeType value2) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
64 NativeType result = value1 - value2;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
65 // hacker's delight 2-12 overflow iff the arguments have different signs and
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
66 // the sign of the result is different than the sign of arg1
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
67 if (((value1 ^ value2) & (value1 ^ result)) >= 0) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
68 return false;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
69 }
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
70 return true;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
71 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
72
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
73 static bool can_overflow(const Type* type1, const Type* type2) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
74 if (type2 == TypeClass::ZERO) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
75 return false;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
76 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
77 return true;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
78 }
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
79 };
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
80
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
81 template <typename OverflowOp>
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
82 class MulHelper {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
83 public:
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
84 typedef typename OverflowOp::TypeClass TypeClass;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
85
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
86 static bool can_overflow(const Type* type1, const Type* type2) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
87 if (type1 == TypeClass::ZERO || type2 == TypeClass::ZERO) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
88 return false;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
89 } else if (type1 == TypeClass::ONE || type2 == TypeClass::ONE) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
90 return false;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
91 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
92 return true;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
93 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
94 };
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
95
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
96 bool OverflowAddINode::will_overflow(jint v1, jint v2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
97 return AddHelper<OverflowAddINode>::will_overflow(v1, v2);
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
98 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
99
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
100 bool OverflowSubINode::will_overflow(jint v1, jint v2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
101 return SubHelper<OverflowSubINode>::will_overflow(v1, v2);
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
102 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
103
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
104 bool OverflowMulINode::will_overflow(jint v1, jint v2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
105 jlong result = (jlong) v1 * (jlong) v2;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
106 if ((jint) result == result) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
107 return false;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
108 }
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
109 return true;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
110 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
111
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
112 bool OverflowAddLNode::will_overflow(jlong v1, jlong v2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
113 return AddHelper<OverflowAddLNode>::will_overflow(v1, v2);
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
114 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
115
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
116 bool OverflowSubLNode::will_overflow(jlong v1, jlong v2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
117 return SubHelper<OverflowSubLNode>::will_overflow(v1, v2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
118 }
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
119
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
120 bool OverflowMulLNode::will_overflow(jlong val1, jlong val2) const {
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
121 jlong result = val1 * val2;
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
122 jlong ax = (val1 < 0 ? -val1 : val1);
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
123 jlong ay = (val2 < 0 ? -val2 : val2);
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
124
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
125 bool overflow = false;
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
126 if ((ax | ay) & CONST64(0xFFFFFFFF00000000)) {
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
127 // potential overflow if any bit in upper 32 bits are set
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
128 if ((val1 == min_jlong && val2 == -1) || (val2 == min_jlong && val1 == -1)) {
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
129 // -1 * Long.MIN_VALUE will overflow
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
130 overflow = true;
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
131 } else if (val2 != 0 && (result / val2 != val1)) {
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
132 overflow = true;
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
133 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
134 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
135
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
136 return overflow;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
137 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
138
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
139 bool OverflowAddINode::can_overflow(const Type* t1, const Type* t2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
140 return AddHelper<OverflowAddINode>::can_overflow(t1, t2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
141 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
142
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
143 bool OverflowSubINode::can_overflow(const Type* t1, const Type* t2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
144 if (in(1) == in(2)) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
145 return false;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
146 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
147 return SubHelper<OverflowSubINode>::can_overflow(t1, t2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
148 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
149
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
150 bool OverflowMulINode::can_overflow(const Type* t1, const Type* t2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
151 return MulHelper<OverflowMulINode>::can_overflow(t1, t2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
152 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
153
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
154 bool OverflowAddLNode::can_overflow(const Type* t1, const Type* t2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
155 return AddHelper<OverflowAddLNode>::can_overflow(t1, t2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
156 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
157
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
158 bool OverflowSubLNode::can_overflow(const Type* t1, const Type* t2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
159 if (in(1) == in(2)) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
160 return false;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
161 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
162 return SubHelper<OverflowSubLNode>::can_overflow(t1, t2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
163 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
164
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
165 bool OverflowMulLNode::can_overflow(const Type* t1, const Type* t2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
166 return MulHelper<OverflowMulLNode>::can_overflow(t1, t2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
167 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
168
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
169 const Type* OverflowNode::sub(const Type* t1, const Type* t2) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
170 fatal(err_msg_res("sub() should not be called for '%s'", NodeClassNames[this->Opcode()]));
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
171 return TypeInt::CC;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
172 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
173
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
174 template <typename OverflowOp>
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
175 struct IdealHelper {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
176 typedef typename OverflowOp::TypeClass TypeClass; // TypeInt, TypeLong
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
177 typedef typename TypeClass::NativeType NativeType;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
178
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
179 static Node* Ideal(const OverflowOp* node, PhaseGVN* phase, bool can_reshape) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
180 Node* arg1 = node->in(1);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
181 Node* arg2 = node->in(2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
182 const Type* type1 = phase->type(arg1);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
183 const Type* type2 = phase->type(arg2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
184
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
185 if (type1 == NULL || type2 == NULL) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
186 return NULL;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
187 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
188
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
189 if (type1 != Type::TOP && type1->singleton() &&
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
190 type2 != Type::TOP && type2->singleton()) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
191 NativeType val1 = TypeClass::as_self(type1)->get_con();
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
192 NativeType val2 = TypeClass::as_self(type2)->get_con();
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
193 if (node->will_overflow(val1, val2) == false) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
194 Node* con_result = ConINode::make(phase->C, 0);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
195 return con_result;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
196 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
197 return NULL;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
198 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
199 return NULL;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
200 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
201
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
202 static const Type* Value(const OverflowOp* node, PhaseTransform* phase) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
203 const Type *t1 = phase->type( node->in(1) );
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
204 const Type *t2 = phase->type( node->in(2) );
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
205 if( t1 == Type::TOP ) return Type::TOP;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
206 if( t2 == Type::TOP ) return Type::TOP;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
207
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
208 const TypeClass* i1 = TypeClass::as_self(t1);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
209 const TypeClass* i2 = TypeClass::as_self(t2);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
210
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
211 if (i1 == NULL || i2 == NULL) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
212 return TypeInt::CC;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
213 }
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
214
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
215 if (t1->singleton() && t2->singleton()) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
216 NativeType val1 = i1->get_con();
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
217 NativeType val2 = i2->get_con();
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
218 if (node->will_overflow(val1, val2)) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
219 return TypeInt::CC;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
220 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
221 return TypeInt::ZERO;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
222 } else if (i1 != TypeClass::TYPE_DOMAIN && i2 != TypeClass::TYPE_DOMAIN) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
223 if (node->will_overflow(i1->_lo, i2->_lo)) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
224 return TypeInt::CC;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
225 } else if (node->will_overflow(i1->_lo, i2->_hi)) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
226 return TypeInt::CC;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
227 } else if (node->will_overflow(i1->_hi, i2->_lo)) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
228 return TypeInt::CC;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
229 } else if (node->will_overflow(i1->_hi, i2->_hi)) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
230 return TypeInt::CC;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
231 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
232 return TypeInt::ZERO;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
233 }
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
234
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
235 if (!node->can_overflow(t1, t2)) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
236 return TypeInt::ZERO;
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
237 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
238 return TypeInt::CC;
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
239 }
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
240 };
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
241
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
242 Node* OverflowINode::Ideal(PhaseGVN* phase, bool can_reshape) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
243 return IdealHelper<OverflowINode>::Ideal(this, phase, can_reshape);
12972
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
244 }
59e8ad757e19 8026844: Various Math functions needs intrinsification
rbackman
parents: 12888
diff changeset
245
17726
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
246 Node* OverflowLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
247 return IdealHelper<OverflowLNode>::Ideal(this, phase, can_reshape);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
248 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
249
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
250 const Type* OverflowINode::Value(PhaseTransform* phase) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
251 return IdealHelper<OverflowINode>::Value(this, phase);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
252 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
253
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
254 const Type* OverflowLNode::Value(PhaseTransform* phase) const {
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
255 return IdealHelper<OverflowLNode>::Value(this, phase);
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
256 }
085b304a1cc5 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 12972
diff changeset
257