1 ; RUN: opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=1 -force-vector-width=4 -S -enable-if-conversion | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5 ; This is kernel11 from "LivermoreLoops". We can't vectorize it because we
6 ; access both x[k] and x[k-1].
8 ; void kernel11(ptr x, ptr y, int n) {
9 ; for ( int k=1 ; k<n ; k++ )
10 ; x[k] = x[k-1] + y[k];
13 ; CHECK-LABEL: @kernel11(
14 ; CHECK-NOT: <4 x double>
16 define i32 @kernel11(ptr %x, ptr %y, i32 %n) nounwind uwtable ssp {
17 %1 = alloca ptr, align 8
18 %2 = alloca ptr, align 8
19 %3 = alloca i32, align 4
20 %k = alloca i32, align 4
21 store ptr %x, ptr %1, align 8
22 store ptr %y, ptr %2, align 8
23 store i32 %n, ptr %3, align 4
24 store i32 1, ptr %k, align 4
27 ; <label>:4 ; preds = %25, %0
28 %5 = load i32, ptr %k, align 4
29 %6 = load i32, ptr %3, align 4
30 %7 = icmp slt i32 %5, %6
31 br i1 %7, label %8, label %28
33 ; <label>:8 ; preds = %4
34 %9 = load i32, ptr %k, align 4
35 %10 = sub nsw i32 %9, 1
36 %11 = sext i32 %10 to i64
37 %12 = load ptr, ptr %1, align 8
38 %13 = getelementptr inbounds double, ptr %12, i64 %11
39 %14 = load double, ptr %13, align 8
40 %15 = load i32, ptr %k, align 4
41 %16 = sext i32 %15 to i64
42 %17 = load ptr, ptr %2, align 8
43 %18 = getelementptr inbounds double, ptr %17, i64 %16
44 %19 = load double, ptr %18, align 8
45 %20 = fadd double %14, %19
46 %21 = load i32, ptr %k, align 4
47 %22 = sext i32 %21 to i64
48 %23 = load ptr, ptr %1, align 8
49 %24 = getelementptr inbounds double, ptr %23, i64 %22
50 store double %20, ptr %24, align 8
53 ; <label>:25 ; preds = %8
54 %26 = load i32, ptr %k, align 4
55 %27 = add nsw i32 %26, 1
56 store i32 %27, ptr %k, align 4
59 ; <label>:28 ; preds = %4
64 ; A[i*7] is scalarized, and the different scalars can in theory wrap
65 ; around and overwrite other scalar elements. However we can still
66 ; vectorize because we can version the loop to avoid this case.
69 ; for (int i=0; i<256; ++i) {
77 ; CHECK-LABEL: @func2(
80 define i32 @func2(ptr nocapture %a) nounwind uwtable ssp {
83 ; <label>:1 ; preds = %7, %0
84 %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %7 ]
85 %2 = mul nsw i64 %indvars.iv, 7
86 %3 = getelementptr inbounds i32, ptr %a, i64 %2
87 %4 = load i32, ptr %3, align 4
88 %5 = icmp sgt i32 %4, 3
89 br i1 %5, label %6, label %7
91 ; <label>:6 ; preds = %1
93 %tmp1 = mul i32 %tmp, %4
96 ; <label>:7 ; preds = %6, %1
97 %x.0 = phi i32 [ %tmp1, %6 ], [ %4, %1 ]
98 %8 = add nsw i32 %x.0, 3
99 store i32 %8, ptr %3, align 4
100 %indvars.iv.next = add i64 %indvars.iv, 1
101 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
102 %exitcond = icmp eq i32 %lftr.wideiv, 256
103 br i1 %exitcond, label %9, label %1
105 ; <label>:9 ; preds = %7