annotate src/share/vm/opto/mathexactnode.cpp @ 12972:59e8ad757e19

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