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

            Bug ID: 123313
           Summary: `a < 10 ? b : -1` could be better
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

take:
```
int f(int a, int b, int c)
{
  a = -1;
  if (c < 10) a = b;
  return a;
}
```

Currently for -march=rv64gc_zicond -O2 GCC produces:
```
        li      a5,9
        addi    a1,a1,1
        sgt     a2,a2,a5
        czero.nez       a2,a1,a2
        addi    a0,a2,-1
```

But this could be optimized to just:
```
        slti    a0, a2, 10
        addi    a0, a0, -1
        or      a0, a0, a1
```

That is:
`((a < 10) - 1) | b`

Reply via email to