RISC-V code generation refines arithmetic operation selection for rv64
RISC-V RV64 code generation now favors PLUS operations to better utilize sign extensions, improving code efficiency.
This commit refines the selection of arithmetic operations (AOP) for RISC-V RV64 targets. By preferring the ‘PLUS’ operation, the compiler can leverage sign extensions for free through ‘addw’ and ‘addiw’ instructions. This change can eliminate later sign extension operations, as demonstrated in a specific test case, potentially improving code performance. The impact on identifying ‘bseti’ will be monitored, with future work planned to potentially defer AOP resolution until after the combine pass.
In Details
The RISC-V backend's pattern selection for arithmetic operations has been adjusted. For rv64, the target now steers more AOP modes towards the PLUS variant. This is motivated by the observation that PLUS can incorporate sign-extension information for free via addw/addiw, reducing the need for subsequent explicit sign-extension instructions and potentially enabling further optimizations. This change might affect the cost model for 'bseti' patterns, necessitating future adjustments in the combine pass.
- AOP
- Arithmetic Operation. In this context, it refers to patterns for arithmetic operations like add, subtract, etc., within the RISC-V backend.
- RV64
- A 64-bit variant of the RISC-V instruction set architecture. It supports 64-bit registers and operations.
- Sign Extension
- The process of expanding a number's binary representation by filling the most significant bits with copies of the original sign bit. This is crucial for maintaining the value of a number when converting it from a smaller to a larger data type.
- addw/addiw
- Specific RISC-V instructions. 'addw' performs a 64-bit addition, while 'addiw' performs a 32-bit addition with sign extension to 64 bits. These can be used to efficiently handle sign extensions.
- bseti
- Likely a pattern or instruction related to setting bits, possibly involving bit manipulation or conditional operations within the RISC-V architecture.
- combine pass
- A GCC optimization pass that performs various transformations on the intermediate representation (IR) to simplify and optimize code. It often runs after other optimization passes.