< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/UnsignedRightShiftNode.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.nodes.calc;
  26 

  27 import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
  28 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.ShiftOp.UShr;
  29 import org.graalvm.compiler.core.common.type.IntegerStamp;
  30 import org.graalvm.compiler.core.common.type.Stamp;
  31 import org.graalvm.compiler.graph.NodeClass;
  32 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  33 import org.graalvm.compiler.lir.gen.ArithmeticLIRGeneratorTool;
  34 import org.graalvm.compiler.nodeinfo.NodeInfo;
  35 import org.graalvm.compiler.nodes.ConstantNode;
  36 import org.graalvm.compiler.nodes.NodeView;
  37 import org.graalvm.compiler.nodes.ValueNode;
  38 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  39 
  40 import jdk.vm.ci.meta.JavaKind;
  41 
  42 @NodeInfo(shortName = ">>>")
  43 public final class UnsignedRightShiftNode extends ShiftNode<UShr> {
  44 
  45     public static final NodeClass<UnsignedRightShiftNode> TYPE = NodeClass.create(UnsignedRightShiftNode.class);
  46 


  67             return ret;
  68         }
  69 
  70         return canonical(this, this.getArithmeticOp(), this.stamp(view), forX, forY, view);
  71     }
  72 
  73     @SuppressWarnings("unused")
  74     private static ValueNode canonical(UnsignedRightShiftNode node, ArithmeticOpTable.ShiftOp<UShr> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
  75         if (forY.isConstant()) {
  76             int amount = forY.asJavaConstant().asInt();
  77             int originalAmout = amount;
  78             int mask = op.getShiftAmountMask(stamp);
  79             amount &= mask;
  80             if (amount == 0) {
  81                 return forX;
  82             }
  83 
  84             Stamp xStampGeneric = forX.stamp(view);
  85             if (xStampGeneric instanceof IntegerStamp) {
  86                 IntegerStamp xStamp = (IntegerStamp) xStampGeneric;



  87 
  88                 if (xStamp.lowerBound() >>> amount == xStamp.upperBound() >>> amount) {
  89                     // The result of the shift is constant.
  90                     return ConstantNode.forIntegerKind(stamp.getStackKind(), xStamp.lowerBound() >>> amount);
  91                 }
  92 
  93                 if (amount == xStamp.getBits() - 1 && xStamp.lowerBound() == -1 && xStamp.upperBound() == 0) {
  94                     // Shift is equivalent to a negation, i.e., turns -1 into 1 and keeps 0 at 0.
  95                     return NegateNode.create(forX, view);
  96                 }
  97             }
  98 
  99             if (forX instanceof ShiftNode) {
 100                 ShiftNode<?> other = (ShiftNode<?>) forX;
 101                 if (other.getY().isConstant()) {
 102                     int otherAmount = other.getY().asJavaConstant().asInt() & mask;
 103                     if (other instanceof UnsignedRightShiftNode) {
 104                         int total = amount + otherAmount;
 105                         if (total != (total & mask)) {
 106                             return ConstantNode.forIntegerKind(stamp.getStackKind(), 0);
 107                         }
 108                         return new UnsignedRightShiftNode(other.getX(), ConstantNode.forInt(total));
 109                     } else if (other instanceof LeftShiftNode && otherAmount == amount) {
 110                         if (stamp.getStackKind() == JavaKind.Long) {


   1 /*
   2  * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.nodes.calc;
  26 
  27 import jdk.vm.ci.code.CodeUtil;
  28 import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
  29 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.ShiftOp.UShr;
  30 import org.graalvm.compiler.core.common.type.IntegerStamp;
  31 import org.graalvm.compiler.core.common.type.Stamp;
  32 import org.graalvm.compiler.graph.NodeClass;
  33 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  34 import org.graalvm.compiler.lir.gen.ArithmeticLIRGeneratorTool;
  35 import org.graalvm.compiler.nodeinfo.NodeInfo;
  36 import org.graalvm.compiler.nodes.ConstantNode;
  37 import org.graalvm.compiler.nodes.NodeView;
  38 import org.graalvm.compiler.nodes.ValueNode;
  39 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  40 
  41 import jdk.vm.ci.meta.JavaKind;
  42 
  43 @NodeInfo(shortName = ">>>")
  44 public final class UnsignedRightShiftNode extends ShiftNode<UShr> {
  45 
  46     public static final NodeClass<UnsignedRightShiftNode> TYPE = NodeClass.create(UnsignedRightShiftNode.class);
  47 


  68             return ret;
  69         }
  70 
  71         return canonical(this, this.getArithmeticOp(), this.stamp(view), forX, forY, view);
  72     }
  73 
  74     @SuppressWarnings("unused")
  75     private static ValueNode canonical(UnsignedRightShiftNode node, ArithmeticOpTable.ShiftOp<UShr> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
  76         if (forY.isConstant()) {
  77             int amount = forY.asJavaConstant().asInt();
  78             int originalAmout = amount;
  79             int mask = op.getShiftAmountMask(stamp);
  80             amount &= mask;
  81             if (amount == 0) {
  82                 return forX;
  83             }
  84 
  85             Stamp xStampGeneric = forX.stamp(view);
  86             if (xStampGeneric instanceof IntegerStamp) {
  87                 IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
  88                 long xMask = CodeUtil.mask(xStamp.getBits());
  89                 long xLowerBound = xStamp.lowerBound() & xMask;
  90                 long xUpperBound = xStamp.upperBound() & xMask;
  91 
  92                 if (xLowerBound >>> amount == xUpperBound >>> amount) {
  93                     // The result of the shift is constant.
  94                     return ConstantNode.forIntegerKind(stamp.getStackKind(), xLowerBound >>> amount);
  95                 }
  96 
  97                 if (amount == xStamp.getBits() - 1 && xStamp.lowerBound() == -1 && xStamp.upperBound() == 0) {
  98                     // Shift is equivalent to a negation, i.e., turns -1 into 1 and keeps 0 at 0.
  99                     return NegateNode.create(forX, view);
 100                 }
 101             }
 102 
 103             if (forX instanceof ShiftNode) {
 104                 ShiftNode<?> other = (ShiftNode<?>) forX;
 105                 if (other.getY().isConstant()) {
 106                     int otherAmount = other.getY().asJavaConstant().asInt() & mask;
 107                     if (other instanceof UnsignedRightShiftNode) {
 108                         int total = amount + otherAmount;
 109                         if (total != (total & mask)) {
 110                             return ConstantNode.forIntegerKind(stamp.getStackKind(), 0);
 111                         }
 112                         return new UnsignedRightShiftNode(other.getX(), ConstantNode.forInt(total));
 113                     } else if (other instanceof LeftShiftNode && otherAmount == amount) {
 114                         if (stamp.getStackKind() == JavaKind.Long) {


< prev index next >