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

            Bug ID: 106602
           Summary: riscv: suboptimal codegen for shift left, right, left
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vineetg at rivosinc dot com
                CC: christophm30 at gmail dot com, kito at gcc dot gnu.org
  Target Milestone: ---

This came up when investigating
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106545. The test to supposedly
induce the peephole doesn't, but generates far inferior code.

unsigned long foo2(unsigned long a)
{
        return (unsigned long)(unsigned int)a << 6;
}

-march=rv64gc -O2   # no bitmanip

foo2:
        li      a5,1
        slli    a5,a5,38
        addi    a5,a5,-64
        slli    a0,a0,6
        and     a0,a0,a5
        ret

llvm generates expected

foo:
        slli    a0, a0, 32
        srli    a0, a0, 26
        ret

Reply via email to