1 /* |
1 /* |
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
120 max = iv.initNode(); |
120 max = iv.initNode(); |
121 min = end; |
121 min = end; |
122 } |
122 } |
123 ValueNode range = sub(max, min); |
123 ValueNode range = sub(max, min); |
124 |
124 |
125 ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1); |
125 ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph); |
126 if (oneOff) { |
126 if (oneOff) { |
127 range = add(range, one); |
127 range = add(range, one); |
128 } |
128 } |
129 // round-away-from-zero divison: (range + stride -/+ 1) / stride |
129 // round-away-from-zero divison: (range + stride -/+ 1) / stride |
130 ValueNode denominator = add(range, sub(absStride, one)); |
130 ValueNode denominator = add(graph, range, sub(absStride, one), NodeView.DEFAULT); |
131 ValueNode div = unsignedDivBefore(graph, loop.entryPoint(), denominator, absStride, null); |
131 ValueNode div = unsignedDivBefore(graph, loop.entryPoint(), denominator, absStride, null); |
132 |
132 |
133 if (assumeLoopEntered) { |
133 if (assumeLoopEntered) { |
134 return graph.addOrUniqueWithInputs(div); |
134 return graph.addOrUniqueWithInputs(div); |
135 } |
135 } |
136 ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0); |
136 ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph); |
137 // This check is "wide": it looks like min <= max |
137 // This check is "wide": it looks like min <= max |
138 // That's OK even if the loop is strict (`!isLimitIncluded()`) |
138 // That's OK even if the loop is strict (`!isLimitIncluded()`) |
139 // because in this case, `div` will be zero when min == max |
139 // because in this case, `div` will be zero when min == max |
140 LogicNode noEntryCheck = getCounterIntegerHelper().createCompareNode(max, min, NodeView.DEFAULT); |
140 LogicNode noEntryCheck = getCounterIntegerHelper().createCompareNode(max, min, NodeView.DEFAULT); |
141 return graph.addOrUniqueWithInputs(ConditionalNode.create(noEntryCheck, zero, div, NodeView.DEFAULT)); |
141 return graph.addOrUniqueWithInputs(ConditionalNode.create(noEntryCheck, zero, div, NodeView.DEFAULT)); |
|
142 } |
|
143 |
|
144 /** |
|
145 * Determine if the loop might be entered. Returns {@code false} if we can tell statically that |
|
146 * the loop cannot be entered; returns {@code true} if the loop might possibly be entered, |
|
147 * including in the case where we cannot be sure statically. |
|
148 * |
|
149 * @return false if the loop can definitely not be entered, true otherwise |
|
150 */ |
|
151 public boolean loopMightBeEntered() { |
|
152 Stamp stamp = iv.valueNode().stamp(NodeView.DEFAULT); |
|
153 |
|
154 ValueNode max; |
|
155 ValueNode min; |
|
156 if (iv.direction() == Direction.Up) { |
|
157 max = end; |
|
158 min = iv.initNode(); |
|
159 } else { |
|
160 assert iv.direction() == Direction.Down; |
|
161 max = iv.initNode(); |
|
162 min = end; |
|
163 } |
|
164 if (oneOff) { |
|
165 max = add(max, ConstantNode.forIntegerStamp(stamp, 1)); |
|
166 } |
|
167 |
|
168 LogicNode entryCheck = getCounterIntegerHelper().createCompareNode(min, max, NodeView.DEFAULT); |
|
169 if (entryCheck.isContradiction()) { |
|
170 // We can definitely not enter this loop. |
|
171 return false; |
|
172 } else { |
|
173 // We don't know for sure that the loop can't be entered, so assume it can. |
|
174 return true; |
|
175 } |
142 } |
176 } |
143 |
177 |
144 /** |
178 /** |
145 * @return true if the loop has constant bounds. |
179 * @return true if the loop has constant bounds. |
146 */ |
180 */ |