https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123884

Milan Tripkovic <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #1 from Milan Tripkovic <[email protected]> ---
Created attachment 64180
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64180&action=edit
Proposed Patch

Hello,
As shown in the examples, combine produces patterns of the form:
> (set (reg:DI 142)
>    (xor:DI (sign_extend:DI (ashift:SI (const_int 1 [0x1])
>                (subreg:QI (reg:DI 145 [ i_denom ]) 0)))
>        (reg:DI 144 [ dst ])))

These fail to match the existing bitmanip patterns because the sign_extend
prevents recognition, even though semantically the upper 32 bits are irrelevant
except for satisfying the ABI.

To address this, I introduced a define_insn_and_split patterns:

bclr_sextw_pair and <code>_sextw_pair

Which matches the combined form and lowers it into:
bclr (or corresponding bitmanip op) on the 32-bit subword
followed by an explicit sext.w
This allows combine to recognize the opportunity while still preserving ABI
correctness.

<code>_sextw_pair contains code_iterator any_or which includes ior and xor,
so we don’t need two separate patterns for bset and binv.

I have regression tested these changes on  riscv64 and added 3 new tests for
bclr, binv and bset.

Reply via email to