RFR: 8349563: Improve AbsNode::Value() for integer types

Jasmine Karthikeyan jkarthikeyan at openjdk.org
Wed Apr 2 14:33:00 UTC 2025


On Thu, 27 Feb 2025 02:38:09 GMT, Dean Long <dlong at openjdk.org> wrote:

>> Hi all,
>> This is a small patch that improves the implementation of Value() for `AbsINode` and `AbsLNode` by returning the absolute value of the input range. Most of the logic is trivial except for the special case where `_lo == jint_min/jlong_min` which must return the entire type range when encountered, for which I've added a small proof in the comments. I've also added some unit tests and updated the file to limit IR check platforms with more granularity.
>> 
>> Thoughts and reviews would be appreciated!
>
> src/hotspot/share/opto/subnode.cpp line 1938:
> 
>> 1936: 
>> 1937:   NativeType lo_abs = uabs(t->_lo);
>> 1938:   NativeType hi_abs = uabs(t->_hi);
> 
> Converting unsigned to signed is C++ Undefined Behavior, is it not?

This is a great point, I believe you're correct that it's UB. We currently do the same logic in the old code as well:
https://github.com/openjdk/jdk/blob/a0677d94d8c83a75cee054700e098faa97edca3c/src/hotspot/share/opto/subnode.cpp#L1945-L1947
However, I'm unsure what the best way to solve this would be. Do you happen to have any ideas? Thanks a lot!

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23685#discussion_r2024955772


More information about the hotspot-compiler-dev mailing list