< prev index next >

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

Print this page

        

@@ -82,11 +82,11 @@
             long constY = forY.asJavaConstant().asLong();
             IntegerStamp xStamp = (IntegerStamp) forX.stamp(view);
             IntegerStamp yStamp = (IntegerStamp) forY.stamp(view);
             if (constY < 0 && constY != CodeUtil.minValue(yStamp.getBits())) {
                 Stamp newStamp = IntegerStamp.OPS.getRem().foldStamp(forX.stamp(view), forY.stamp(view));
-                return canonical(null, forX, ConstantNode.forIntegerStamp(yStamp, -constY), zeroCheck, newStamp, view, tool);
+                return canonical(self, forX, ConstantNode.forIntegerStamp(yStamp, -constY), zeroCheck, newStamp, view, tool);
             }
 
             if (constY == 1) {
                 return ConstantNode.forIntegerStamp(stamp, 0);
             } else if (CodeUtil.isPowerOf2(constY) && tool != null && tool.allUsagesAvailable()) {

@@ -102,14 +102,23 @@
                         return new NegateNode(new AndNode(new NegateNode(forX), ConstantNode.forIntegerStamp(stamp, constY - 1)));
                     }
                 }
             }
         }
-        return self != null ? self : new SignedRemNode(forX, forY, zeroCheck);
+        if (self != null && self.x == forX && self.y == forY) {
+            return self;
+        } else {
+            return new SignedRemNode(forX, forY, zeroCheck);
+        }
     }
 
     private static boolean allUsagesCompareAgainstZero(SignedRemNode self) {
+        if (self == null) {
+            // If the node was not yet created, then we do not know its usages yet.
+            return false;
+        }
+
         int compareAgainstZero = 0;
         int usageCount = self.getUsageCount();
         for (int i = 0; i < usageCount; i++) {
             Node usage = self.getUsageAt(i);
             if (usage instanceof IntegerEqualsNode) {
< prev index next >