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

            Bug ID: 117346
           Summary: ccmp does not go through canonicalize_comparison
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: middle-end
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 85605
  Target Milestone: ---

Take (before the patch for PR 85605):
```
static inline int
GT (unsigned int x)
{
  return x > 0xfefffffe;
}

int
check1 (int x, int y)
{
  if (GT (x) && x > y)
    return 100;

  return x;
}

int
check (int x, int y)
{
  if ( x > y && GT (x))
    return 100;

  return x;
}
```

Right now check produces:
```
        mov     w1, -16777217
        cmp     w0, w1
        mov     w1, 100
        csel    w0, w0, w1, cc
```

While check1 produces:
```
        mov     w1, 65534
        movk    w1, 0xfeff, lsl 16
        ccmp    w0, w1, 0, gt
```
Which is the same except check is smaller. That is due to going through
canonicalize_comparison which was added in r9-2428-gec18e48eaa0d7e . But the
ccmp generation does not go through emit_store_flag_1 or prepare_cmp_insn so
this optimization is missed.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85605
[Bug 85605] Potentially missing optimization under x64 and ARM: seemingly
unnecessary branch in codegen

Reply via email to