RFR: 8347901: C2 should remove unused leaf / pure runtime calls [v2]

Emanuel Peter epeter at openjdk.org
Fri Jun 20 13:45:32 UTC 2025


On Fri, 20 Jun 2025 07:50:54 GMT, Marc Chevalier <mchevalier at openjdk.org> wrote:

>> src/hotspot/share/opto/divnode.cpp line 1642:
>> 
>>> 1640:   }
>>> 1641:   assert(projs.catchall_ioproj == nullptr, "no exceptions from floating mod");
>>> 1642:   assert(projs.catchall_catchproj == nullptr, "no exceptions from floating mod");
>> 
>> Why were you able to remove this?
>
> Pure functions have only control input, data inputs (1 or 2 in practice, so far), control output and data output: they can't alter the memory, they can't throw etc since they are pure. All these output were already unnecessary (which I noticed when working on removing modulo a few months ago), and are now simply not present, so the rewiring is useless.

Great! When I remove code like that, then I often just leave a "info" code comment, just to help the reviewers - you don't need to do that, it's just an idea ;)

>> src/hotspot/share/opto/multnode.cpp line 177:
>> 
>>> 175:   }
>>> 176:   return this;
>>> 177: }
>> 
>> What would happen if we miss to do this optimization? I suppose we would have a Tuple left in the graph and get a bad AD file assert / deopt in product?
>
> Exactly. Bad AD file. I don't think it's possible at the moment because when we return a tuple node during IGVN instead of a call, the user (all projections) are added to the worklist and they will all skip the tuple. As used for now, a Tuple should appear and disappear in the same IGVN.

Yes, I think it is safe. And if we did indeed forget to remove it at some point, we would deopt at the "bad AD file", and that's not horrible. And we would catch it with the corresponding assert. Reasonable :)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25760#discussion_r2159031237
PR Review Comment: https://git.openjdk.org/jdk/pull/25760#discussion_r2159035323


More information about the graal-dev mailing list