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

            Bug ID: 89430
           Summary: A missing ifcvt optimization to generate csel
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jiangning.liu at amperecomputing dot com
  Target Milestone: ---

For a small case,

unsigned *a;
void test(unsigned k, unsigned b) {
        if (b < a[k]) {
                a[k] = b;
        }
}

"gcc -O3 -S" generates,

        adrp    x2, a
        uxtw    x0, w0
        ldr     x2, [x2, #:lo12:a]
        ldr     w3, [x2, x0, lsl 2]
        cmp     w3, w1
        bls     .L1
        str     w1, [x2, x0, lsl 2]

Actually we should use csel instruction instead of conditional branch, so
expect to have the followings generated,

        adrp    x2, a
        uxtw    x0, w0
        ldr     x2, [x2, #:lo12:a]
        ldr     w3, [x2, x0, lsl 2]
        cmp     w3, w1
        csel    w1, w1, w3, hi
        str     w1, [x2, x0, lsl 2]

RTL optimization ifcvt misses this opportunity.

Reply via email to