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

ktkachov at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-11-29
                 CC|                            |ktkachov at gcc dot gnu.org,
                   |                            |rsandifo at gcc dot gnu.org
             Blocks|                            |53947
     Ever confirmed|0                           |1

--- Comment #1 from ktkachov at gcc dot gnu.org ---
Confirmed.
Trying to find just the index (not the max value) vectorises as well:
void test_vec(int *data, int n) {
        int best_i, best = 0;

        for (int i = 0; i < n; i++) {
                if (data[i] > best) {
//                        best = data[i];
                        best_i = i;
                }
        }

        data[best_i] = data[0];
        data[0] = best;
}


-O3:
.L4:
        ldr     q1, [x2], 16
        mov     v3.16b, v2.16b
        add     v2.4s, v2.4s, v4.4s
        cmle    v1.4s, v1.4s, #0
        cmp     x2, x3
        bif     v0.16b, v3.16b, v1.16b
        bne     .L4
        smaxv   s0, v0.4s
        and     w3, w1, -4
        umov    w2, v0.s[0]
        cmn     w2, #1
        csel    w2, w2, wzr, ne
        tst     x1, 3
        beq     .L2
.L3:

But their combination seems like it's throwing the machinery off. I'm guessing
the index-finding needs some if-conversion and masking to happen in the
vectoriser


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations

Reply via email to