RFR: 8356176: C2 MemorySegment: missing RCE with byteSize() in Loop Exit Check inside the for Expression [v3]

Manuel Hässig mhaessig at openjdk.org
Tue Aug 12 16:45:14 UTC 2025


On Tue, 12 Aug 2025 14:58:12 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>>> How is this impacted if we have wins on both the entry and the backedge? Is that possible? Do we have any benchmarks here?
>> 
>> In general, we ignore the wins on the entry. So it is profitable if the wins on the loop back is greater than the threshold.
>
> Sure, I gathered as much. It would still be nice to have some examples / IR-tests / JMH-benchmarks here. Just to make sure we are getting the conditions right.

Is this better?

// Is this split profitable with respect to the policy?
    // In general this means that the split has to have more wins than specified
    // in the policy. However, for loops we need to take into account where the
    // wins happen.
    bool profitable(int policy) const {
      assert(_region->is_Loop() || (_loop_entry_wins == 0 && _loop_back_wins == 0), "wins on loop edges without a loop");

      // In loops, we need to be careful when splitting, because splitting nodes
      // related to the iv through the phi can sufficiently rearrange the loop
      // structure to prevent RCE and thus vectorization. Thus, we only deem splitting
      // profitable if the win of a split is not on the entry edge, as such wins
      // only pay off once and have a high chance of messing up the loop structure.
      return (_loop_entry_wins == 0 && _total_wins > policy) ||
      // If there are wins on the entry edge but the backadge also has sufficient wins,
      // there is sufficient profitability to spilt regardless of the risk of messing
      // up the loop structure.
             _loop_back_wins > policy ||
      // If the policy is less than 0, a split is always profitable, i.e. we always
      // split. This is needed when we split a node and then must also split a
      // dependant node, i.e. spliting a Bool node after splitting a Cmp node.
             policy < 0;
    }

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26429#discussion_r2270534465


More information about the hotspot-compiler-dev mailing list