11/*
2- * Copyright (c) 2009, 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2009, 2023 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2727import java .util .Iterator ;
2828
2929import org .graalvm .compiler .core .common .type .Stamp ;
30+ import org .graalvm .compiler .debug .GraalError ;
3031import org .graalvm .compiler .graph .Node ;
3132import org .graalvm .compiler .graph .NodeBitMap ;
3233import org .graalvm .compiler .graph .NodeClass ;
3334import org .graalvm .compiler .graph .NodeStack ;
3435import org .graalvm .compiler .graph .Position ;
3536import org .graalvm .compiler .graph .iterators .NodePredicate ;
37+ import org .graalvm .compiler .graph .spi .NodeWithIdentity ;
3638import org .graalvm .compiler .nodeinfo .InputType ;
3739import org .graalvm .compiler .nodeinfo .NodeInfo ;
3840import org .graalvm .compiler .nodeinfo .Verbosity ;
3941import org .graalvm .compiler .nodes .calc .FloatingNode ;
42+ import org .graalvm .compiler .nodes .memory .MemoryAccess ;
4043import org .graalvm .compiler .nodes .spi .NodeValueMap ;
4144
4245import jdk .vm .ci .meta .Constant ;
@@ -256,7 +259,7 @@ public boolean recursivelyDataFlowEqualsUpTo(FloatingNode that, InputType ignore
256259 if (this == that ) {
257260 return true ;
258261 }
259- if (this . getNodeClass () != that . getNodeClass () || !this . valueEquals ( that )) {
262+ if (that == null || !recursiveDataFlowEqualsHelper ( this , that )) {
260263 return false ;
261264 }
262265
@@ -298,7 +301,7 @@ public boolean recursivelyDataFlowEqualsUpTo(FloatingNode that, InputType ignore
298301 if (thisInput == thatInput ) {
299302 continue ;
300303 }
301- if (thisInput == null || thatInput == null || thisInput . getNodeClass () != thatInput . getNodeClass () || !( thisInput instanceof FloatingNode ) || ! thisInput . valueEquals ( thatInput )) {
304+ if (thisInput == null || thatInput == null || ! recursiveDataFlowEqualsHelper ( thisInput , thatInput )) {
302305 return false ;
303306 }
304307 these .push (thisInput );
@@ -311,4 +314,33 @@ public boolean recursivelyDataFlowEqualsUpTo(FloatingNode that, InputType ignore
311314
312315 return true ;
313316 }
317+
318+ /**
319+ * Determines if the two nodes can be considered "value equals" in the context of
320+ * {@link #recursivelyDataFlowEqualsUpTo(FloatingNode, InputType)}. Specifically, checks if the
321+ * two nodes are of the same floating, non-identity class, have equal data fields, and are not
322+ * memory accesses that we could only consider equal if they were GVN'ed. This method only looks
323+ * at node classes and data fields, all inputs must be checked separately.
324+ *
325+ * @return {@code true} if the two nodes can be considered equal, {@code false} otherwise
326+ */
327+ private static boolean recursiveDataFlowEqualsHelper (Node thisNode , Node thatNode ) {
328+ GraalError .guarantee (thisNode != thatNode , "identity should be checked by the caller" );
329+ if (thisNode == null || thatNode == null || thisNode .getNodeClass () != thatNode .getNodeClass ()) {
330+ return false ;
331+ }
332+ if (!(thisNode instanceof FloatingNode ) || thisNode instanceof NodeWithIdentity ) {
333+ return false ;
334+ }
335+ if (!thisNode .valueEquals (thatNode )) {
336+ return false ;
337+ }
338+ if (thisNode instanceof MemoryAccess ) {
339+ MemoryAccess access = (MemoryAccess ) thisNode ;
340+ if (access .getLocationIdentity ().isAny () || access .getLocationIdentity ().isMutable ()) {
341+ return false ;
342+ }
343+ }
344+ return true ;
345+ }
314346}
0 commit comments