author | kvn |
Tue, 05 Nov 2013 17:38:04 -0800 | |
changeset 22838 | 82c7497fbad4 |
parent 21105 | 47618ee96ed5 |
child 22911 | ff49c48c887d |
permissions | -rw-r--r-- |
20289 | 1 |
/* |
2 |
* Copyright (c) 2013, 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 |
#include "precompiled.hpp" |
|
26 |
#include "memory/allocation.inline.hpp" |
|
27 |
#include "opto/addnode.hpp" |
|
20715
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
28 |
#include "opto/cfgnode.hpp" |
20289 | 29 |
#include "opto/machnode.hpp" |
20715
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
30 |
#include "opto/matcher.hpp" |
20289 | 31 |
#include "opto/mathexactnode.hpp" |
32 |
#include "opto/subnode.hpp" |
|
33 |
||
21105
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
34 |
MathExactNode::MathExactNode(Node* ctrl, Node* in1) : MultiNode(2) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
35 |
init_class_id(Class_MathExact); |
20289 | 36 |
init_req(0, ctrl); |
21105
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
37 |
init_req(1, in1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
38 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
39 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
40 |
MathExactNode::MathExactNode(Node* ctrl, Node* in1, Node* in2) : MultiNode(3) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
41 |
init_class_id(Class_MathExact); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
42 |
init_req(0, ctrl); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
43 |
init_req(1, in1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
44 |
init_req(2, in2); |
20289 | 45 |
} |
46 |
||
20715
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
47 |
BoolNode* MathExactNode::bool_node() const { |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
48 |
Node* flags = flags_node(); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
49 |
BoolNode* boolnode = flags->unique_out()->as_Bool(); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
50 |
assert(boolnode != NULL, "must have BoolNode"); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
51 |
return boolnode; |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
52 |
} |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
53 |
|
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
54 |
IfNode* MathExactNode::if_node() const { |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
55 |
BoolNode* boolnode = bool_node(); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
56 |
IfNode* ifnode = boolnode->unique_out()->as_If(); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
57 |
assert(ifnode != NULL, "must have IfNode"); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
58 |
return ifnode; |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
59 |
} |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
60 |
|
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
61 |
Node* MathExactNode::control_node() const { |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
62 |
IfNode* ifnode = if_node(); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
63 |
return ifnode->in(0); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
64 |
} |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
65 |
|
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
66 |
Node* MathExactNode::non_throwing_branch() const { |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
67 |
IfNode* ifnode = if_node(); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
68 |
if (bool_node()->_test._test == BoolTest::overflow) { |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
69 |
return ifnode->proj_out(0); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
70 |
} |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
71 |
return ifnode->proj_out(1); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
72 |
} |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
73 |
|
20289 | 74 |
// If the MathExactNode won't overflow we have to replace the |
75 |
// FlagsProjNode and ProjNode that is generated by the MathExactNode |
|
21105
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
76 |
Node* MathExactNode::no_overflow(PhaseGVN* phase, Node* new_result) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
77 |
PhaseIterGVN* igvn = phase->is_IterGVN(); |
20289 | 78 |
if (igvn) { |
79 |
ProjNode* result = result_node(); |
|
80 |
ProjNode* flags = flags_node(); |
|
81 |
||
82 |
if (result != NULL) { |
|
83 |
igvn->replace_node(result, new_result); |
|
84 |
} |
|
85 |
||
86 |
if (flags != NULL) { |
|
20715
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
87 |
BoolNode* boolnode = bool_node(); |
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
88 |
switch (boolnode->_test._test) { |
20289 | 89 |
case BoolTest::overflow: |
90 |
// if the check is for overflow - never taken |
|
20715
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
91 |
igvn->replace_node(boolnode, phase->intcon(0)); |
20289 | 92 |
break; |
93 |
case BoolTest::no_overflow: |
|
94 |
// if the check is for no overflow - always taken |
|
20715
be1135dc1406
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents:
20289
diff
changeset
|
95 |
igvn->replace_node(boolnode, phase->intcon(1)); |
20289 | 96 |
break; |
97 |
default: |
|
98 |
fatal("Unexpected value of BoolTest"); |
|
99 |
break; |
|
100 |
} |
|
101 |
flags->del_req(0); |
|
102 |
} |
|
103 |
} |
|
104 |
return new_result; |
|
105 |
} |
|
106 |
||
21105
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
107 |
Node* MathExactINode::match(const ProjNode* proj, const Matcher* m) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
108 |
uint ideal_reg = proj->ideal_reg(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
109 |
RegMask rm; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
110 |
if (proj->_con == result_proj_node) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
111 |
rm = m->mathExactI_result_proj_mask(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
112 |
} else { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
113 |
assert(proj->_con == flags_proj_node, "must be result or flags"); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
114 |
assert(ideal_reg == Op_RegFlags, "sanity"); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
115 |
rm = m->mathExactI_flags_proj_mask(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
116 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
117 |
return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
118 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
119 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
120 |
Node* MathExactLNode::match(const ProjNode* proj, const Matcher* m) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
121 |
uint ideal_reg = proj->ideal_reg(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
122 |
RegMask rm; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
123 |
if (proj->_con == result_proj_node) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
124 |
rm = m->mathExactL_result_proj_mask(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
125 |
} else { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
126 |
assert(proj->_con == flags_proj_node, "must be result or flags"); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
127 |
assert(ideal_reg == Op_RegFlags, "sanity"); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
128 |
rm = m->mathExactI_flags_proj_mask(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
129 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
130 |
return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
131 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
132 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
133 |
Node* AddExactINode::Ideal(PhaseGVN* phase, bool can_reshape) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
134 |
Node* arg1 = in(1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
135 |
Node* arg2 = in(2); |
20289 | 136 |
|
137 |
const Type* type1 = phase->type(arg1); |
|
138 |
const Type* type2 = phase->type(arg2); |
|
139 |
||
140 |
if (type1 != Type::TOP && type1->singleton() && |
|
141 |
type2 != Type::TOP && type2->singleton()) { |
|
142 |
jint val1 = arg1->get_int(); |
|
143 |
jint val2 = arg2->get_int(); |
|
144 |
jint result = val1 + val2; |
|
145 |
// Hacker's Delight 2-12 Overflow if both arguments have the opposite sign of the result |
|
146 |
if ( (((val1 ^ result) & (val2 ^ result)) >= 0)) { |
|
147 |
Node* con_result = ConINode::make(phase->C, result); |
|
148 |
return no_overflow(phase, con_result); |
|
149 |
} |
|
150 |
return NULL; |
|
151 |
} |
|
152 |
||
21105
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
153 |
if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) { // (Add 0 x) == x |
20289 | 154 |
Node* add_result = new (phase->C) AddINode(arg1, arg2); |
155 |
return no_overflow(phase, add_result); |
|
156 |
} |
|
157 |
||
158 |
if (type2->singleton()) { |
|
159 |
return NULL; // no change - keep constant on the right |
|
160 |
} |
|
161 |
||
162 |
if (type1->singleton()) { |
|
163 |
// Make it x + Constant - move constant to the right |
|
164 |
swap_edges(1, 2); |
|
165 |
return this; |
|
166 |
} |
|
167 |
||
168 |
if (arg2->is_Load()) { |
|
169 |
return NULL; // no change - keep load on the right |
|
170 |
} |
|
171 |
||
172 |
if (arg1->is_Load()) { |
|
173 |
// Make it x + Load - move load to the right |
|
174 |
swap_edges(1, 2); |
|
175 |
return this; |
|
176 |
} |
|
177 |
||
178 |
if (arg1->_idx > arg2->_idx) { |
|
179 |
// Sort the edges |
|
180 |
swap_edges(1, 2); |
|
181 |
return this; |
|
182 |
} |
|
183 |
||
184 |
return NULL; |
|
185 |
} |
|
186 |
||
21105
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
187 |
Node* AddExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
188 |
Node* arg1 = in(1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
189 |
Node* arg2 = in(2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
190 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
191 |
const Type* type1 = phase->type(arg1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
192 |
const Type* type2 = phase->type(arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
193 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
194 |
if (type1 != Type::TOP && type1->singleton() && |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
195 |
type2 != Type::TOP && type2->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
196 |
jlong val1 = arg1->get_long(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
197 |
jlong val2 = arg2->get_long(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
198 |
jlong result = val1 + val2; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
199 |
// Hacker's Delight 2-12 Overflow if both arguments have the opposite sign of the result |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
200 |
if ( (((val1 ^ result) & (val2 ^ result)) >= 0)) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
201 |
Node* con_result = ConLNode::make(phase->C, result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
202 |
return no_overflow(phase, con_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
203 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
204 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
205 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
206 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
207 |
if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) { // (Add 0 x) == x |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
208 |
Node* add_result = new (phase->C) AddLNode(arg1, arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
209 |
return no_overflow(phase, add_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
210 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
211 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
212 |
if (type2->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
213 |
return NULL; // no change - keep constant on the right |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
214 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
215 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
216 |
if (type1->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
217 |
// Make it x + Constant - move constant to the right |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
218 |
swap_edges(1, 2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
219 |
return this; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
220 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
221 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
222 |
if (arg2->is_Load()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
223 |
return NULL; // no change - keep load on the right |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
224 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
225 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
226 |
if (arg1->is_Load()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
227 |
// Make it x + Load - move load to the right |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
228 |
swap_edges(1, 2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
229 |
return this; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
230 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
231 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
232 |
if (arg1->_idx > arg2->_idx) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
233 |
// Sort the edges |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
234 |
swap_edges(1, 2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
235 |
return this; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
236 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
237 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
238 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
239 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
240 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
241 |
Node* SubExactINode::Ideal(PhaseGVN* phase, bool can_reshape) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
242 |
Node* arg1 = in(1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
243 |
Node* arg2 = in(2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
244 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
245 |
const Type* type1 = phase->type(arg1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
246 |
const Type* type2 = phase->type(arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
247 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
248 |
if (type1 != Type::TOP && type1->singleton() && |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
249 |
type2 != Type::TOP && type2->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
250 |
jint val1 = arg1->get_int(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
251 |
jint val2 = arg2->get_int(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
252 |
jint result = val1 - val2; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
253 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
254 |
// Hacker's Delight 2-12 Overflow iff the arguments have different signs and |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
255 |
// the sign of the result is different than the sign of arg1 |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
256 |
if (((val1 ^ val2) & (val1 ^ result)) >= 0) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
257 |
Node* con_result = ConINode::make(phase->C, result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
258 |
return no_overflow(phase, con_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
259 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
260 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
261 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
262 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
263 |
if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
264 |
// Sub with zero is the same as add with zero |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
265 |
Node* add_result = new (phase->C) AddINode(arg1, arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
266 |
return no_overflow(phase, add_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
267 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
268 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
269 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
270 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
271 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
272 |
Node* SubExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
273 |
Node* arg1 = in(1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
274 |
Node* arg2 = in(2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
275 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
276 |
const Type* type1 = phase->type(arg1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
277 |
const Type* type2 = phase->type(arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
278 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
279 |
if (type1 != Type::TOP && type1->singleton() && |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
280 |
type2 != Type::TOP && type2->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
281 |
jlong val1 = arg1->get_long(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
282 |
jlong val2 = arg2->get_long(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
283 |
jlong result = val1 - val2; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
284 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
285 |
// Hacker's Delight 2-12 Overflow iff the arguments have different signs and |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
286 |
// the sign of the result is different than the sign of arg1 |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
287 |
if (((val1 ^ val2) & (val1 ^ result)) >= 0) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
288 |
Node* con_result = ConLNode::make(phase->C, result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
289 |
return no_overflow(phase, con_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
290 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
291 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
292 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
293 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
294 |
if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
295 |
// Sub with zero is the same as add with zero |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
296 |
Node* add_result = new (phase->C) AddLNode(arg1, arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
297 |
return no_overflow(phase, add_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
298 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
299 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
300 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
301 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
302 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
303 |
Node* NegExactINode::Ideal(PhaseGVN* phase, bool can_reshape) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
304 |
Node *arg = in(1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
305 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
306 |
const Type* type = phase->type(arg); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
307 |
if (type != Type::TOP && type->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
308 |
jint value = arg->get_int(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
309 |
if (value != min_jint) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
310 |
Node* neg_result = ConINode::make(phase->C, -value); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
311 |
return no_overflow(phase, neg_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
312 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
313 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
314 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
315 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
316 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
317 |
Node* NegExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
318 |
Node *arg = in(1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
319 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
320 |
const Type* type = phase->type(arg); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
321 |
if (type != Type::TOP && type->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
322 |
jlong value = arg->get_long(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
323 |
if (value != min_jlong) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
324 |
Node* neg_result = ConLNode::make(phase->C, -value); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
325 |
return no_overflow(phase, neg_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
326 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
327 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
328 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
329 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
330 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
331 |
Node* MulExactINode::Ideal(PhaseGVN* phase, bool can_reshape) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
332 |
Node* arg1 = in(1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
333 |
Node* arg2 = in(2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
334 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
335 |
const Type* type1 = phase->type(arg1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
336 |
const Type* type2 = phase->type(arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
337 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
338 |
if (type1 != Type::TOP && type1->singleton() && |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
339 |
type2 != Type::TOP && type2->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
340 |
jint val1 = arg1->get_int(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
341 |
jint val2 = arg2->get_int(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
342 |
jlong result = (jlong) val1 * (jlong) val2; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
343 |
if ((jint) result == result) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
344 |
// no overflow |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
345 |
Node* mul_result = ConINode::make(phase->C, result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
346 |
return no_overflow(phase, mul_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
347 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
348 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
349 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
350 |
if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
351 |
return no_overflow(phase, ConINode::make(phase->C, 0)); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
352 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
353 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
354 |
if (type1 == TypeInt::ONE) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
355 |
Node* mul_result = new (phase->C) AddINode(arg2, phase->intcon(0)); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
356 |
return no_overflow(phase, mul_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
357 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
358 |
if (type2 == TypeInt::ONE) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
359 |
Node* mul_result = new (phase->C) AddINode(arg1, phase->intcon(0)); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
360 |
return no_overflow(phase, mul_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
361 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
362 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
363 |
if (type1 == TypeInt::MINUS_1) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
364 |
return new (phase->C) NegExactINode(NULL, arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
365 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
366 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
367 |
if (type2 == TypeInt::MINUS_1) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
368 |
return new (phase->C) NegExactINode(NULL, arg1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
369 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
370 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
371 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
372 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
373 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
374 |
Node* MulExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
375 |
Node* arg1 = in(1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
376 |
Node* arg2 = in(2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
377 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
378 |
const Type* type1 = phase->type(arg1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
379 |
const Type* type2 = phase->type(arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
380 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
381 |
if (type1 != Type::TOP && type1->singleton() && |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
382 |
type2 != Type::TOP && type2->singleton()) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
383 |
jlong val1 = arg1->get_long(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
384 |
jlong val2 = arg2->get_long(); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
385 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
386 |
jlong result = val1 * val2; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
387 |
jlong ax = (val1 < 0 ? -val1 : val1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
388 |
jlong ay = (val2 < 0 ? -val2 : val2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
389 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
390 |
bool overflow = false; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
391 |
if ((ax | ay) & CONST64(0xFFFFFFFF00000000)) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
392 |
// potential overflow if any bit in upper 32 bits are set |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
393 |
if ((val1 == min_jlong && val2 == -1) || (val2 == min_jlong && val1 == -1)) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
394 |
// -1 * Long.MIN_VALUE will overflow |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
395 |
overflow = true; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
396 |
} else if (val2 != 0 && (result / val2 != val1)) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
397 |
overflow = true; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
398 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
399 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
400 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
401 |
if (!overflow) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
402 |
Node* mul_result = ConLNode::make(phase->C, result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
403 |
return no_overflow(phase, mul_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
404 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
405 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
406 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
407 |
if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
408 |
return no_overflow(phase, ConLNode::make(phase->C, 0)); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
409 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
410 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
411 |
if (type1 == TypeLong::ONE) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
412 |
Node* mul_result = new (phase->C) AddLNode(arg2, phase->longcon(0)); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
413 |
return no_overflow(phase, mul_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
414 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
415 |
if (type2 == TypeLong::ONE) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
416 |
Node* mul_result = new (phase->C) AddLNode(arg1, phase->longcon(0)); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
417 |
return no_overflow(phase, mul_result); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
418 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
419 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
420 |
if (type1 == TypeLong::MINUS_1) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
421 |
return new (phase->C) NegExactLNode(NULL, arg2); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
422 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
423 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
424 |
if (type2 == TypeLong::MINUS_1) { |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
425 |
return new (phase->C) NegExactLNode(NULL, arg1); |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
426 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
427 |
|
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
428 |
return NULL; |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
429 |
} |
47618ee96ed5
8026844: Various Math functions needs intrinsification
rbackman
parents:
20715
diff
changeset
|
430 |