< prev index next >

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

Print this page




 148                 return new IntegerEqualsNode(newX, newY);
 149             }
 150             throw GraalError.shouldNotReachHere();
 151         }
 152 
 153         @Override
 154         public LogicNode canonical(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth, CanonicalCondition condition,
 155                         boolean unorderedIsTrue, ValueNode forX, ValueNode forY, NodeView view) {
 156             if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
 157                 return LogicConstantNode.tautology();
 158             } else if (forX.stamp(view).alwaysDistinct(forY.stamp(view))) {
 159                 return LogicConstantNode.contradiction();
 160             }
 161 
 162             if (forX instanceof AddNode && forY instanceof AddNode) {
 163                 AddNode addX = (AddNode) forX;
 164                 AddNode addY = (AddNode) forY;
 165                 ValueNode v1 = null;
 166                 ValueNode v2 = null;
 167                 if (addX.getX() == addY.getX()) {

 168                     v1 = addX.getY();
 169                     v2 = addY.getY();
 170                 } else if (addX.getX() == addY.getY()) {

 171                     v1 = addX.getY();
 172                     v2 = addY.getX();
 173                 } else if (addX.getY() == addY.getX()) {

 174                     v1 = addX.getX();
 175                     v2 = addY.getY();
 176                 } else if (addX.getY() == addY.getY()) {

 177                     v1 = addX.getX();
 178                     v2 = addY.getX();
 179                 }
 180                 if (v1 != null) {
 181                     assert v2 != null;
 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) {


 288     @Override
 289     public Stamp getSucceedingStampForY(boolean negated, Stamp xStamp, Stamp yStamp) {
 290         if (!negated) {
 291             return xStamp.join(yStamp);
 292         }
 293         return null;
 294     }
 295 
 296     @Override
 297     public TriState tryFold(Stamp xStampGeneric, Stamp yStampGeneric) {
 298         if (xStampGeneric instanceof IntegerStamp && yStampGeneric instanceof IntegerStamp) {
 299             IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
 300             IntegerStamp yStamp = (IntegerStamp) yStampGeneric;
 301             if (xStamp.alwaysDistinct(yStamp)) {
 302                 return TriState.FALSE;
 303             } else if (xStamp.neverDistinct(yStamp)) {
 304                 return TriState.TRUE;
 305             }
 306         }
 307         return TriState.UNKNOWN;















 308     }
 309 }


 148                 return new IntegerEqualsNode(newX, newY);
 149             }
 150             throw GraalError.shouldNotReachHere();
 151         }
 152 
 153         @Override
 154         public LogicNode canonical(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth, CanonicalCondition condition,
 155                         boolean unorderedIsTrue, ValueNode forX, ValueNode forY, NodeView view) {
 156             if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
 157                 return LogicConstantNode.tautology();
 158             } else if (forX.stamp(view).alwaysDistinct(forY.stamp(view))) {
 159                 return LogicConstantNode.contradiction();
 160             }
 161 
 162             if (forX instanceof AddNode && forY instanceof AddNode) {
 163                 AddNode addX = (AddNode) forX;
 164                 AddNode addY = (AddNode) forY;
 165                 ValueNode v1 = null;
 166                 ValueNode v2 = null;
 167                 if (addX.getX() == addY.getX()) {
 168                     // (x + y) == (x + z) => y == z
 169                     v1 = addX.getY();
 170                     v2 = addY.getY();
 171                 } else if (addX.getX() == addY.getY()) {
 172                     // (x + y) == (z + x) => y == z
 173                     v1 = addX.getY();
 174                     v2 = addY.getX();
 175                 } else if (addX.getY() == addY.getX()) {
 176                     // (y + x) == (x + z) => y == z
 177                     v1 = addX.getX();
 178                     v2 = addY.getY();
 179                 } else if (addX.getY() == addY.getY()) {
 180                     // (y + x) == (z + x) => y == z
 181                     v1 = addX.getX();
 182                     v2 = addY.getX();
 183                 }
 184                 if (v1 != null) {
 185                     assert v2 != null;
 186                     return create(v1, v2, view);
 187                 }
 188             }
 189 
 190             if (forX instanceof SubNode && forY instanceof SubNode) {
 191                 SubNode subX = (SubNode) forX;
 192                 SubNode subY = (SubNode) forY;
 193                 ValueNode v1 = null;
 194                 ValueNode v2 = null;
 195                 if (subX.getX() == subY.getX()) {
 196                     // (x - y) == (x - z) => y == z
 197                     v1 = subX.getY();
 198                     v2 = subY.getY();
 199                 } else if (subX.getY() == subY.getY()) {
 200                     // (y - x) == (z - x) => y == z
 201                     v1 = subX.getX();
 202                     v2 = subY.getX();
 203                 }
 204                 if (v1 != null) {
 205                     assert v2 != null;
 206                     return create(v1, v2, view);
 207                 }
 208             }
 209 
 210             if (forX instanceof AddNode) {
 211                 AddNode addNode = (AddNode) forX;
 212                 if (addNode.getX() == forY) {
 213                     // (x + y) == x => y == 0
 214                     return create(addNode.getY(), ConstantNode.forIntegerStamp(view.stamp(addNode), 0), view);
 215                 } else if (addNode.getY() == forY) {
 216                     // (x + y) == y => x == 0
 217                     return create(addNode.getX(), ConstantNode.forIntegerStamp(view.stamp(addNode), 0), view);
 218                 }
 219             }
 220 
 221             if (forY instanceof AddNode) {
 222                 AddNode addNode = (AddNode) forY;
 223                 if (addNode.getX() == forX) {
 224                     // x == (x + y) => y == 0
 225                     return create(addNode.getY(), ConstantNode.forIntegerStamp(view.stamp(addNode), 0), view);
 226                 } else if (addNode.getY() == forX) {
 227                     // y == (x + y) => x == 0
 228                     return create(addNode.getX(), ConstantNode.forIntegerStamp(view.stamp(addNode), 0), view);
 229                 }
 230             }
 231 
 232             if (forX instanceof SubNode) {
 233                 SubNode subNode = (SubNode) forX;
 234                 if (subNode.getX() == forY) {
 235                     // (x - y) == x => y == 0
 236                     return create(subNode.getY(), ConstantNode.forIntegerStamp(view.stamp(subNode), 0), view);
 237                 }
 238             }
 239 
 240             if (forY instanceof SubNode) {
 241                 SubNode subNode = (SubNode) forY;
 242                 if (forX == subNode.getX()) {
 243                     // x == (x - y) => y == 0
 244                     return create(subNode.getY(), ConstantNode.forIntegerStamp(view.stamp(subNode), 0), view);
 245                 }
 246             }
 247 
 248             return super.canonical(constantReflection, metaAccess, options, smallestCompareWidth, condition, unorderedIsTrue, forX, forY, view);
 249         }
 250 
 251         @Override
 252         protected LogicNode canonicalizeSymmetricConstant(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth,
 253                         CanonicalCondition condition, Constant constant, ValueNode nonConstant, boolean mirrored, boolean unorderedIsTrue, NodeView view) {
 254             if (constant instanceof PrimitiveConstant) {
 255                 PrimitiveConstant primitiveConstant = (PrimitiveConstant) constant;
 256                 IntegerStamp nonConstantStamp = ((IntegerStamp) nonConstant.stamp(view));
 257                 if ((primitiveConstant.asLong() == 1 && nonConstantStamp.upperBound() == 1 && nonConstantStamp.lowerBound() == 0) ||
 258                                 (primitiveConstant.asLong() == -1 && nonConstantStamp.upperBound() == 0 && nonConstantStamp.lowerBound() == -1)) {
 259                     // nonConstant can only be 0 or 1 (respective -1), test against 0 instead of 1
 260                     // (respective -1) for a more canonical graph and also to allow for faster
 261                     // execution
 262                     // on specific platforms.
 263                     return LogicNegationNode.create(
 264                                     IntegerEqualsNode.create(constantReflection, metaAccess, options, smallestCompareWidth, nonConstant, ConstantNode.forIntegerStamp(nonConstantStamp, 0),
 265                                                     view));
 266                 } else if (primitiveConstant.asLong() == 0) {
 267                     if (nonConstant instanceof AndNode) {


 350     @Override
 351     public Stamp getSucceedingStampForY(boolean negated, Stamp xStamp, Stamp yStamp) {
 352         if (!negated) {
 353             return xStamp.join(yStamp);
 354         }
 355         return null;
 356     }
 357 
 358     @Override
 359     public TriState tryFold(Stamp xStampGeneric, Stamp yStampGeneric) {
 360         if (xStampGeneric instanceof IntegerStamp && yStampGeneric instanceof IntegerStamp) {
 361             IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
 362             IntegerStamp yStamp = (IntegerStamp) yStampGeneric;
 363             if (xStamp.alwaysDistinct(yStamp)) {
 364                 return TriState.FALSE;
 365             } else if (xStamp.neverDistinct(yStamp)) {
 366                 return TriState.TRUE;
 367             }
 368         }
 369         return TriState.UNKNOWN;
 370     }
 371 
 372     @Override
 373     public TriState implies(boolean thisNegated, LogicNode other) {
 374         // x == y => !(x < y)
 375         // x == y => !(y < x)
 376         if (!thisNegated && other instanceof IntegerLessThanNode) {
 377             ValueNode otherX = ((IntegerLessThanNode) other).getX();
 378             ValueNode otherY = ((IntegerLessThanNode) other).getY();
 379             if ((getX() == otherX && getY() == otherY) || (getX() == otherY && getY() == otherX)) {
 380                 return TriState.FALSE;
 381             }
 382         }
 383 
 384         return super.implies(thisNegated, other);
 385     }
 386 }
< prev index next >