RFR: 8349523: Unused runtime calls to drem/frem should be removed

Christian Hagedorn chagedorn at openjdk.org
Thu Feb 20 09:58:52 UTC 2025


On Wed, 19 Feb 2025 12:47:03 GMT, Marc Chevalier <duke at openjdk.org> wrote:

> Remove frem and drem macros nodes when the result is not used. These nodes have other outputs (like memory), which is not meaningful, but preventing them to be dropped so easily. This patch removes the useless frem/drem nodes, and by rewiring the inputs to the outputs.
> 
> Thanks,
> Marc

What I did in my full fix for Assertion Predicates to remove a no-longer-needed CFG node (i.e. treat it as a `nop`) is to just return the input in `Identity()`:

Node* TemplateAssertionPredicateNode::Identity(PhaseGVN* phase) {
  if (phase->C->post_loop_opts_phase() || _useless) {
    return in(0);
  }
  ...
}

But since we have a `CallNode` with projections, I'm not sure if we could do the same but might be worth a try? We then probably need to add the check in `ProjNode::Identity()` and return `in(0)->in(0)` to skip over the `drem/frem` node - similar to what we do in `IfProjNode::Identity()` to skip over the `If` node that has projections:
https://github.com/openjdk/jdk/blob/1e87ff01994df16df7de331040fc5d7a4a85f630/src/hotspot/share/opto/ifnode.cpp#L1819
Not sure if we need to do it only for the control projection or all the outgoing projections of the dead `drem/frem`. 

If both worked, we can still decide if we want that additional `ProjNode::Identity()` method instead of handling it the way you propose it in this PR.

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

PR Comment: https://git.openjdk.org/jdk/pull/23694#issuecomment-2671002605


More information about the hotspot-compiler-dev mailing list