RFR: 8349563: Improve AbsNode::Value() for integer types [v4]
Quan Anh Mai
qamai at openjdk.org
Thu Aug 7 08:00:23 UTC 2025
On Thu, 3 Jul 2025 03:27:32 GMT, Jasmine Karthikeyan <jkarthikeyan 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!
>
> Jasmine Karthikeyan has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains six commits:
>
> - Code review and constant folding test
> - Merge
> - Replace uabs usage with ABS
> - Merge branch 'master' into abs-value
> - Merge
> - Improve AbsNode::Value
With unsigned bounds, you can simply do:
juint umin = MIN2<juint>(uabs(t->_ulo), uabs(t->_uhi));
juint umax = MAX2<juint>(uabs(t->_lo), uabs(t->_hi));
return TypeInt::make_unsigned(umin, umax, t->_widen);
The proof can be inferred trivially from the property of `TypeInt` (you can find this in the doc of `TypeInt`). Since the set of values of a `TypeInt` looks like this:
smin ---------- lo ===== uhi ------ 0 -----ulo ========= hi --------- smax
or (in this case `lo == ulo`, `hi == uhi`)
smin ----------- lo ======= hi --- 0 ------------------------------------- smax
or (in this case `lo == ulo`, `hi == uhi`)
smin --------------------------------- 0 ------- lo ========= hi -------- smax
You can see that in all 3 cases, the minimum of the uabs of a value is either `uabs(ulo)` or `uabs(uhi)` and the maximum is either `uabs(lo)` or `uabs(hi)`.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23685#issuecomment-3162975167
More information about the hotspot-compiler-dev
mailing list