182 return create(v1, v2, view);
183 }
184 }
185
186 return super.canonical(constantReflection, metaAccess, options, smallestCompareWidth, condition, unorderedIsTrue, forX, forY, view);
187 }
188
189 @Override
190 protected LogicNode canonicalizeSymmetricConstant(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth,
191 CanonicalCondition condition, Constant constant, ValueNode nonConstant, boolean mirrored, boolean unorderedIsTrue, NodeView view) {
192 if (constant instanceof PrimitiveConstant) {
193 PrimitiveConstant primitiveConstant = (PrimitiveConstant) constant;
194 IntegerStamp nonConstantStamp = ((IntegerStamp) nonConstant.stamp(view));
195 if ((primitiveConstant.asLong() == 1 && nonConstantStamp.upperBound() == 1 && nonConstantStamp.lowerBound() == 0) ||
196 (primitiveConstant.asLong() == -1 && nonConstantStamp.upperBound() == 0 && nonConstantStamp.lowerBound() == -1)) {
197 // nonConstant can only be 0 or 1 (respective -1), test against 0 instead of 1
198 // (respective -1) for a more canonical graph and also to allow for faster
199 // execution
200 // on specific platforms.
201 return LogicNegationNode.create(
202 IntegerEqualsNode.create(constantReflection, metaAccess, options, smallestCompareWidth, nonConstant, ConstantNode.forIntegerKind(nonConstant.getStackKind(), 0),
203 view));
204 } else if (primitiveConstant.asLong() == 0) {
205 if (nonConstant instanceof AndNode) {
206 AndNode andNode = (AndNode) nonConstant;
207 return new IntegerTestNode(andNode.getX(), andNode.getY());
208 } else if (nonConstant instanceof SubNode) {
209 SubNode subNode = (SubNode) nonConstant;
210 return IntegerEqualsNode.create(constantReflection, metaAccess, options, smallestCompareWidth, subNode.getX(), subNode.getY(), view);
211 } else if (nonConstant instanceof ShiftNode && nonConstant.stamp(view) instanceof IntegerStamp) {
212 if (nonConstant instanceof LeftShiftNode) {
213 LeftShiftNode shift = (LeftShiftNode) nonConstant;
214 if (shift.getY().isConstant()) {
215 int mask = shift.getShiftAmountMask();
216 int amount = shift.getY().asJavaConstant().asInt() & mask;
217 if (shift.getX().getStackKind() == JavaKind.Int) {
218 return new IntegerTestNode(shift.getX(), ConstantNode.forInt(-1 >>> amount));
219 } else {
220 assert shift.getX().getStackKind() == JavaKind.Long;
221 return new IntegerTestNode(shift.getX(), ConstantNode.forLong(-1L >>> amount));
222 }
|
182 return create(v1, v2, view);
183 }
184 }
185
186 return super.canonical(constantReflection, metaAccess, options, smallestCompareWidth, condition, unorderedIsTrue, forX, forY, view);
187 }
188
189 @Override
190 protected LogicNode canonicalizeSymmetricConstant(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth,
191 CanonicalCondition condition, Constant constant, ValueNode nonConstant, boolean mirrored, boolean unorderedIsTrue, NodeView view) {
192 if (constant instanceof PrimitiveConstant) {
193 PrimitiveConstant primitiveConstant = (PrimitiveConstant) constant;
194 IntegerStamp nonConstantStamp = ((IntegerStamp) nonConstant.stamp(view));
195 if ((primitiveConstant.asLong() == 1 && nonConstantStamp.upperBound() == 1 && nonConstantStamp.lowerBound() == 0) ||
196 (primitiveConstant.asLong() == -1 && nonConstantStamp.upperBound() == 0 && nonConstantStamp.lowerBound() == -1)) {
197 // nonConstant can only be 0 or 1 (respective -1), test against 0 instead of 1
198 // (respective -1) for a more canonical graph and also to allow for faster
199 // execution
200 // on specific platforms.
201 return LogicNegationNode.create(
202 IntegerEqualsNode.create(constantReflection, metaAccess, options, smallestCompareWidth, nonConstant, ConstantNode.forIntegerStamp(nonConstantStamp, 0),
203 view));
204 } else if (primitiveConstant.asLong() == 0) {
205 if (nonConstant instanceof AndNode) {
206 AndNode andNode = (AndNode) nonConstant;
207 return new IntegerTestNode(andNode.getX(), andNode.getY());
208 } else if (nonConstant instanceof SubNode) {
209 SubNode subNode = (SubNode) nonConstant;
210 return IntegerEqualsNode.create(constantReflection, metaAccess, options, smallestCompareWidth, subNode.getX(), subNode.getY(), view);
211 } else if (nonConstant instanceof ShiftNode && nonConstant.stamp(view) instanceof IntegerStamp) {
212 if (nonConstant instanceof LeftShiftNode) {
213 LeftShiftNode shift = (LeftShiftNode) nonConstant;
214 if (shift.getY().isConstant()) {
215 int mask = shift.getShiftAmountMask();
216 int amount = shift.getY().asJavaConstant().asInt() & mask;
217 if (shift.getX().getStackKind() == JavaKind.Int) {
218 return new IntegerTestNode(shift.getX(), ConstantNode.forInt(-1 >>> amount));
219 } else {
220 assert shift.getX().getStackKind() == JavaKind.Long;
221 return new IntegerTestNode(shift.getX(), ConstantNode.forLong(-1L >>> amount));
222 }
|