src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/MultiGuardNode.java
changeset 58299 6df94ce3ab2f
parent 52578 7dd81e82d083
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/MultiGuardNode.java	Tue Sep 24 08:54:08 2019 -0700
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/MultiGuardNode.java	Tue Sep 24 12:47:15 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,8 @@
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.graph.NodeClass;
 import org.graalvm.compiler.graph.NodeInputList;
+import org.graalvm.compiler.graph.spi.Canonicalizable;
+import org.graalvm.compiler.graph.spi.CanonicalizerTool;
 import org.graalvm.compiler.graph.spi.Simplifiable;
 import org.graalvm.compiler.graph.spi.SimplifierTool;
 import org.graalvm.compiler.nodeinfo.NodeInfo;
@@ -43,7 +45,7 @@
 import org.graalvm.compiler.nodes.util.GraphUtil;
 
 @NodeInfo(allowedUsageTypes = Guard, cycles = CYCLES_0, size = SIZE_0)
-public final class MultiGuardNode extends FloatingNode implements GuardingNode, LIRLowerable, Simplifiable, Node.ValueNumberable {
+public final class MultiGuardNode extends FloatingNode implements GuardingNode, LIRLowerable, Simplifiable, Canonicalizable, Node.ValueNumberable {
     public static final NodeClass<MultiGuardNode> TYPE = NodeClass.create(MultiGuardNode.class);
 
     @OptionalInput(Guard) NodeInputList<ValueNode> guards;
@@ -58,6 +60,20 @@
     }
 
     @Override
+    public Node canonical(CanonicalizerTool tool) {
+        // Make sure there are no nulls remaining in the set of guards references.
+        guards.trim();
+        if (guards.size() == 0) {
+            // No guards left => can delete the multi-guard.
+            return null;
+        } else if (guards.size() == 1) {
+            // Only a single guard left => replace multi-guard with that single guard.
+            return guards.get(0);
+        }
+        return this;
+    }
+
+    @Override
     public void simplify(SimplifierTool tool) {
         if (usages().filter(node -> node instanceof ValueAnchorNode).isNotEmpty()) {
             /*