CT_00_052 -- Improve initial RTL generation for add/sub (GCC)
About
The add/sub expanders currently only allow a simm12 operand which forces any non-conformant constants into registers. But much like the logical op work recently integrated we can sometimes do better and avoid constant synthesis or adjust the synthesis targets.
The most obvious cases are:
Avoid constant synthesis for addi/subi cases where we can emit a series of addi/subi instructions at same cost as constant synthesis. This should subsume all the SUM_OF_TWO_S12 stuff that was added in 2024.
Use that new expander path to implement add_ptr3 which should help cases where fp→sp elimination creates out of range offsets
Sometimes it is better to negate the constant and select the opposite operator. There's an upstream bug for this case. With zbs enabled this should be a bset+sub as we can synthesize 0x20000000 more efficiently than its negation.
long foo(long a) { a -= 0x200000000; return a; }
Stakeholders/Partners
RISE:
Ventana: Jeff Law
External:
Dependencies
Status
Development | IN PROGRESS |
|
|---|---|---|
Development Timeline | 1H2025 |
|
Upstreaming | IN PROGRESS
|
|
Upstream Version | gcc-16 (target) (Spring 2026)
|
|
Contacts | Jeff Law (Ventana) |
|
Dependencies | None |
|
Updates
Jul 16, 2025
Implementation is in progress, but not ready for upstreaming or even performance analysis. Moving to 2H2025
Initial implementation is showing the codegen we want for emitting addi+addi sequences or li+shNadd sequences, but needs cleanup
Initial implementation shows promise for handling cases where we can negate the constant as well
Jun 9, 2025
Noted as a work item