On 2/10/23 15:41, Philipp Tomsich wrote:
When if-conversion encounters sequences using immediates, the
sequences can't trivially map back onto czero.eqz/czero.nezt (even if
benefitial) due to czero.eqz/czero.nez not having immediate forms.

This adds a splitter to rewrite opportunities for Zicond that operate
on an immediate by first putting the immediate into a register to
enable the non-immediate czero.eqz/czero.nez instructions to operate
on the value.

Consider code, such as

   long func2 (long a, long c)
   {
     if (c)
       a = 2;
     else
       a = 5;
     return a;
   }

which will be converted to

   func2:
        seqz    a0,a2
        neg     a0,a0
        andi    a0,a0,3
        addi    a0,a0,2
        ret

Following this change, we generate

        li      a0,3
        czero.nez a0,a0,a2
        addi    a0,a0,2
        ret

This commit also introduces a simple unit test for if-conversion with
immediate (literal) values as the sources for simple sets in the THEN
and ELSE blocks. The test checks that the conditional-zero instruction
(czero.eqz/nez) is emitted as part of the resulting branchless
instruction sequence.

gcc/ChangeLog:

        * config/riscv/zicond.md: Support immediates for
        czero.eqz/czero.nez through a splitter.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/zicond-ifconv-imm.c: New test.
Same comment & resolution as with the #3 in this series.

A note though. I've got Raphael looking at wiring this capability into the mov<mode>cc expander as well. When complete that *may* make this patch largely obsolete. But I don't think we necessarily need to wait for that to work to land this patch.

jeff

Reply via email to