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

            Bug ID: 105477
           Summary: RISC-V: Regression: Useless moves in conditional
                    select return
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophm30 at gmail dot com
  Target Milestone: ---

Commit 3a7ba8fd triggers a regression so that on RISC-V two useless move
instructions are generated.

Test code:
"""
long test(long a, long b, long c)
{
  return (!c ? a : b);
}
"""

GCC 10.2.0, GCC 11 or upstream/master before 3a7ba8fd generates (rv64gc + -O3):
test:
        beq     a2,zero,.L2
        mv      a0,a1
.L2:
        ret

Current upstream/master generates:
<test>:
   0:   87aa                    mv      a5,a0
   2:   852e                    mv      a0,a1
   4:   e211                    bnez    a2,8 <.L2>
   6:   853e                    mv      a0,a5
<.L2>:
   8:   8082                    ret

This might be an issue in the ifcvt code (in combination of the RISC-V backend)
or something where the RISC-V backend needs to improve.

Some context to this issue:
* The mentioned change (3a7ba8fd) is not problematic at all and fixes an issue
PR104960
* PR105314 reports a similar issue, that is also triggered by the same change

Reply via email to