This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
GCC Auto-Vectorization with Strided Writes
- From: SDS <sds dot biz dot main at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 15 Oct 2015 23:56:48 -0400
- Subject: GCC Auto-Vectorization with Strided Writes
- Authentication-results: sourceware.org; auth=none
When compiled on GCC 5.1 using -std=c99, -O3, and -mavx2, the
following code snippet auto-vectorizes:
#include <stdint.h>
void test(uint32_t *restrict a,
uint32_t *restrict b) {
uint32_t *a_aligned = __builtin_assume_aligned(a, 32);
uint32_t *b_aligned = __builtin_assume_aligned(b, 32);
for (int i = 0; i < (1L << 10); i += 2) {
a_aligned[i] = 2 * b_aligned[i];
a_aligned[i+1] = 3 * a_aligned[i+1];
}
}
But the following code snippet does not auto-vectorize:
#include <stdint.h>
void test(uint32_t *restrict a,
uint32_t *restrict b) {
uint32_t *a_aligned = __builtin_assume_aligned(a, 32);
uint32_t *b_aligned = __builtin_assume_aligned(b, 32);
for (int i = 0; i < (1L << 10); i += 2) {
a_aligned[i] = 2 * b_aligned[i];
a_aligned[i+1] = a_aligned[i+1];
}
}
This was also the case for GCC 4.8 and 4.9. Adding volatile to
a_aligned's declaration inhibits auto-vectorization completely.
Is there a way to make the latter code snippet auto-vectorize?
Cheers,
S.D.S.