question for ZCMP compile
Jeff Law
jeffreyalaw@gmail.com
Tue Sep 1 06:37:45 GMT 2026
On 8/31/26 9:02 PM, 冯尚功 via Gcc-help wrote:
> Dear RISC-V GCC Maintainers,
>
>
> I am writing to seek your guidance on generating Zcmp instructions (cm.push, cm.pop, etc.) when compiling for an RV32E target using GCC 16.
> Environment & Configuration:
> Compiler: GCC 16.1.0 (Custom build based on riscv-gnu-toolchain)
> Target Architecture: -march=rv32emc_zicsr_zcmp -mabi=ilp32e
> Optimization Level: -O1 (with -fshrink-wrap-separate enabled)
> The Issue:
> I need to generate Zcmp instructions under the -O1 optimization level for performance reasons, but I do not want to use -Os. Currently, -O1 rarely generates Zcmp instructions for this target.
> I have investigated the compiler parameters and found that running riscv32-unknown-elf-gcc -Q --help=params | grep -iE 'zcmp|compress' yields no Zcmp-specific tuning parameters (such as riscv-zcmp-max-stack-size or similar). It seems the Zcmp tuning parameter interface might not be fully exposed in this GCC 16 build.
> My Questions:
> 1. Is there a specific way or a hidden compiler flag to force/encourage Zcmp instruction generation under -O1 for the rv32emc_zcmp + ilp32e combination?
> 2. Since RV32E only has two callee-saved registers (s0 and s1), does the Zcmp selector require specific code patterns (e.g., explicitly binding both registers) to meet the minimum threshold under -O1?
> 3. Are there any known limitations or missing patches in the current GCC 16 development branch regarding Zcmp support for RV32E?
> Any insights, recommended compiler flags, or code-level workarounds would be highly appreciated.
> Thank you for your time and support.
In general, if you're using separate shrink wrapping, then I would not
expect to see any Zcmp stuff firing. Also note that cm.popretz was also
disabled due to some very nasty bugs in its implementation. That was
gcc-15 and I believe that it stayed in that state for gcc-16 with Kito
fixing those bugs on the trunk for next year's gcc-17 release.
Kito probably has additional state on why separate shrink wrapping and
Zcmp don't play well together -- I don't typically work 32bit or any of
the more embedded focused extensions.
If you have cases which you think should work which aren't, I would
recommend filing a bug so that the problem can be tracked.
gcc.gnu.org/bugzilla.
Jeff
More information about the Gcc-help
mailing list