RFR: 8342103: C2 compiler support for Float16 type and associated operations [v3]

Jatin Bhateja jbhateja at openjdk.org
Tue Nov 26 08:28:44 UTC 2024


On Mon, 25 Nov 2024 20:04:09 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:

>> Hi All,
>> 
>> This patch adds C2 compiler support for various Float16 operations added by [PR#22128](https://github.com/openjdk/jdk/pull/22128)
>> 
>> Following is the summary of changes included with this patch:-
>> 
>> 1. Detection of various Float16 operations through inline expansion or pattern folding idealizations.
>> 2. Float16 operations like add, sub, mul, div, max, and min are inferred through pattern folding idealization.
>> 3. Float16 SQRT and FMA operation are inferred through inline expansion and their corresponding entry points are defined in the newly added Float16Math class.
>>       -    These intrinsics receive unwrapped short arguments encoding IEEE 754 binary16 values.
>> 5. New specialized IR nodes for Float16 operations, associated idealizations, and constant folding routines.
>> 6. New Ideal type for constant and non-constant Float16 IR nodes. Please refer to [FAQs ](https://github.com/openjdk/jdk/pull/21490#issuecomment-2482867818)for more details.
>> 7. Since Float16 uses short as its storage type, hence raw FP16 values are always loaded into general purpose register, but FP16 ISA instructions generally operate over floating point registers, therefore compiler injectes reinterpretation IR before and after Float16 operation nodes to move short value to floating point register and vice versa.
>> 8. New idealization routines to optimize redundant reinterpretation chains. HF2S + S2HF = HF
>> 6. Auto-vectorization of newly supported scalar operations.
>> 7. X86 and AARCH64 backend implementation for all supported intrinsics.
>> 9. Functional and Performance validation tests.
>> 
>> Kindly review and share your feedback.
>> 
>> Best Regards,
>> Jatin
>
> Jatin Bhateja has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Review comments resolution

> Another example where I asked if we have good tests: ![image](https://private-user-images.githubusercontent.com/32593061/389841818-8fafd51e-9fed-453f-aedb-7dc6d6d17cc1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzI2MDg3MDMsIm5iZiI6MTczMjYwODQwMywicGF0aCI6Ii8zMjU5MzA2MS8zODk4NDE4MTgtOGZhZmQ1MWUtOWZlZC00NTNmLWFlZGItN2RjNmQ2ZDE3Y2MxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDExMjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQxMTI2VDA4MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTMwZTBhOTVjOGRmNzViY2ZjYWU0M2E3ZmE1ZWEzYmYzY2E1YmQxN2JiZDkwOGJiYjZhNTcxZTFmZDc3MGU2ZjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.-qd93PHlVMGcEbMblqKRIgdGc6tj-M7sq4oglGpgtSA)
> 
> And the test you point to is this: ![image](https://private-user-images.githubusercontent.com/32593061/389841921-0bfda1d7-7bc0-4e5b-8ea7-171a02a805ff.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzI2MDg3MDMsIm5iZiI6MTczMjYwODQwMywicGF0aCI6Ii8zMjU5MzA2MS8zODk4NDE5MjEtMGJmZGExZDctN2JjMC00ZTViLThlYTctMTcxYTAyYTgwNWZmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDExMjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQxMTI2VDA4MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJiMWIzYWUzYjY0NDE0NWUzMzYwMTAxMDk3MzM2YmU1MzdhNjlhZjk0ODdjN2U4OTZjMmI5YWVlMTZmMDkwZjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.bpkhyUSEqf80pl8reM1Wa7OCvPX6Z3muzqlWOVMCnjs)
> 
> It only covers a single constant `divisor = 8`. But what about divisors that are out of the allowed range, or not powers of 2? How do we know that you chose the bounds correctly, and are not off-by-1? And what about negative divisors? ![image](https://private-user-images.githubusercontent.com/32593061/389842530-8f2260e5-0075-4d34-9d30-2cec817c72f2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzI2MDg3MDMsIm5iZiI6MTczMjYwODQwMywicGF0aCI6Ii8zMjU5MzA2MS8zODk4NDI1MzAtOGYyMjYwZTUtMDA3NS00ZDM0LTlkMzAtMmNlYzgxN2M3MmYyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDExMjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQxMTI2VDA4MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ1YjNiNmY0NzQ2ZjEzMjk5ZTM1N2ZkZjk4MGRlYjYzNGRiYjg1NTQxZGViMTNhMTI1MDEyN2YxMjViYWNiNjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.7ThWV8y58sDmCuTzt
 g62HlvKu93Is1R6OiomwmSM8u8)

Please refer to my detailed comments on divide by power of two transformation, test point specifically test division to multiplication transformation if divisor is POT.

https://github.com/openjdk/jdk/pull/21490/files#diff-ff6734d21eacbbdeae65d3b11f5261cbb6158752a9ccf5fb13eb0d2e5eb3f414R829

https://github.com/openjdk/jdk/pull/21490/files#diff-ff6734d21eacbbdeae65d3b11f5261cbb6158752a9ccf5fb13eb0d2e5eb3f414R839

Hi @eme64 
I can feel the reviewer's pain,  I think adding one gtest makes sense here to test various newly added Type primitives like geth, is_nan etc and idioms being folded in newly added value transformation.

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

PR Comment: https://git.openjdk.org/jdk/pull/21490#issuecomment-2499970345


More information about the core-libs-dev mailing list