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

            Bug ID: 128420
           Summary: Redundant masking on RISC-V
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: law at gcc dot gnu.org
  Target Milestone: ---

extern const unsigned char tab[16];
int f (int y)
{
  return tab[(y & 3) << 2] + ((y & 3) == 3);
}

Compiled with -march=rv64gcbv_zicond shows code like this:

f:
        lui     a5,%hi(tab)
        andi    a4,a0,3          # y & 3
        addi    t0,a5,%lo(tab)
        sh2add  t1,a4,t0
        lbu     t2,0(t1)
        andi    a0,a0,3          # y & 3 again
        addi    a1,a0,-3
        seqz    a2,a1
        add     a0,a2,t2
        ret

Part of the problem is the define_insn_and_split hiding the y & 3 until after
reload, but even with that fixed, we still don't eliminate the redundant
computation.

Reply via email to