annotate graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64AddressLowering.java @ 21787:2766fee1809a

Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 08 Jun 2015 19:32:59 +0200
parents f4e1d958f1c3
children 0e095e2c24e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21784
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
23
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24 package com.oracle.graal.compiler.amd64;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
25
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
26 import com.oracle.graal.asm.*;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.asm.amd64.AMD64Address.Scale;
21787
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
28 import com.oracle.graal.compiler.common.type.*;
21784
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.nodes.calc.*;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.memory.address.*;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.phases.common.AddressLoweringPhase.AddressLowering;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
33 import com.oracle.jvmci.code.*;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
34 import com.oracle.jvmci.meta.*;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
35
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
36 public class AMD64AddressLowering extends AddressLowering {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
37
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
38 private final CodeCacheProvider codeCache;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
39
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
40 public AMD64AddressLowering(CodeCacheProvider codeCache) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
41 this.codeCache = codeCache;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
42 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
43
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
44 @Override
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
45 public AddressNode lower(ValueNode address) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
46 return lower(address, null);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
47 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
48
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
49 @Override
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
50 public AddressNode lower(ValueNode base, ValueNode offset) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51 AMD64AddressNode ret = new AMD64AddressNode(base, offset);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52 boolean changed;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
53 do {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
54 changed = improve(ret);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
55 } while (changed);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
56 return base.graph().unique(ret);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
57 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
58
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
59 protected boolean improve(AMD64AddressNode ret) {
21787
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
60 ValueNode newBase = improveInput(ret, ret.getBase(), 0);
21784
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
61 if (newBase != ret.getBase()) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
62 ret.setBase(newBase);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
63 return true;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
64 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
65
21787
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
66 ValueNode newIdx = improveInput(ret, ret.getIndex(), ret.getScale().log2);
21784
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
67 if (newIdx != ret.getIndex()) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
68 ret.setIndex(newIdx);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
69 return true;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
70 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
71
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
72 if (ret.getIndex() instanceof LeftShiftNode) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
73 LeftShiftNode shift = (LeftShiftNode) ret.getIndex();
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
74 if (shift.getY().isConstant()) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
75 int amount = ret.getScale().log2 + shift.getY().asJavaConstant().asInt();
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
76 Scale scale = Scale.fromShift(amount);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
77 if (scale != null) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
78 ret.setIndex(shift.getX());
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
79 ret.setScale(scale);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
80 return true;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
81 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
82 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
83 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
84
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
85 if (ret.getScale() == Scale.Times1) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
86 if (ret.getBase() == null || ret.getIndex() == null) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
87 if (ret.getBase() instanceof AddNode) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
88 AddNode add = (AddNode) ret.getBase();
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
89 ret.setBase(add.getX());
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
90 ret.setIndex(add.getY());
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
91 return true;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
92 } else if (ret.getIndex() instanceof AddNode) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
93 AddNode add = (AddNode) ret.getIndex();
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
94 ret.setBase(add.getX());
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
95 ret.setIndex(add.getY());
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
96 return true;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
97 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
98 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
99
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
100 if (ret.getBase() instanceof LeftShiftNode && !(ret.getIndex() instanceof LeftShiftNode)) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
101 ValueNode tmp = ret.getBase();
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
102 ret.setBase(ret.getIndex());
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
103 ret.setIndex(tmp);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
104 return true;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
105 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
106 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
107
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
108 return false;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
109 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
110
21787
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
111 private ValueNode improveInput(AMD64AddressNode address, ValueNode node, int shift) {
21784
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
112 if (node == null) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
113 return null;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
114 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
115
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
116 if (node.isConstant()) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
117 return improveConstDisp(address, node, node.asJavaConstant(), null, shift);
21787
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
118 } else {
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
119 if (node.stamp() instanceof IntegerStamp && ((IntegerStamp) node.stamp()).getBits() == 64) {
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
120 if (node instanceof ZeroExtendNode) {
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
121 if (((ZeroExtendNode) node).getInputBits() == 32) {
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
122 /*
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
123 * We can just swallow a zero-extend from 32 bit to 64 bit because the upper
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
124 * half of the register will always be zero.
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
125 */
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
126 return ((ZeroExtendNode) node).getValue();
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
127 }
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
128 } else if (node instanceof AddNode) {
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
129 AddNode add = (AddNode) node;
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
130 if (add.getX().isConstant()) {
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
131 return improveConstDisp(address, node, add.getX().asJavaConstant(), add.getY(), shift);
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
132 } else if (add.getY().isConstant()) {
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
133 return improveConstDisp(address, node, add.getY().asJavaConstant(), add.getX(), shift);
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
134 }
2766fee1809a Use the fact that a range checked array index is not negative to avoid sign-extension of the index register.
Roland Schatz <roland.schatz@oracle.com>
parents: 21784
diff changeset
135 }
21784
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
136 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
137 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
138
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
139 return node;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
140 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
141
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
142 private ValueNode improveConstDisp(AMD64AddressNode address, ValueNode original, JavaConstant c, ValueNode other, int shift) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
143 if (c.getKind().isNumericInteger() && !codeCache.needsDataPatch(c)) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
144 long disp = address.getDisplacement();
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
145 disp += c.asLong() << shift;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
146 if (NumUtil.isInt(disp)) {
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
147 address.setDisplacement((int) disp);
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
148 return other;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
149 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
150 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
151 return original;
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
152 }
f4e1d958f1c3 [AMD64] Create AMD64 specific address nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
153 }