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

            Bug ID: 128553
           Summary: SAT_MUL(a,2) vs SAT_ADD(a,a) code generation
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---
            Target: riscv

Take:
```
unsigned long f_add(unsigned long a)
{
    unsigned long res;
    if (__builtin_add_overflow (a,a,&res))
      res = -1;
    return res;
}

unsigned long f_mult(unsigned long a)
{
    unsigned long res;
    if (__builtin_mul_overflow (a,2ul,&res))
      res = -1;
    return res;
}

unsigned long f_mult_alt(unsigned long a)
{
    unsigned long res;
    if (__builtin_mul_overflow (a,2u,&res))
      res = -1;
    return res;
}
```

I had assumed these 3 functions produce the same results but currently only
f_mult_alt produces decent results.

Reply via email to