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

            Bug ID: 124019
           Summary: Improve subword arithmetic and comparisons
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: law at gcc dot gnu.org
  Target Milestone: ---

Consider this code on rv64gcbv_zicond:

typedef unsigned char uint8_t;
typedef signed char int8_t;
bool f1(int8_t a)
{
    int8_t b = a << 4;
    return b == -128;
}

Generates something like this:

        slli    a0,a0,4 # 6     [c=4 l=4]  ashldi3
        sext.b  a0,a0   # 9     [c=4 l=4]  *extendqidi2_bitmanip/0
        addi    a0,a0,128       # 11    [c=4 l=4]  *adddi3/1
        seqz    a0,a0   # 20    [c=4 l=4]  *seq_zero_didi

What would be better would be to use andi to mask off all but the low 4 bits
then use addi+seqz to check of the low 4 bits are precisely 0x8.

Reply via email to