On 12/13/23 16:00, Alex Coplan wrote:
Hi, In PR112906 we ICE because we try to use force_reg to reload an auto-increment address, but force_reg can't do this. With the aim of fixing the PR by supporting reloading arbitrary addresses in pre-RA splitters, this patch generalizes lra-constraints.cc:emit_inc and makes it available to the rest of the compiler by moving the generalized version to emit-rtl.cc. We observe that the separate IN parameter to LRA's emit_inc is redundant, since the function is static and is only (statically) called once in lra-constraints.cc, with in == value. As such, we drop the IN parameter and simplify the code accordingly.
The function was initially adopted from reload1.cc:inc_for_reload.
We wrap the emit_inc code in a virtual class to allow LRA to override how reload pseudos are created, thereby preserving the existing LRA behaviour as much as possible. We then add a second (higher-level) routine to emit-rtl.cc, force_reload_address, which can reload arbitrary addresses. This uses the generalized emit_inc code to handle the RTX_AUTOINC case. The second patch in this series uses force_reload_address to fix PR112906. Since we intend to call address_reload_context::emit_autoinc from within splitters, and the code lifted from LRA calls recog, we have to avoid clobbering recog_data. We do this by introducing a new RAII class for saving/restoring recog_data on the stack. Bootstrapped/regtested on aarch64-linux-gnu, bootstrapped on x86_64-linux-gnu, OK for trunk?
OK for me. Thank you.
gcc/ChangeLog: PR target/112906 * emit-rtl.cc (address_reload_context::emit_autoinc): New. (force_reload_address): New. * emit-rtl.h (struct address_reload_context): Declare. (force_reload_address): Declare. * lra-constraints.cc (class lra_autoinc_reload_context): New. (emit_inc): Drop IN parameter, invoke code moved to emit-rtl.cc:address_reload_context::emit_autoinc. (curr_insn_transform): Drop redundant IN parameter in call to emit_inc. * recog.h (class recog_data_saver): New.