RFR: 8371065: C2 SuperWord: VTransformLoopPhiNode::apply set wrong type, led to wrong constant folding of phi [v7]

Emanuel Peter epeter at openjdk.org
Mon Nov 10 16:25:19 UTC 2025


> In `VTransformLoopPhiNode::apply`, we may have to modify the type of the phi node, because it may have been turned from a scalar phi to a vector phi by `VTransformReductionVectorNode::optimize_move_non_strict_order_reductions_out_of_loop`. This logic was refactored in https://github.com/openjdk/jdk/pull/27704, and I missed an edges case.
> 
> The issue is when we also (uslessly) set the type of phis that stay scalar: the `in1` type can be a constant, and then we set the `phi` type to be constant. And then the phi wrongly constant folds.
> 
> I now limit the modification to cases where the `phi` used to be for scalars, but now is for vectors. In those cases we should not have a constant. For good measure, I also added a corresponding assert.
> 
> ---------
> 
> Thanks @rwestrel for filing this issue and spending a lot of time reproducing it without his changes.
> I tried to find a simpler reproducer, but it was difficult: We need a constant on the lhs of the phi in the main-loop. But this requires us to constant-fold the pre-loop phi, and somehow magically not constant fold the phi of the main-loop. That is quite tricky, and I gave up.

Emanuel Peter has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 11 commits:

 - manual merge with cost model change
 - fix assert code
 - refine fix
 - wip fix, still broken
 - second reproducer
 - move fix to apply_backedge
 - add diagnostic flag for product build
 - add assert
 - rm debug printing
 - add test
 - ... and 1 more: https://git.openjdk.org/jdk/compare/72989e0f...dfc7c87e

-------------

Changes: https://git.openjdk.org/jdk/pull/28113/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28113&range=06
  Stats: 286 lines in 4 files changed: 256 ins; 6 del; 24 mod
  Patch: https://git.openjdk.org/jdk/pull/28113.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28113/head:pull/28113

PR: https://git.openjdk.org/jdk/pull/28113


More information about the hotspot-compiler-dev mailing list