Skip to content

Commit 28d4d66

Browse files
committed
Backport to 22.3: Don't consider distinct reads equivalent
1 parent 983fdc5 commit 28d4d66

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

  • compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes

‎compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/ValueNode.java‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -27,16 +27,19 @@
2727
import java.util.Iterator;
2828

2929
import org.graalvm.compiler.core.common.type.Stamp;
30+
import org.graalvm.compiler.debug.GraalError;
3031
import org.graalvm.compiler.graph.Node;
3132
import org.graalvm.compiler.graph.NodeBitMap;
3233
import org.graalvm.compiler.graph.NodeClass;
3334
import org.graalvm.compiler.graph.NodeStack;
3435
import org.graalvm.compiler.graph.Position;
3536
import org.graalvm.compiler.graph.iterators.NodePredicate;
37+
import org.graalvm.compiler.graph.spi.NodeWithIdentity;
3638
import org.graalvm.compiler.nodeinfo.InputType;
3739
import org.graalvm.compiler.nodeinfo.NodeInfo;
3840
import org.graalvm.compiler.nodeinfo.Verbosity;
3941
import org.graalvm.compiler.nodes.calc.FloatingNode;
42+
import org.graalvm.compiler.nodes.memory.MemoryAccess;
4043
import org.graalvm.compiler.nodes.spi.NodeValueMap;
4144

4245
import 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

Comments
 (0)