RFR: 8276563: Undefined Behaviour in class Assembler [v7]

Andrew Haley aph at openjdk.java.net
Wed Nov 17 14:13:36 UTC 2021


On Tue, 16 Nov 2021 17:58:22 GMT, Mai Đặng Quân Anh <duke at openjdk.java.net> wrote:

>> Andrew Haley has updated the pull request incrementally with two additional commits since the last revision:
>> 
>>  - Whitespace
>>  - Simplify and improve portability.
>
> src/hotspot/cpu/aarch64/register_aarch64.hpp line 62:
> 
>> 60:   // accessors
>> 61:   int encoding() const             { assert(is_valid(), "invalid register"); return encoding_nocheck(); }
>> 62:   bool is_valid() const            { return this >= first() && this - first() < number_of_registers; }
> 
> Some tiny suggestions, an unsigned comparison between `this - first()` and `number_of_registers` would be sufficient here.
> Suggestion:
> 
>   bool is_valid() const            { (unsigned)(this - first()) < number_of_registers; }

OK.
To my surprise, this really does generate better code. I've been a GCC maintainer for a very long time, and I could have sworn that we did this optimization in the last century.

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

PR: https://git.openjdk.java.net/jdk/pull/6280


More information about the hotspot-compiler-dev mailing list