https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88259
Ramana Radhakrishnan <ramana at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ramana at gcc dot gnu.org --- Comment #2 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> --- (In reply to ktkachov from comment #1) > 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 ISTR there is some limit in if conversion around the vectorizer where it only works on very simple if-blocks. But this is from memory and it's a bit fuzzy now.