Skip to content

Commit

Permalink
[GR-52973] [GR-53570] [GR-53628] Various fixes for compiler crashes
Browse files Browse the repository at this point in the history
PullRequest: graal/17486
  • Loading branch information
gergo- committed Apr 25, 2024
2 parents ea3bb50 + 6f4daf7 commit ef9314d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import jdk.graal.compiler.nodes.spi.CanonicalizerTool;
import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool;
import jdk.graal.compiler.nodes.util.GraphUtil;

import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.PrimitiveConstant;

Expand Down Expand Up @@ -195,7 +194,7 @@ private static ValueNode canonical(AndNode self, BinaryOp<And> op, ValueNode for
// ~x & ~y |-> ~(x | y)
return new NotNode(OrNode.create(((NotNode) forX).getValue(), ((NotNode) forY).getValue(), view));
}
if (forY instanceof NotNode && ((NotNode) forY).getValue() == forX) {
if (forY instanceof NotNode && ((NotNode) forY).getValue() == forX && rawXStamp instanceof IntegerStamp) {
// x & ~x |-> 0
return ConstantNode.forIntegerStamp(rawXStamp, 0L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jdk.graal.compiler.core.common.type.ArithmeticOpTable.ShiftOp;
import jdk.graal.compiler.core.common.type.ArithmeticOpTable.ShiftOp.Shl;
import jdk.graal.compiler.core.common.type.IntegerStamp;
import jdk.graal.compiler.core.common.type.PrimitiveStamp;
import jdk.graal.compiler.core.common.type.Stamp;
import jdk.graal.compiler.debug.Assertions;
import jdk.graal.compiler.graph.NodeClass;
Expand Down Expand Up @@ -139,7 +140,7 @@ private static ValueNode canonical(LeftShiftNode leftShiftNode, ArithmeticOpTabl
if (other instanceof LeftShiftNode) {
int total = amount + otherAmount;
if (total != (total & mask)) {
return ConstantNode.forIntegerKind(stamp.getStackKind(), 0);
return ConstantNode.forIntegerBits(PrimitiveStamp.getBits(stamp), 0);
}
return new LeftShiftNode(other.getX(), ConstantNode.forInt(total));
} else if ((other instanceof RightShiftNode || other instanceof UnsignedRightShiftNode) && otherAmount == amount) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, 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
Expand Down Expand Up @@ -108,7 +108,7 @@ protected LogicNode canonicalizeSymmetricConstant(ConstantReflectionProvider con
if (type != null && nonConstant instanceof GetClassNode) {
GetClassNode getClassNode = (GetClassNode) nonConstant;
ValueNode object = getClassNode.getObject();
assert ((ObjectStamp) object.stamp(view)).nonNull();
assert ((ObjectStamp) object.stamp(view)).nonNull() : "getClassNode %s object %s should have a non-null stamp, got: %s".formatted(getClassNode, object, object.stamp(view));
if (!type.isPrimitive() && (type.isConcrete() || type.isArray())) {
return InstanceOfNode.create(TypeReference.createExactTrusted(type), object);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, 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
Expand Down Expand Up @@ -112,7 +112,7 @@ private static ValueNode canonical(RightShiftNode rightShiftNode, ArithmeticOpTa

if (xStamp.lowerBound() >> amount == xStamp.upperBound() >> amount) {
// Right shift turns the result of the expression into a constant.
return ConstantNode.forIntegerKind(stamp.getStackKind(), xStamp.lowerBound() >> amount);
return ConstantNode.forIntegerBits(xStamp.getBits(), xStamp.lowerBound() >> amount);
}
}

Expand All @@ -128,10 +128,10 @@ private static ValueNode canonical(RightShiftNode rightShiftNode, ArithmeticOpTa
IntegerStamp istamp = (IntegerStamp) other.getX().stamp(view);

if (istamp.isPositive()) {
return ConstantNode.forIntegerKind(stamp.getStackKind(), 0);
return ConstantNode.forIntegerBits(istamp.getBits(), 0);
}
if (istamp.isStrictlyNegative()) {
return ConstantNode.forIntegerKind(stamp.getStackKind(), -1L);
return ConstantNode.forIntegerBits(istamp.getBits(), -1L);
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, 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
Expand Down Expand Up @@ -28,6 +28,7 @@
import jdk.graal.compiler.core.common.type.ArithmeticOpTable.ShiftOp;
import jdk.graal.compiler.core.common.type.ArithmeticOpTable.ShiftOp.UShr;
import jdk.graal.compiler.core.common.type.IntegerStamp;
import jdk.graal.compiler.core.common.type.PrimitiveStamp;
import jdk.graal.compiler.core.common.type.Stamp;
import jdk.graal.compiler.debug.Assertions;
import jdk.graal.compiler.graph.NodeClass;
Expand Down Expand Up @@ -97,7 +98,7 @@ private static ValueNode canonical(UnsignedRightShiftNode node, ArithmeticOpTabl

if (xLowerBound >>> amount == xUpperBound >>> amount) {
// The result of the shift is constant.
return ConstantNode.forIntegerKind(stamp.getStackKind(), xLowerBound >>> amount);
return ConstantNode.forIntegerBits(PrimitiveStamp.getBits(stamp), xLowerBound >>> amount);
}

if (amount == xStamp.getBits() - 1 && xStamp.lowerBound() == -1 && xStamp.upperBound() == 0) {
Expand All @@ -113,7 +114,7 @@ private static ValueNode canonical(UnsignedRightShiftNode node, ArithmeticOpTabl
if (other instanceof UnsignedRightShiftNode) {
int total = amount + otherAmount;
if (total != (total & mask)) {
return ConstantNode.forIntegerKind(stamp.getStackKind(), 0);
return ConstantNode.forIntegerBits(PrimitiveStamp.getBits(stamp), 0);
}
return new UnsignedRightShiftNode(other.getX(), ConstantNode.forInt(total));
} else if (other instanceof LeftShiftNode && otherAmount == amount) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, 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
Expand Down Expand Up @@ -628,6 +628,7 @@ protected void mergeEarlyExits() {
phi.setNodeSourcePosition(merge.getNodeSourcePosition());
phi.addInput(vpn);
phi.addInput(newVpn);
phi.inferStamp();
introducedPhis.add(phi);
replaceWith = phi;
} else {
Expand Down

0 comments on commit ef9314d

Please sign in to comment.