On Tue, 12 May 2026 14:04:34 GMT, Tobias Hartmann <[email protected]> wrote:
>> The problem is that we are pushing casts through InlineTypeNodes without >> checking if their types are even compatible. In dead parts of the graph, >> when a type check wasn't folded yet, the type of the CheckCastPP can be >> completely unrelated to the type of the InlineTypeNode. Pushing the cast >> through leads to an incorrect type being used further below in the graph and >> subsequent failures. >> >> I tried hard to come up with standalone reproducer for this but failed. It >> reproduces reliably with replay compilation though. >> >> Thanks, >> Tobias >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Tobias Hartmann has updated the pull request incrementally with one > additional commit since the last revision: > > Fixed check Yes, an alternative fix would be to move the `TypeNode::Ideal` call to before this optimization to let it fold the CheckCastPP aggresively: diff --git a/src/hotspot/share/opto/castnode.cpp b/src/hotspot/share/opto/castnode.cpp index c46045c9810..aa7fae8369e 100644 --- a/src/hotspot/share/opto/castnode.cpp +++ b/src/hotspot/share/opto/castnode.cpp @@ -115,6 +115,13 @@ Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) { return this; } + if (in(1) != nullptr && phase->type(in(1)) != Type::TOP) { + Node* progress = TypeNode::Ideal(phase, can_reshape); + if (progress != nullptr) { + return progress; + } + } + // Push cast through InlineTypeNode InlineTypeNode* vt = in(1)->isa_InlineType(); if (vt != nullptr && vt->is_allocated(phase)) { @@ -128,10 +135,6 @@ Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) { return vt; } - if (in(1) != nullptr && phase->type(in(1)) != Type::TOP) { - return TypeNode::Ideal(phase, can_reshape); - } - return nullptr; } However, we would fail again when running with `-XX:-KillPathsReachableByDeadTypeNode` which is "ok" but something we would like to avoid. ------------- PR Comment: https://git.openjdk.org/valhalla/pull/2423#issuecomment-4432961797
