RFR: 8347901: C2 should remove unused leaf / pure runtime calls
Marc Chevalier
mchevalier at openjdk.org
Fri Jun 20 07:53:30 UTC 2025
On Wed, 18 Jun 2025 14:40:07 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> A first part toward a better support of pure functions, but this time, with guidance from @iwanowww.
>>
>> ## Pure Functions
>>
>> Pure functions (considered here) are functions that have no side effects, no effect on the control flow (no exception or such), cannot deopt etc.. It's really a function that you can execute anywhere, with whichever arguments without effect other than wasting time. Integer division is not pure as dividing by zero is throwing. But many floating point functions will just return `NaN` or `+/-infinity` in problematic cases.
>>
>> ## Scope
>>
>> We are not going all powerful for now! It's mostly about identifying some pure functions and being able to remove them if the result is unused. Some other things are not part of this PR, on purpose. Especially, this PR doesn't propose a way to move pure calls around. The reason is that pure calls are later expanded into regular calls, which require a control input. To be able to do the expansion, we just keep the control in the pure call as well.
>>
>> ## Implementation Overview
>>
>> We created here some new node kind for pure calls, inheriting leaf calls, that are expanded into regular leaf calls during final graph reshaping. The possibility to support pure call directly in AD file is left open.
>>
>> This PR also introduces `TupleNode` (largely based on an original idea/implem of @iwanowww), that just tie multiple input together and play well with `ProjNode`: the n-th projection of a `TupleNode` is the n-th input of the tuple. This is a convenient way to skip and remove nodes from the graph while delegating the difficulty of the surgery to the trusted IGVN's implementation.
>>
>> Thanks,
>> Marc
>
> 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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25760#discussion_r2158278198
More information about the graal-dev
mailing list