Why is this brightness adjustment not getting vectorized in Clang?

Viewed 215

I tried compiling this code,

#include <stdlib.h>

struct rgb {
  int r, g, b;
};

void adjust_brightness(struct rgb *picdata, size_t len, int adjustment) {
  // assume adjustment is between 0 and 255.
  for (int i = 0; i < len; i++) {
    picdata[i].r += adjustment;
    picdata[i].g += adjustment;
    picdata[i].b += adjustment;
  }
}

on OSX using this command,

$ cc -Rpass-analysis=loop-vectorize -c -std=c99 -O3 brightness.c
brightness.c:13:3: remark: loop not vectorized: unsafe dependent memory operations in loop [-Rpass-analysis=loop-vectorize]
  for (int i = 0; i < len; i++) {
  ^

Can someone explain what is unsafe and dependent here? I'm learning about SIMD, and this was explained at the most obvious use for SIMD. I was hoping to learn how the compiler would generated SIMD instructions for a simple example. In my head, I expect the compiler to maybe instead of incrementing by 1, it would increment by enough to put the loop body into vector registers?

Do I misunderstand?

0 Answers
Related