Tyler Nowicki | 020dd79 | 2015-08-10 22:17:40 +0000 | [diff] [blame] | 1 | // RUN: %clang -O1 -fvectorize -target x86_64-unknown-unknown -Rpass-analysis=loop-vectorize -emit-llvm -S %s -o - 2>&1 | FileCheck %s |
Tyler Nowicki | 8a0925c | 2015-08-10 19:56:40 +0000 | [diff] [blame] | 2 | |
Tyler Nowicki | 40e5d08 | 2015-08-10 21:18:01 +0000 | [diff] [blame] | 3 | // CHECK: {{.*}}:9:11: remark: loop not vectorized: vectorization requires changes in the order of operations, however IEEE 754 floating-point operations are not commutative; allow commutativity by specifying '#pragma clang loop vectorize(enable)' before the loop or by providing the compiler option '-ffast-math' |
Tyler Nowicki | 8a0925c | 2015-08-10 19:56:40 +0000 | [diff] [blame] | 4 | |
| 5 | double foo(int N) { |
| 6 | double v = 0.0; |
| 7 | |
| 8 | for (int i = 0; i < N; i++) |
| 9 | v = v + 1.0; |
| 10 | |
| 11 | return v; |
| 12 | } |
Tyler Nowicki | 034baf6 | 2015-08-10 23:05:16 +0000 | [diff] [blame^] | 13 | |
| 14 | // CHECK: {{.*}}:18:13: remark: loop not vectorized: cannot prove pointers refer to independent arrays in memory. The loop requires 9 runtime independence checks to vectorize the loop, but that would exceed the limit of 8 checks; avoid runtime pointer checking when you know the arrays will always be independent by specifying '#pragma clang loop vectorize(assume_safety)' before the loop or by specifying 'restrict' on the array arguments. Erroneous results will occur if these options are incorrectly applied! |
| 15 | |
| 16 | void foo2(int *dw, int *uw, int *A, int *B, int *C, int *D, int N) { |
| 17 | for (int i = 0; i < N; i++) { |
| 18 | dw[i] = A[i] + B[i - 1] + C[i - 2] + D[i - 3]; |
| 19 | uw[i] = A[i] + B[i + 1] + C[i + 2] + D[i + 3]; |
| 20 | } |
| 21 | } |